Class WeatherReportObservation
In: lib/weather_report.rb
Parent: Object

The current weather observations (at least at the time of reading - given by attribute reading_date)

Methods

new  

Included Modules

WeatherReportLocation

Constants

DESCRIPTION = /(.*)Temperature: ([-\d\.]+|N\/A|NA|\(none\))(.+)Wind Direction: ([\w -\/\(\)]*), Wind Speed: ([-\d\.]+|N\/A|NA|\(none\))([ ]*)mph, Relative Humidity: ([\d\.]+|N\/A|NA|\(none\))(.*), Pressure: ([\d\.]+|N\/A|NA|\(none\))mB, ([\w -\/]+), Visibility: ([\w -\/]+)/
SUMMARY = /(.+):(\W+)([\w -\/\(\)]+). (.+)/m

Attributes

description  [R] 
humidity  [R] 
pressure  [R] 
pressure_state  [R] 
reading_date  [R] 
temperature  [R] 
visibility  [R] 
wind_direction  [R] 
wind_speed  [R] 

Public Class methods

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

[Source]

# File lib/weather_report.rb, line 98
  def initialize(document)
    doc = REXML::Document.new document
    
    loadLocation(doc)
    @reading_date = DateTime.now
    doc.elements.each("rss/channel/item[1]/title[1]") { |element| 
      md = SUMMARY.match(element.text)
      @description = md[3]
    }
      
    hasDesc = false
    doc.elements.each("rss/channel/item[1]/description[1]") { |element| 
      hasDesc = true
      md = DESCRIPTION.match(element.text)
      @temperature = md[2].to_f
      @wind_direction = md[4]
      @wind_speed = md[5].to_f * 1.61
      @humidity = md[7].to_f
      @pressure = md[9].to_f
      @pressure_state = md[10]
      @visibility = md[11]
    }
    raise WeatherReport::WeatherReportFormatError unless hasDesc
    
    rescue
      raise WeatherReport::WeatherReportFormatError
  end

[Validate]