Class: WeatherBug::Forecast
- Inherits:
-
TransformableData
- Object
- TransformableData
- WeatherBug::Forecast
- Defined in:
- lib/weatherbug/forecast.rb
Instance Method Summary collapse
Methods inherited from TransformableData
from_document, register_transformer
Instance Method Details
#date ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/weatherbug/forecast.rb', line 16 def date date ||= begin key = title.split[0] # Remove 'night' return Date.today if key == 'Today' || key == 'Tonight' return Date.today + 1 if key == 'Tomorrow' # Figure out how far forward to go return nil unless appropriate_wday_index = Date::DAYNAMES.index(key) today_index = Date.today.wday distance = appropriate_wday_index - today_index Date.today + (distance > 0 ? distance : distance + 7) end end |