Module: TerminalVis::ParameterCollector

Defined in:
lib/output/parameter_collector.rb

Overview

This module holds methods who are collecting the required parameters for a specific output format. They collect them from the corresponding repositories and return them.

Class Method Summary collapse

Class Method Details

.create_error_message(parameter, type) ⇒ Object (private)

method to create an error message when rescuing an error

Parameters:

  • parameter (Symbol)

    the requested parameter

  • type (String)

    a string containing the type for the error message



108
109
110
111
112
# File 'lib/output/parameter_collector.rb', line 108

private_class_method def self.create_error_message(parameter, type)
  message = " Error: at least one argument of #{parameter}" \
            " is not a valid #{type}".red
  TerminalVis::print_error(message)
end

.determine_indices_for_deltaHash

gets the indices of the data sets which should be substracted

Returns:

  • (Hash)

    the indices of the two datasets



29
30
31
32
33
34
# File 'lib/output/parameter_collector.rb', line 29

def self.determine_indices_for_delta
  data_indices = retrieve_parameters(:first, :second, :delta, 'Integer')
  data_indices[:first] -= 1
  data_indices[:second] -= 1
  return data_indices
end

.determine_interpolation_valuesObject

method to get the required coordinates to start an interpolation



23
24
25
# File 'lib/output/parameter_collector.rb', line 23

def self.determine_interpolation_values
  retrieve_parameters(:x, :y, :coord, 'Float')
end

.determine_range_parametersHash

method to determine the required parameters for the paramater -r

Returns:

  • (Hash)

    a hash with with required parameters



38
39
40
41
42
43
44
45
# File 'lib/output/parameter_collector.rb', line 38

def self.determine_range_parameters
  parameters = retrieve_parameters(:lower, :upper, :range, 'Integer')
  parameters[:lower] -= 1
  parameters[:upper] -= 1
  parameters[:all] = TerminalVis.parameter_handler.
                                 repository.parameters[:all]
  return parameters
end

.determine_region_parametersHash

method to get the required values to create a region that will be interpolated

Returns:

  • (Hash)

    the values to determine the interpolation region



50
51
52
53
54
# File 'lib/output/parameter_collector.rb', line 50

def self.determine_region_parameters
  parameters = retrieve_parameters(:inter, :delta, :section, 'Float')
  { :inter_x => parameters[:inter], :delta_x => parameters[:delta],
    :inter_y => parameters[:inter], :delta_y => parameters[:delta]}
end

.determine_timeline_valuesHash

method to get the required values to generate timeline output

Returns:

  • (Hash)

    a hash with the required values



15
16
17
18
19
20
# File 'lib/output/parameter_collector.rb', line 15

def self.determine_timeline_values
  values = retrieve_parameters(:x, :y, :time, 'Float')
  values[:y_size] = TerminalVis.option_handler.options.
                     repository[:y_time_size]
  return values
end

.read_parameter(parameter, index) ⇒ String (private)

method to read the value for a given parameter and index

Parameters:

  • parameter (Symbol)

    the provided parameter

  • index (Integer)

    the given index

Returns:

  • (String)

    the value stored for the parameter at index



101
102
103
# File 'lib/output/parameter_collector.rb', line 101

private_class_method def self.read_parameter(parameter, index)
  TerminalVis.parameter_handler.repository.parameters[parameter][index]
end

.retrieve_float_parameters(first, second, parameter) ⇒ Hash (private)

method to retrive the parameters for float values

Parameters:

  • first (Symbol)

    the first parameter argument

  • second (Symbol)

    the second parameter argument

  • parameter (Symbol)

    the requested parameter

Returns:

  • (Hash)

    the hash with the required values



92
93
94
95
# File 'lib/output/parameter_collector.rb', line 92

private_class_method def self.retrieve_float_parameters(first, second, parameter)
  {first => Float(read_parameter(parameter, 0)),
   second => Float(read_parameter(parameter, 1))}
end

.retrieve_integer_parameters(first, second, parameter) ⇒ Hash (private)

method to retrive the parameters for interger values

Parameters:

  • first (Symbol)

    the first parameter argument

  • second (Symbol)

    the second parameter argument

  • parameter (Symbol)

    the requested parameter

Returns:

  • (Hash)

    the hash with the required values



82
83
84
85
# File 'lib/output/parameter_collector.rb', line 82

private_class_method def self.retrieve_integer_parameters(first, second, parameter)
  {first => Integer(read_parameter(parameter, 0)),
   second => Integer(read_parameter(parameter, 1))}
end

.retrieve_parameters(first, second, parameter, type) ⇒ Hash (private)

method to retrive the parameters for the given type

Parameters:

  • first (Symbol)

    the first parameter argument

  • second (Symbol)

    the second parameter argument

  • parameter (Symbol)

    the requested parameter

  • type (String)

    the required type

Returns:

  • (Hash)

    the hash with the required values



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/output/parameter_collector.rb', line 62

private_class_method def self.retrieve_parameters(first, second, parameter, type)
  begin
    case type
      when 'Integer'
        return retrieve_integer_parameters(first, second, parameter)
      when 'Float'
        return retrieve_float_parameters(first, second, parameter)
      else
        TerminalVis::print_error(" Error: unknown parameter: #{type}")
    end
  rescue ArgumentError
    create_error_message(parameter, type)
  end
end