Class: MetaData::DataDomain
- Inherits:
-
Object
- Object
- MetaData::DataDomain
- Defined in:
- lib/data/data_domain.rb
Overview
DataDomain represents the meta data for one dimension
Instance Attribute Summary collapse
-
#lower ⇒ Float
readonly
Lower boundary of the dimension.
-
#name ⇒ String
readonly
Name of the data.
-
#step ⇒ Float
readonly
Step range between two values.
-
#upper ⇒ Float
readonly
Upper boundary of the dimension.
Instance Method Summary collapse
-
#get_coordinate_to_index(index) ⇒ Float
method to get the coordinate to a given index.
-
#initialize(name, lower, upper, step) ⇒ DataDomain
constructor
initialization.
-
#number_of_values ⇒ Integer
method to get the number of data values specified by the values of the domain object.
Constructor Details
#initialize(name, lower, upper, step) ⇒ DataDomain
initialization
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/data/data_domain.rb', line 39 def initialize(name, lower, upper, step) @name = name begin @lower = Float(lower) @upper = Float(upper) @step = Float(step) rescue ArgumentError raise ArgumentError, ' Error in data domain: received non number argument.'.red end end |
Instance Attribute Details
#lower ⇒ Float (readonly)
Returns lower boundary of the dimension.
27 28 29 |
# File 'lib/data/data_domain.rb', line 27 def lower @lower end |
#name ⇒ String (readonly)
Returns name of the data.
25 26 27 |
# File 'lib/data/data_domain.rb', line 25 def name @name end |
#step ⇒ Float (readonly)
Returns step range between two values.
31 32 33 |
# File 'lib/data/data_domain.rb', line 31 def step @step end |
#upper ⇒ Float (readonly)
Returns upper boundary of the dimension.
29 30 31 |
# File 'lib/data/data_domain.rb', line 29 def upper @upper end |
Instance Method Details
#get_coordinate_to_index(index) ⇒ Float
method to get the coordinate to a given index
63 64 65 66 67 68 69 70 71 |
# File 'lib/data/data_domain.rb', line 63 def get_coordinate_to_index(index) coordinate = lower + index * step if (coordinate < lower || coordinate > upper) raise RangeError, " Error: #{index} creates coordinate #{coordinate} that lies " \ "out of range".red end return coordinate end |
#number_of_values ⇒ Integer
method to get the number of data values specified by the values of the domain object
54 55 56 |
# File 'lib/data/data_domain.rb', line 54 def number_of_values Integer((@upper - @lower) / @step) + 1 end |