Class: MetaData::DataDomain

Inherits:
Object
  • Object
show all
Defined in:
lib/data/data_domain.rb

Overview

DataDomain represents the meta data for one dimension

Raises:

  • (ArgumentError)

    if parsing of attribute values fails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, lower, upper, step) ⇒ DataDomain

initialization

Parameters:

  • name (String)

    the name of the data

  • lower (String)

    the lower boundary of the dimension

  • upper (String)

    the upper boundary of the dimension

  • step (String)

    the step range between two values

Raises:

  • (ArgumentError)

    when one of the parameters is not a number



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

#lowerFloat (readonly)

Returns lower boundary of the dimension.

Returns:

  • (Float)

    lower boundary of the dimension



27
28
29
# File 'lib/data/data_domain.rb', line 27

def lower
  @lower
end

#nameString (readonly)

Returns name of the data.

Returns:

  • (String)

    name of the data



25
26
27
# File 'lib/data/data_domain.rb', line 25

def name
  @name
end

#stepFloat (readonly)

Returns step range between two values.

Returns:

  • (Float)

    step range between two values



31
32
33
# File 'lib/data/data_domain.rb', line 31

def step
  @step
end

#upperFloat (readonly)

Returns upper boundary of the dimension.

Returns:

  • (Float)

    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

Parameters:

  • index (Integer)

    the given index

Returns:

  • (Float)

    the coordinate

Raises:

  • (RangeError)

    if the index creates a coordinate that lies out of the domain range



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_valuesInteger

method to get the number of data values specified by the values of the domain object

Returns:

  • (Integer)

    the number of data values



54
55
56
# File 'lib/data/data_domain.rb', line 54

def number_of_values
  Integer((@upper - @lower) / @step) + 1
end