Class: Weather::Forecast
- Inherits:
-
Object
- Object
- Weather::Forecast
- Defined in:
- lib/forecast.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#current ⇒ Object
Current conditions.
-
#day(id) ⇒ Object
Defines a day.
-
#distance_unit ⇒ Object
Unit of distance.
-
#initialize(doc) ⇒ Forecast
constructor
A new instance of Forecast.
-
#last_update ⇒ Object
Last update (future).
-
#location_id ⇒ Object
Location ID.
-
#location_name ⇒ Object
Location name.
-
#night(id) ⇒ Object
Defines a night.
-
#precipitation_unit ⇒ Object
Unit of precipitation.
-
#presure_unit ⇒ Object
Unit of presure.
-
#speed_unit ⇒ Object
Unit of speed.
-
#temp_unit ⇒ Object
Unit of temperature (F | C).
-
#tomorrow ⇒ Object
Used to know the forecast from tomorrow.
Constructor Details
#initialize(doc) ⇒ Forecast
Returns a new instance of Forecast.
12 13 14 |
# File 'lib/forecast.rb', line 12 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
10 11 12 |
# File 'lib/forecast.rb', line 10 def doc @doc end |
Instance Method Details
#current ⇒ Object
Current conditions
17 18 19 |
# File 'lib/forecast.rb', line 17 def current Weather::Current.new(doc.at("weather/cc")) end |
#day(id) ⇒ Object
Defines a day
67 68 69 70 71 72 73 74 75 |
# File 'lib/forecast.rb', line 67 def day(id) day = nil (doc/"weather/dayf/day").each do |d| if d.attributes["d"] == id.to_s day = d end end Weather::Day.new(day) end |
#distance_unit ⇒ Object
Unit of distance
37 38 39 |
# File 'lib/forecast.rb', line 37 def distance_unit doc.at("weather/head/ud").innerHTML end |
#last_update ⇒ Object
Last update (future)
57 58 59 |
# File 'lib/forecast.rb', line 57 def last_update Time.parse(doc.at("weather/dayf/lsup").innerHTML) end |
#location_id ⇒ Object
Location ID
27 28 29 |
# File 'lib/forecast.rb', line 27 def location_id doc.at("weather/loc")["id"] end |
#location_name ⇒ Object
Location name
22 23 24 |
# File 'lib/forecast.rb', line 22 def location_name doc.at("weather/loc/dnam").innerHTML end |
#night(id) ⇒ Object
Defines a night
78 79 80 81 82 83 84 85 86 |
# File 'lib/forecast.rb', line 78 def night(id) night = nil (doc/"weather/dayf/day").each do |d| if d.attributes["d"] == id.to_s night = d end end Weather::Night.new(night) end |
#precipitation_unit ⇒ Object
Unit of precipitation
47 48 49 |
# File 'lib/forecast.rb', line 47 def precipitation_unit doc.at("weather/head/up").innerHTML end |
#presure_unit ⇒ Object
Unit of presure
52 53 54 |
# File 'lib/forecast.rb', line 52 def presure_unit doc.at("weather/head/ur").innerHTML end |
#speed_unit ⇒ Object
Unit of speed
42 43 44 |
# File 'lib/forecast.rb', line 42 def speed_unit doc.at("weather/head/us").innerHTML end |
#temp_unit ⇒ Object
Unit of temperature (F | C)
32 33 34 |
# File 'lib/forecast.rb', line 32 def temp_unit doc.at("weather/head/ut").innerHTML end |
#tomorrow ⇒ Object
Used to know the forecast from tomorrow
62 63 64 |
# File 'lib/forecast.rb', line 62 def tomorrow day(1) end |