Class: DataOutput::BaseOutput
- Inherits:
-
Object
- Object
- DataOutput::BaseOutput
- Defined in:
- lib/output/data_output/base_output.rb
Overview
This class provides basic methods for the other color legends to work with. The children need to define the method print_meta_information which will print the desired meta information for the chosen output. If the child class does not implement this method BaseOutput raises a NotImplementedError.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data_set ⇒ DataSet
readonly
private
The used dataset.
-
#legend ⇒ ColorLegend::BaseLegend
readonly
private
The color legend for the data.
-
#with_extreme_values ⇒ boolean
readonly
private
If the output should highlight the extreme values.
Instance Method Summary collapse
-
#determine_output_type_and_print_value(value) ⇒ Symbol
private
in case of extreme values this method checks, if the current value is equal one of the two extreme values, if true denote the special markings.
-
#print_data(with_legend, domain_x, domain_y) ⇒ Object
private
prints the data and the additional informations.
-
#print_data_and_get_extrema(domain_y, data_axis) ⇒ Hash
private
reverses the data to print it in the correct occurence.
-
#print_domain_information(domain, dim_string) ⇒ Object
private
prints the domain information for the given domain.
-
#print_extreme_information(extreme_coordinates) ⇒ Object
private
prints the coordinates and values of the extreme values.
-
#print_extreme_values_for(coordinates, type, value) ⇒ Object
private
prints all the coordinates of the given extreme value.
-
#print_meta_information ⇒ Object
private
abstract
abstract method to print the used meta information.
-
#set_attributes(data_set, with_extreme_values) ⇒ Object
private
method to set the attributes.
Instance Attribute Details
#data_set ⇒ DataSet (readonly, private)
Returns the used dataset.
21 22 23 |
# File 'lib/output/data_output/base_output.rb', line 21 def data_set @data_set end |
#legend ⇒ ColorLegend::BaseLegend (readonly, private)
Returns the color legend for the data.
17 18 19 |
# File 'lib/output/data_output/base_output.rb', line 17 def legend @legend end |
#with_extreme_values ⇒ boolean (readonly, private)
Returns if the output should highlight the extreme values.
19 20 21 |
# File 'lib/output/data_output/base_output.rb', line 19 def with_extreme_values @with_extreme_values end |
Instance Method Details
#determine_output_type_and_print_value(value) ⇒ Symbol (private)
in case of extreme values this method checks, if the current value is equal one of the two extreme values, if true denote the special markings
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/output/data_output/base_output.rb', line 37 def determine_output_type_and_print_value(value) # create output for maximum if (value == @data_set.max_value && @with_extreme_values) print '++'.light_gray.bright.black_bg return :maximum # create output for minimum elsif (value == @data_set.min_value && @with_extreme_values) print '--'.light_gray.bright.black_bg return :minimum # create normal output else print @legend.create_output_string_for(value,' ') return :normal end end |
#print_data(with_legend, domain_x, domain_y) ⇒ Object (private)
prints the data and the additional informations
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/output/data_output/base_output.rb', line 80 def print_data(with_legend, domain_x, domain_y) data_axis = DataAxis.new() extreme_coordinates = print_data_and_get_extrema(domain_y, data_axis) data_axis.print_x_axis_values(domain_x) puts @legend.print_color_legend(with_legend) print_extreme_information(extreme_coordinates) if (@with_extreme_values) puts "\n" nil end |
#print_data_and_get_extrema(domain_y, data_axis) ⇒ Hash (private)
reverses the data to print it in the correct occurence
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/output/data_output/base_output.rb', line 98 def print_data_and_get_extrema(domain_y, data_axis) extreme_coordinates = { :maximum => Array.new(), :minimum => Array.new() } # reverse the data to start with the highest y-value as the first # output line reversed_data = @data_set.data.to_a.reverse.to_h reversed_data.each_pair { |key, row| data_axis.print_y_line_beginning(domain_y, key) row.each_index { |index| output = determine_output_type_and_print_value(row[index]) extreme_coordinates[output] << [index, key] if (output != :normal) } puts } extreme_coordinates end |
#print_domain_information(domain, dim_string) ⇒ Object (private)
prints the domain information for the given domain
123 124 125 126 127 |
# File 'lib/output/data_output/base_output.rb', line 123 def print_domain_information(domain, dim_string) puts "%s-axis with %s from %.1f up to %.1f and steprange %.2f." % [dim_string, domain.name, domain.lower, domain.upper, domain.step] nil end |
#print_extreme_information(extreme_coordinates) ⇒ Object (private)
prints the coordinates and values of the extreme values
55 56 57 58 59 60 61 62 |
# File 'lib/output/data_output/base_output.rb', line 55 def print_extreme_information(extreme_coordinates) puts 'Dataset extreme values:' print_extreme_values_for(extreme_coordinates[:maximum], 'Maximum (++):', @data_set.max_value) print_extreme_values_for(extreme_coordinates[:minimum], 'Minimum (--):', @data_set.min_value) nil end |
#print_extreme_values_for(coordinates, type, value) ⇒ Object (private)
prints all the coordinates of the given extreme value
68 69 70 71 72 73 74 75 |
# File 'lib/output/data_output/base_output.rb', line 68 def print_extreme_values_for(coordinates, type, value) while (coordinates.size > 0) coordinate = coordinates.shift color = @legend.create_output_string_for(value,' ') puts " %s %.3f at %s [%s]." % [type, value, coordinate, color] end nil end |
#print_meta_information ⇒ Object (private)
subclasses need to implement this method
abstract method to print the used meta information
132 133 134 135 136 |
# File 'lib/output/data_output/base_output.rb', line 132 def fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: print_meta_information " \ "from its base class".red end |
#set_attributes(data_set, with_extreme_values) ⇒ Object (private)
method to set the attributes
27 28 29 30 |
# File 'lib/output/data_output/base_output.rb', line 27 def set_attributes(data_set, with_extreme_values) @data_set = data_set @with_extreme_values = with_extreme_values end |