| Class | WeatherReportForecasts |
| In: |
lib/weather_report.rb
|
| Parent: | Array |
A collection of forecasts for a particular location
| image_url | [R] | |
| reading_date | [R] |
Constructs the weather forecasts from an XML string or file containing the XML in BBC Backstage weather format
# File lib/weather_report.rb, line 135 def initialize(document) doc = REXML::Document.new document @reading_date = DateTime.now loadLocation(doc) doc.elements.each("rss/channel/image/url") { |element| @image_url = element.text } doc.elements.each("rss/channel/item/") { |element| self << WeatherReportForecast.new(element) } raise WeatherReport::WeatherReportFormatError if length == 0 rescue raise WeatherReport::WeatherReportFormatError end
Returns a forecast for a day given by a Date, DateTime, Time, or a string that can be parsed to a date. If there is no forecast for the given date then nil is returned.
# File lib/weather_report.rb, line 163 def for(date = Date.today) date = case date.class.name when 'String' Date.parse(date) when 'Date' date when 'DateTime' Date.new(date.year, date.month, date.day) when 'Time' Date.new(date.year, date.month, date.day) end day = nil self.each do |fd| day = fd if date == fd.date end return day end