Class: TimelineOutput
- Inherits:
-
Object
- Object
- TimelineOutput
- Defined in:
- lib/output/timeline_output.rb
Overview
This class holds methods to print a previously created timelime into the terminal providing simple axis for the z dimension on the abscissa and the data values on the ordinate.
Instance Attribute Summary collapse
-
#extrema ⇒ Object
readonly
Returns the value of attribute extrema.
Instance Method Summary collapse
-
#append_legend_output(output, meta_data, max_size) ⇒ Array
private
method to append the axis and legend information below the timeline.
-
#check_and_append_values(values, line_string) ⇒ String
private
method to finish the creation of a line of timeline output.
-
#check_type_and_print(value) ⇒ String
private
method to check the type of hit.
-
#create_axis_legend(data_size, max_size, meta_data) ⇒ String
private
method to create value informations for the abscissa.
-
#create_axis_string(data_size, max_size) ⇒ String
private
method to create the axis of the abscissa.
-
#create_extreme_output(max_size) ⇒ String
private
method to create the output of the extreme values.
-
#create_output_array(mapped_values, meta_data) ⇒ Array
private
method to create the output array, consisting of a string for each line holding ordinate values and markings for the values and two additional lines for the abscissa.
-
#finish_axis_legend(puffer, start, meta_data) ⇒ String
private
method to finish the axis legend string.
-
#initialize(mapped_values, meta_data, values) ⇒ TimelineOutput
constructor
initialization.
-
#print_output_head(x, y) ⇒ Object
private
simple method for printing an output haeder.
Constructor Details
#initialize(mapped_values, meta_data, values) ⇒ TimelineOutput
initialization
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/output/timeline_output.rb', line 19 def initialize(mapped_values, , values) @extrema = { :maximum => Array.new(), :minimum => Array.new() } output = create_output_array(mapped_values, ) print_output_head(values[:x],values[:y]) output.reverse.each { |value| puts value } end |
Instance Attribute Details
#extrema ⇒ Object (readonly)
Returns the value of attribute extrema.
33 34 35 |
# File 'lib/output/timeline_output.rb', line 33 def extrema @extrema end |
Instance Method Details
#append_legend_output(output, meta_data, max_size) ⇒ Array (private)
method to append the axis and legend information below the timeline
75 76 77 78 79 80 |
# File 'lib/output/timeline_output.rb', line 75 def append_legend_output(output, , max_size) data_size = .domain_z.number_of_values output.unshift(create_axis_string(data_size, max_size)) output.unshift(create_axis_legend(data_size, max_size, )) output.unshift(create_extreme_output(max_size)) end |
#check_and_append_values(values, line_string) ⇒ String (private)
method to finish the creation of a line of timeline output
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/output/timeline_output.rb', line 87 def check_and_append_values(values, line_string) values.each { |value| if (value[0] == :miss) line_string.concat(' ') else line_string.concat(check_type_and_print(value)) end } return line_string end |
#check_type_and_print(value) ⇒ String (private)
method to check the type of hit
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/output/timeline_output.rb', line 163 def check_type_and_print(value) if (value[0] == :maximum) @extrema[:maximum] = value[1] return 'x'.red.bright elsif (value[0] == :minimum) @extrema[:minimum] = value[1] return 'x'.cyan.bright end 'x'.green end |
#create_axis_legend(data_size, max_size, meta_data) ⇒ String (private)
method to create value informations for the abscissa
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/output/timeline_output.rb', line 121 def create_axis_legend(data_size, max_size, ) str = String.new() max_size.times {str.concat(' ')} position = 1 start = Integer(.domain_z.lower) while (data_size - position >= 10) str.concat("%-10s" % start.to_s) position += 10 start += Integer((10 * .domain_z.step).round(1)) end str.concat(finish_axis_legend(data_size - position, start, )) end |
#create_axis_string(data_size, max_size) ⇒ String (private)
method to create the axis of the abscissa
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/output/timeline_output.rb', line 102 def create_axis_string(data_size, max_size) str = String.new() max_size.times {str.concat(' ')} str.concat('--|') position = 1 while (data_size - position >= 10) str.concat('---------|') position += 10 end (data_size - position).times {str.concat('-')} str.concat('|') end |
#create_extreme_output(max_size) ⇒ String (private)
method to create the output of the extreme values
151 152 153 154 155 156 157 |
# File 'lib/output/timeline_output.rb', line 151 def create_extreme_output(max_size) str = String.new() max_size.times {str.concat(' ')} str.concat("Maximum: #{@extrema[:maximum].round(3)}\n") max_size.times {str.concat(' ')} str.concat("Minimum: #{@extrema[:minimum].round(3)}") end |
#create_output_array(mapped_values, meta_data) ⇒ Array (private)
method to create the output array, consisting of a string for each line holding ordinate values and markings for the values and two additional lines for the abscissa
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/output/timeline_output.rb', line 53 def create_output_array(mapped_values, ) output = Array.new() max_size = ("%.2f" % mapped_values.keys.last).length mapped_values.each_pair { |key, values| line_string = "%.2f" % (key) if (line_string.length <= max_size) (max_size - line_string.length).times { line_string.concat(' ')} end line_string.concat('| ') output << check_and_append_values(values, line_string) } append_legend_output(output, , max_size) end |
#finish_axis_legend(puffer, start, meta_data) ⇒ String (private)
method to finish the axis legend string
140 141 142 143 144 145 146 |
# File 'lib/output/timeline_output.rb', line 140 def finish_axis_legend(puffer, start, ) str = ("%-#{puffer}s" % start.to_s) if (puffer > 5) str.concat(Integer(.domain_z.upper).to_s) end str end |
#print_output_head(x, y) ⇒ Object (private)
simple method for printing an output haeder
40 41 42 43 44 |
# File 'lib/output/timeline_output.rb', line 40 def print_output_head(x,y) puts "\nPrinting timeline for Coordinate (%.2f, %.2f)" % [x, y] puts "\n" nil end |