Class: Barometer::Base
- Inherits:
-
Object
- Object
- Barometer::Base
- Defined in:
- lib/barometer/base.rb
Constant Summary collapse
- @@config =
allow the configuration of specific weather APIs to be used, and the order in which they would be used
{ 1 => [:wunderground] }
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#success ⇒ Object
Returns the value of attribute success.
-
#weather ⇒ Object
Returns the value of attribute weather.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query = nil) ⇒ Base
constructor
A new instance of Base.
-
#measure(metric = nil) ⇒ Object
iterate through all the configured sources and collect weather data for each one.
- #success? ⇒ Boolean
Constructor Details
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
11 12 13 |
# File 'lib/barometer/base.rb', line 11 def query @query end |
#success ⇒ Object
Returns the value of attribute success.
12 13 14 |
# File 'lib/barometer/base.rb', line 12 def success @success end |
#weather ⇒ Object
Returns the value of attribute weather.
12 13 14 |
# File 'lib/barometer/base.rb', line 12 def weather @weather end |
Class Method Details
.config ⇒ Object
8 |
# File 'lib/barometer/base.rb', line 8 def self.config; @@config; end |
.config=(hash) ⇒ Object
9 |
# File 'lib/barometer/base.rb', line 9 def self.config=(hash); @@config = hash; end |
Instance Method Details
#measure(metric = nil) ⇒ Object
iterate through all the configured sources and collect weather data for each one
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/barometer/base.rb', line 23 def measure(metric=nil) return nil unless @query level = 1 until self.success? if sources = @@config[level] _dig(sources, nil, metric) else raise OutOfSources end level += 1 end @weather end |
#success? ⇒ Boolean
38 |
# File 'lib/barometer/base.rb', line 38 def success?; @success; end |