Class: DataInput::DataSet
- Inherits:
-
Object
- Object
- DataInput::DataSet
- Defined in:
- lib/data/data_set.rb
Overview
Class to represent a two dimensional data set
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The data stored in a Hash (Integer => Array).
-
#max_value ⇒ Float
readonly
The maximal value of the dataset.
-
#min_value ⇒ Float
readonly
The minimal value of the dataset.
Instance Method Summary collapse
-
#find_extreme_values ⇒ Object
private
searches for the minimal and maximal value of the dataset.
-
#initialize(raw_data) ⇒ DataSet
constructor
initialization.
-
#process_data(raw_data) ⇒ Object
private
processes the raw data and parses it in number values.
Constructor Details
#initialize(raw_data) ⇒ DataSet
initialization
19 20 21 22 |
# File 'lib/data/data_set.rb', line 19 def initialize(raw_data) @data = Hash.new() process_data(raw_data) end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns the data stored in a Hash (Integer => Array).
15 16 17 |
# File 'lib/data/data_set.rb', line 15 def data @data end |
#max_value ⇒ Float (readonly)
Returns the maximal value of the dataset.
13 14 15 |
# File 'lib/data/data_set.rb', line 13 def max_value @max_value end |
#min_value ⇒ Float (readonly)
Returns the minimal value of the dataset.
11 12 13 |
# File 'lib/data/data_set.rb', line 11 def min_value @min_value end |
Instance Method Details
#find_extreme_values ⇒ Object (private)
searches for the minimal and maximal value of the dataset
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/data/data_set.rb', line 46 def find_extreme_values @min_value = @data[0][1].to_f @max_value = @data[0][1].to_f data.each_value { |row| row.each { |value| @min_value = value if (value < @min_value) @max_value = value if (value > @max_value) } } end |
#process_data(raw_data) ⇒ Object (private)
processes the raw data and parses it in number values
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/data/data_set.rb', line 28 def process_data(raw_data) row = 0 begin raw_data.each { |line| @data[row] = line.map { |s| Float(s) s.to_f } row += 1 } find_extreme_values rescue StandardError => e raise ArgumentError, " Error in data set while parsing data:\n " .concat(e.).red end end |