Class: Weather::Forecast::Conditions

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

Overview

Abstract class that all Forecast entities are based on.

Direct Known Subclasses

CurrentConditions, FutureConditions

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol) ⇒ Object

For elements in the forecast that we have not defined an explicit accessor, this allows accessing the raw underlying data in the forecast xml.



157
158
159
160
161
162
163
# File 'lib/weather/forecast.rb', line 157

def method_missing(symbol)
  begin
    return @xml.elements[symbol.to_s].text
  rescue NoMethodError
    return "N/A"
  end
end

Instance Method Details

#latest_updateObject

The date and time when the conditions were last measured/forecast. Returned as a Time object.



175
176
177
# File 'lib/weather/forecast.rb', line 175

def latest_update
  Time.parse(self.lsup)
end

#windObject

The wind conditions as an anonymous object (i.e. wind.d or wind.direction for wind direction, wind.s or wind.speed for wind speed, wind.h or wind.heading for heading, etc.) See the <wind> element in the weather.com XML data spec for more info.



169
170
171
# File 'lib/weather/forecast.rb', line 169

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