Class: Weather::Forecast::FutureConditions

Inherits:
Conditions
  • Object
show all
Defined in:
lib/weather/forecast.rb

Overview

Abstract class representing either a day or night in the daily forecast (note that “future” can include today).

Direct Known Subclasses

Day, Night

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ FutureConditions

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

#xmlObject (readonly)

Returns the value of attribute xml.



264
265
266
# File 'lib/weather/forecast.rb', line 264

def xml
  @xml
end

Instance Method Details

#dateObject



293
294
295
296
297
# File 'lib/weather/forecast.rb', line 293

def date
  # FIXME: this will break if rolling over to next year (i.e. fetched 5 days into the future on Dec 30), since today's year is assumed
  mon, day = @xml.attributes['dt'].split(" ")
  Time.local(Time.now.year, mon, day)
end

#highObject Also known as: hi



305
306
307
# File 'lib/weather/forecast.rb', line 305

def high
  clean_temp('hi')
end

#iconObject

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_updateObject

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

#lowObject Also known as: lo



310
311
312
# File 'lib/weather/forecast.rb', line 310

def low
  clean_temp('low')
end

#outlookObject



316
317
318
# File 'lib/weather/forecast.rb', line 316

def outlook
  mypart.elements['t'].text
end

#outlook_briefObject



320
321
322
# File 'lib/weather/forecast.rb', line 320

def outlook_brief
  mypart.elements['bt'].text
end

#popObject Also known as: ppcp



324
325
326
# File 'lib/weather/forecast.rb', line 324

def pop
  mypart.elements['ppcp'].text.to_i
end

#sunriseObject



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

#sunsetObject



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 # add 12 since we need 24 hour clock and sunset is always (?) in the PM
  minute = minute.to_i
  Time.local(date.year, date.month, date.day, hour, minute)
end

#windObject



289
290
291
# File 'lib/weather/forecast.rb', line 289

def wind
  fix_wind(complex_attribute(mypart.elements['wind']))
end