Module: TerminalVis

Defined in:
lib/output/output.rb,
lib/main/main_module.rb,
lib/math/interpolation.rb,
lib/math/linear_interpolation.rb,
lib/math/region_interpolation.rb,
lib/output/parameter_collector.rb,
lib/math/bilinear_interpolation.rb

Overview

This module holds the main singleton methods that are called from the script. It also stores the data ans parameter repository so it can be called from the other classes and modules if they need data oder parameter informations.

Defined Under Namespace

Modules: Interpolation, Output, ParameterCollector

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.data_repoDataRepository (readonly)

Returns the repository storing the datasets.

Returns:

  • (DataRepository)

    the repository storing the datasets



19
20
21
# File 'lib/main/main_module.rb', line 19

def data_repo
  @data_repo
end

.option_handlerConfiguration_Handler (readonly)

Returns the handler controlling the configuration parameter.

Returns:

  • (Configuration_Handler)

    the handler controlling the configuration parameter



25
26
27
# File 'lib/main/main_module.rb', line 25

def option_handler
  @option_handler
end

.parameter_handlerParameter::ParameterHandler (readonly)

Returns the handler controlling the parameters.

Returns:



22
23
24
# File 'lib/main/main_module.rb', line 22

def parameter_handler
  @parameter_handler
end

Class Method Details

.check_index(meta_data, index) ⇒ Object (private)

method to check if provided integer index lies in range of dataseries

Parameters:

  • meta_data (VisMetaData)

    the meta data which should be checked for the corresponding index

  • index (Integer)

    the given index from the input



103
104
105
106
107
108
109
110
111
# File 'lib/main/main_module.rb', line 103

private_class_method def self.check_index(, index)
  if (index < 0 || index >= @data_repo.repository[].series.size)
    text_index = @parameter_handler.repository.parameters[:index]
    data_size = @data_repo.repository[].series.size
    message = " Error: input #{text_index} for -i is not valid" \
              " for dataset with length #{data_size}".red
    print_error(message)
  end
end

.create_metadataVisMetaData

creates the MetaData::VisMetaData based on the provided parameters

Returns:

  • (VisMetaData)

    returns the meta data for the dataset



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/main/main_module.rb', line 38

def self.
  begin
    if (@parameter_handler.repository.parameters[:meta])
      @data_repo.add_data(@parameter_handler.repository.parameters[:file])
    else
      @data_repo.add_data_with_default_meta(
                     @parameter_handler.repository.parameters[:file])
    end
  rescue StandardError => e
    print_error(" Error while creating metadata:\n ".concat(e.message))
  end
end

.determine_configuration_optionsObject

method to adjust the default options if the parameter was provided



52
53
54
55
56
57
# File 'lib/main/main_module.rb', line 52

def self.determine_configuration_options
  if (@parameter_handler.repository.parameters[:option])
    @option_handler.process_parameter(@parameter_handler.
                                      repository.parameters[:option])
  end
end

.get_and_check_index(meta_data) ⇒ Integer

checks if option -i was used, determines if a valid parameter was entered and returns the index on success

Parameters:

  • meta_data (VisMetaData)

    the meta data which should be checked for the corresponding index

Returns:

  • (Integer)

    the index from the parameter, default return is 0



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/main/main_module.rb', line 82

def self.get_and_check_index()
  index = 0   # default data set if -i not set or only one data set
  if (@parameter_handler.repository.parameters[:index])
    begin   # make sure that parameter of -i is an integer
      index = Integer(@parameter_handler.repository.parameters[:index]) - 1
    rescue ArgumentError
      message = " Error: argument of -i is not a number: " \
                "#{@parameter_handler.repository.parameters[:index]}".red
      print_error(message)
    end

    check_index(, index)
  end

  return index
end

.initialize_repositories(arguments) ⇒ Object

singleton method to initialize the required repositories

Parameters:

  • arguments (Array)

    the input values from the terminal input ARGV



30
31
32
33
34
# File 'lib/main/main_module.rb', line 30

def self.initialize_repositories(arguments)
    @parameter_handler = Parameter::ParameterHandler.new(arguments)
    @data_repo = DataInput::DataRepository.new()
    @option_handler = ConfigurationHandler.new()
end

call for standard error output

Parameters:

  • message (String)

    message string with error message



72
73
74
75
# File 'lib/main/main_module.rb', line 72

def self.print_error(message)
  puts "#{message}".red
  puts 'For help type: ruby <script> --help'.green
end

call to print the help text



60
61
62
# File 'lib/main/main_module.rb', line 60

def self.print_help
  HelpOutput.print_help_for(@parameter_handler.repository.parameters[:help])
end

call to print version number and author



65
66
67
68
# File 'lib/main/main_module.rb', line 65

def self.print_version
  puts 'terminal_visualization version 0.9.2'.yellow
  puts 'Created by Benjamin Held (June 2015)'.yellow
end