Class WeatherReportForecasts
In: lib/weather_report.rb
Parent: Array

A collection of forecasts for a particular location

Methods

for   for_today   for_tomorrow   new  

Included Modules

WeatherReportLocation

Classes and Modules

Class WeatherReportForecasts::WeatherReportForecast

Attributes

image_url  [R] 
reading_date  [R] 

Public Class methods

Constructs the weather forecasts from an XML string or file containing the XML in BBC Backstage weather format

[Source]

# 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

Public Instance methods

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.

[Source]

# 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

Returns the forecast for today, or nil is there is no such forecast.

[Source]

# File lib/weather_report.rb, line 152
  def for_today
    self.for(Date.today)
  end

Returns the forecast for tomorrow, or nil is there is no such forecast.

[Source]

# File lib/weather_report.rb, line 157
  def for_tomorrow
    self.for(Date.today+1)
  end

[Validate]