Class: Barometer::Base

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query = nil) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
# File 'lib/barometer/base.rb', line 14

def initialize(query=nil)
  @query = Barometer::Query.new(query)
  @weather = Barometer::Weather.new
  @success = false
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



11
12
13
# File 'lib/barometer/base.rb', line 11

def query
  @query
end

#successObject

Returns the value of attribute success.



12
13
14
# File 'lib/barometer/base.rb', line 12

def success
  @success
end

#weatherObject

Returns the value of attribute weather.



12
13
14
# File 'lib/barometer/base.rb', line 12

def weather
  @weather
end

Class Method Details

.configObject



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

Returns:

  • (Boolean)


38
# File 'lib/barometer/base.rb', line 38

def success?; @success; end