Class: Stormglass::Value
- Inherits:
-
Object
- Object
- Stormglass::Value
- Extended by:
- Forwardable
- Defined in:
- lib/stormglass/value.rb
Overview
represents a value for a stormglass prediction source with prefered unit_type contains a collection of Stormglass::Subvalue’s, which represent a particular unit of measurement for example, a Stormglass::Value for air_temperature would have Stormglass::Subvalue’s for Celsius and Fahrenheit
Instance Method Summary collapse
- #attribute ⇒ Object
- #data_source ⇒ Object
-
#data_sources ⇒ Object
returns the sources available for this value.
- #dict ⇒ Object
- #for_source ⇒ Object
-
#initialize(attribute, src, data_source, unit_type) ⇒ Value
constructor
A new instance of Value.
- #inspect ⇒ Object
- #preffered_subvalue ⇒ Object
- #src ⇒ Object
- #subvalues ⇒ Object
- #to_s ⇒ Object
- #unit_types ⇒ Object
Constructor Details
#initialize(attribute, src, data_source, unit_type) ⇒ Value
Returns a new instance of Value.
10 11 12 13 14 15 |
# File 'lib/stormglass/value.rb', line 10 def initialize(attribute, src, data_source, unit_type) @attribute = attribute @src = src @data_source = data_source @unit_type = unit_type end |
Instance Method Details
#attribute ⇒ Object
36 37 38 |
# File 'lib/stormglass/value.rb', line 36 def attribute @attribute end |
#data_source ⇒ Object
17 18 19 |
# File 'lib/stormglass/value.rb', line 17 def data_source @data_source end |
#data_sources ⇒ Object
returns the sources available for this value
28 29 30 |
# File 'lib/stormglass/value.rb', line 28 def data_sources src.collect{|v| v['source']} end |
#dict ⇒ Object
65 66 67 |
# File 'lib/stormglass/value.rb', line 65 def dict Stormglass::RESULT_DICT[attribute] end |
#for_source ⇒ Object
21 22 23 24 25 |
# File 'lib/stormglass/value.rb', line 21 def for_source @src.collect do |v| v['value'] if (!v['source'].nil? && v['source'] == data_source) end.compact.first end |
#inspect ⇒ Object
44 45 46 47 48 49 |
# File 'lib/stormglass/value.rb', line 44 def inspect string = "#<#{self.class.to_s} " string +="value=#{preffered_subvalue.value}, unit='#{preffered_subvalue.unit}', description='#{preffered_subvalue.description}', " string +="unit_type='#{preffered_subvalue.unit_type}', unit_types=#{unit_types.to_s}, data_source='#{@data_source}', data_sources=#{data_sources}>" string end |
#preffered_subvalue ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/stormglass/value.rb', line 55 def preffered_subvalue if @unit_type subvalues.find{|subvalue| subvalue.unit_type == @unit_type} elsif setting_key = Stormglass.settings.units[@attribute] subvalues.find{|subvalue| subvalue.unit_type == setting_key} else subvalues.first end end |
#src ⇒ Object
40 41 42 |
# File 'lib/stormglass/value.rb', line 40 def src @src end |
#subvalues ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/stormglass/value.rb', line 69 def subvalues subvals = [] raw_val = for_source() subvals << {value: raw_val}.merge(dict) Stormglass::AlternateValues.perform(subvals) subvals.collect{|subvalue| Stormglass::Subvalue.new(subvalue) } end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/stormglass/value.rb', line 32 def to_s preffered_subvalue.to_s end |
#unit_types ⇒ Object
51 52 53 |
# File 'lib/stormglass/value.rb', line 51 def unit_types subvalues.collect(&:unit_type) end |