Class: RangeOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/output/range_output.rb

Overview

Output class for printing datasets of a data series within a given range

Instance Method Summary collapse

Constructor Details

#initialize(meta_data, data_series, parameters, options) ⇒ RangeOutput

singleton method to print the dataset within a given range

Parameters:

  • meta_data (VisMetaData)

    the metadata of the used data series

  • data_series (DataSeries)

    the used data series

  • parameters (Hash)

    the required parameter

  • options (Hash)

    hash with the boolean values for extreme values and extended legend output



18
19
20
21
22
23
24
25
26
27
# File 'lib/output/range_output.rb', line 18

def initialize(, data_series, parameters, options)
  check_range_parameters(, parameters)
  options[:index] = parameters[:lower]

  while (options[:index] <= parameters[:upper])
    determine_output_resolution(data_series, , options)
    determine_animation(parameters)
    options[:index] += 1
  end
end

Instance Method Details

#check_range_parameters(meta_data, indices) ⇒ boolean (private)

method to check if the input parameters are valid

Parameters:

  • meta_data (VisMetaData)

    the metadata of the used data series

  • indices (Hash)

    a hash containing the indices :first and :second

Returns:

  • (boolean)

    true, if the parameters are in the range of the meta data



35
36
37
38
39
# File 'lib/output/range_output.rb', line 35

def check_range_parameters(, indices)
  first_lesser_second?(indices)

  parameter_in_meta_range?(, indices)
end

#determine_animation(parameters) ⇒ Object (private)

method to determine the art of visualization. Without -all or animation speed = 0 the progress will be manual, speed > 0 determines speed in seconds

Parameters:

  • parameters (Hash)

    the required parameters parameter



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/output/range_output.rb', line 90

def determine_animation(parameters)
  animation_speed = 0
  if (parameters[:all])
    animation_speed = Integer(parameters[:all])
  end

  if (animation_speed > 0)
    sleep(animation_speed)
  else
    print 'press Enter to continue ...'.green
    # STDIN to read from console when providing parameters in ARGV
    STDIN.gets.chomp
  end
end

#determine_output_resolution(data_series, meta_data, options) ⇒ Object (private)

method to determine which type of output should be used

Parameters:

  • data_series (DataSeries)

    the used data series

  • meta_data (VisMetaData)

    the metadata of the used data series

  • options (Hash)

    hash with the boolean values for extreme values and



79
80
81
82
83
84
85
# File 'lib/output/range_output.rb', line 79

def determine_output_resolution(data_series, , options)
  if (!options[:auto_scale])
    DataOutput::SingleOutput.new(data_series, , options)
  else
    DataOutput::ScaledDatasetOutput.new(data_series, , options)
  end
end

#first_lesser_second?(indices) ⇒ boolean (private)

method to check if the first parameter is lesser than the second

Parameters:

  • indices (Hash)

    a hash containing the indices :first and :second

Returns:

  • (boolean)

    true, if first < second

Raises:

  • (ArgumentError)

    if first >= second



45
46
47
48
49
50
51
# File 'lib/output/range_output.rb', line 45

def first_lesser_second?(indices)
  if (indices[:lower] >= indices[:upper])
    raise ArgumentError,
      ' Error: First parameter of -r is equal or greater than the second'.red
  end
  return true
end

#parameter_in_meta_range?(meta_data, indices) ⇒ boolean (private)

method to check if the parameters are within the range specified by the MetaData::VisMetaData

Parameters:

  • meta_data (VisMetaData)

    the metadata of the used data series

  • indices (Hash)

    a hash containing the indices :first and :second

Returns:

  • (boolean)

    true, if both parameter are within the meta data range

Raises:

  • (ArgumentError)

    if (first < 0 | second > data size)



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/output/range_output.rb', line 59

def parameter_in_meta_range?(, indices)
  size = .domain_z.number_of_values

  if (indices[:lower] < 0)
    raise ArgumentError,
      ' Error: First parameter of -r is lesser or equal 0'.red
  end

  if (indices[:upper] >= size)
    raise ArgumentError,
      ' Error: Second parameter of -r greater than size of data series'.red
  end

  return true
end