Class: WeatherParameter

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

Constant Summary collapse

DEFAULT_CALCULATION_METHOD =
:mean

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ WeatherParameter

Returns a new instance of WeatherParameter.



10
11
12
13
14
# File 'lib/weather_parameter.rb', line 10

def initialize(args)
  @time_layout  = args[:time_layout]
  @values       = args[:values]
  @calculation_method = args[:calculation_method] || DEFAULT_CALCULATION_METHOD
end

Instance Attribute Details

#calculation_methodObject

Returns the value of attribute calculation_method.



6
7
8
# File 'lib/weather_parameter.rb', line 6

def calculation_method
  @calculation_method
end

#time_layoutObject

Returns the value of attribute time_layout.



6
7
8
# File 'lib/weather_parameter.rb', line 6

def time_layout
  @time_layout
end

#valuesObject

Returns the value of attribute values.



6
7
8
# File 'lib/weather_parameter.rb', line 6

def values
  @values
end

Instance Method Details

#[](i) ⇒ Object



16
17
18
# File 'lib/weather_parameter.rb', line 16

def [](i)
  @values[i] if (@values && @values.is_a?(Array) && i >= 0 && i < @values.length)
end

#value_at(t) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/weather_parameter.rb', line 20

def value_at(t)
  if t.is_a?(TimeSpan)
    self.send @calculation_method, t
  else
    self[@time_layout.index_at(t)]
  end
end