Class: Barometer::Weather
- Inherits:
-
Object
- Object
- Barometer::Weather
- Defined in:
- lib/barometer/weather.rb
Instance Attribute Summary collapse
-
#end_at ⇒ Object
Returns the value of attribute end_at.
-
#responses ⇒ Object
Returns the value of attribute responses.
-
#start_at ⇒ Object
Returns the value of attribute start_at.
Instance Method Summary collapse
- #current ⇒ Object
- #dew_point ⇒ Object
- #for(query) ⇒ Object
- #forecast ⇒ Object
- #heat_index ⇒ Object
- #humidity ⇒ Object
-
#initialize(units = :metric) ⇒ Weather
constructor
A new instance of Weather.
- #pressure ⇒ Object
- #source(source) ⇒ Object
- #success? ⇒ Boolean
- #temperature ⇒ Object
- #today ⇒ Object
- #tomorrow ⇒ Object
- #visibility ⇒ Object
- #wind ⇒ Object
- #wind_chill ⇒ Object
Constructor Details
#initialize(units = :metric) ⇒ Weather
Returns a new instance of Weather.
6 7 8 9 |
# File 'lib/barometer/weather.rb', line 6 def initialize(units=:metric) @units = units @responses = [] end |
Instance Attribute Details
#end_at ⇒ Object
Returns the value of attribute end_at.
4 5 6 |
# File 'lib/barometer/weather.rb', line 4 def end_at @end_at end |
#responses ⇒ Object
Returns the value of attribute responses.
3 4 5 |
# File 'lib/barometer/weather.rb', line 3 def responses @responses end |
#start_at ⇒ Object
Returns the value of attribute start_at.
4 5 6 |
# File 'lib/barometer/weather.rb', line 4 def start_at @start_at end |
Instance Method Details
#current ⇒ Object
19 20 21 |
# File 'lib/barometer/weather.rb', line 19 def current successful_responses.first.current if successful_responses.any? end |
#dew_point ⇒ Object
40 |
# File 'lib/barometer/weather.rb', line 40 def dew_point; average(:dew_point, Data::Temperature); end |
#for(query) ⇒ Object
35 36 37 |
# File 'lib/barometer/weather.rb', line 35 def for(query) successful_responses.first.for(query) if successful_responses.any? end |
#forecast ⇒ Object
23 24 25 |
# File 'lib/barometer/weather.rb', line 23 def forecast successful_responses.first.forecast if successful_responses.any? end |
#heat_index ⇒ Object
41 |
# File 'lib/barometer/weather.rb', line 41 def heat_index; average(:heat_index, Data::Temperature); end |
#humidity ⇒ Object
46 |
# File 'lib/barometer/weather.rb', line 46 def humidity; average(:humidity); end |
#pressure ⇒ Object
43 |
# File 'lib/barometer/weather.rb', line 43 def pressure; average(:pressure, Data::Pressure); end |
#source(source) ⇒ Object
11 12 13 |
# File 'lib/barometer/weather.rb', line 11 def source(source) responses.detect{|response| response.source == source} end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/barometer/weather.rb', line 15 def success? responses.any?(&:success?) end |
#temperature ⇒ Object
39 |
# File 'lib/barometer/weather.rb', line 39 def temperature; average(:temperature, Data::Temperature); end |
#today ⇒ Object
27 28 29 |
# File 'lib/barometer/weather.rb', line 27 def today successful_responses.first.forecast[0] if successful_responses.any? end |
#tomorrow ⇒ Object
31 32 33 |
# File 'lib/barometer/weather.rb', line 31 def tomorrow successful_responses.first.forecast[1] if successful_responses.any? end |
#visibility ⇒ Object
44 |
# File 'lib/barometer/weather.rb', line 44 def visibility; average(:visibility, Data::Distance); end |
#wind ⇒ Object
45 |
# File 'lib/barometer/weather.rb', line 45 def wind; average(:wind, Data::Vector); end |
#wind_chill ⇒ Object
42 |
# File 'lib/barometer/weather.rb', line 42 def wind_chill; average(:wind_chill, Data::Temperature); end |