Class: WeatherReportObservation

Inherits:
Object
  • Object
show all
Includes:
WeatherReportLocation
Defined in:
lib/weather_report.rb

Overview

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

Constant Summary collapse

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

Constants included from WeatherReportLocation

WeatherReportLocation::TITLE

Instance Attribute Summary collapse

Attributes included from WeatherReportLocation

#country, #latitude, #longtitude, #name

Instance Method Summary collapse

Methods included from WeatherReportLocation

#loadLocation

Constructor Details

#initialize(document) ⇒ WeatherReportObservation

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



95
96
97
# File 'lib/weather_report.rb', line 95

def description
  @description
end

#humidityObject (readonly)

Returns the value of attribute humidity.



95
96
97
# File 'lib/weather_report.rb', line 95

def humidity
  @humidity
end

#pressureObject (readonly)

Returns the value of attribute pressure.



95
96
97
# File 'lib/weather_report.rb', line 95

def pressure
  @pressure
end

#pressure_stateObject (readonly)

Returns the value of attribute pressure_state.



95
96
97
# File 'lib/weather_report.rb', line 95

def pressure_state
  @pressure_state
end

#reading_dateObject (readonly)

Returns the value of attribute reading_date.



95
96
97
# File 'lib/weather_report.rb', line 95

def reading_date
  @reading_date
end

#temperatureObject (readonly)

Returns the value of attribute temperature.



95
96
97
# File 'lib/weather_report.rb', line 95

def temperature
  @temperature
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



95
96
97
# File 'lib/weather_report.rb', line 95

def visibility
  @visibility
end

#wind_directionObject (readonly)

Returns the value of attribute wind_direction.



95
96
97
# File 'lib/weather_report.rb', line 95

def wind_direction
  @wind_direction
end

#wind_speedObject (readonly)

Returns the value of attribute wind_speed.



95
96
97
# File 'lib/weather_report.rb', line 95

def wind_speed
  @wind_speed
end