Class: Weather::Forecast::FutureConditions
Overview
Abstract class representing either a day or night in the daily forecast (note that “future” can include today).
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of FutureConditions.
268
269
270
271
272
273
|
# File 'lib/weather/forecast.rb', line 268
def initialize(element)
if (not element.kind_of?($USE_LIBXML ? XML::Node : REXML::Element))
raise "The xml element given to the Day/Night constructor must be a valid REXML::Element"
end
@xml = element
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
275
276
277
278
279
280
281
|
# File 'lib/weather/forecast.rb', line 275
def method_missing(name)
begin
return mypart.elements[name.to_s].text
rescue NoMethodError
return "N/A"
end
end
|
Instance Attribute Details
#xml ⇒ Object
Returns the value of attribute xml.
264
265
266
|
# File 'lib/weather/forecast.rb', line 264
def xml
@xml
end
|
Instance Method Details
#date ⇒ Object
293
294
295
296
297
|
# File 'lib/weather/forecast.rb', line 293
def date
mon, day = @xml.attributes['dt'].split(" ")
Time.local(Time.now.year, mon, day)
end
|
#high ⇒ Object
Also known as:
hi
305
306
307
|
# File 'lib/weather/forecast.rb', line 305
def high
clean_temp('hi')
end
|
#icon ⇒ Object
The numeric ID for the icon representing these forecast conditions. You can find the corresponding icons packaged with RubyWeather in the example/weather_32 directory.
301
302
303
|
# File 'lib/weather/forecast.rb', line 301
def icon
mypart.elements['icon'].text.to_i
end
|
#latest_update ⇒ Object
The date and time when the conditions were last measured/forecast. Returned as a Time object.
285
286
287
|
# File 'lib/weather/forecast.rb', line 285
def latest_update
Time.parse(@xml.attributes['lsup'])
end
|
#low ⇒ Object
Also known as:
lo
310
311
312
|
# File 'lib/weather/forecast.rb', line 310
def low
clean_temp('low')
end
|
#outlook ⇒ Object
316
317
318
|
# File 'lib/weather/forecast.rb', line 316
def outlook
mypart.elements['t'].text
end
|
#outlook_brief ⇒ Object
320
321
322
|
# File 'lib/weather/forecast.rb', line 320
def outlook_brief
mypart.elements['bt'].text
end
|
#pop ⇒ Object
Also known as:
ppcp
324
325
326
|
# File 'lib/weather/forecast.rb', line 324
def pop
mypart.elements['ppcp'].text.to_i
end
|
#sunrise ⇒ Object
329
330
331
332
333
334
|
# File 'lib/weather/forecast.rb', line 329
def sunrise
hour,minute = @xml.elements['sunr'].text.split(" ").first.split(":")
hour = hour.to_i
minute = minute.to_i
Time.local(date.year, date.month, date.day, hour, minute)
end
|
#sunset ⇒ Object
336
337
338
339
340
341
|
# File 'lib/weather/forecast.rb', line 336
def sunset
hour,minute = @xml.elements['suns'].text.split(" ").first.split(":")
hour = hour.to_i + 12 minute = minute.to_i
Time.local(date.year, date.month, date.day, hour, minute)
end
|
#wind ⇒ Object
289
290
291
|
# File 'lib/weather/forecast.rb', line 289
def wind
fix_wind(complex_attribute(mypart.elements['wind']))
end
|