Class: WeatherReportObservation
- Inherits:
-
Object
- Object
- WeatherReportObservation
- 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
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#humidity ⇒ Object
readonly
Returns the value of attribute humidity.
-
#pressure ⇒ Object
readonly
Returns the value of attribute pressure.
-
#pressure_state ⇒ Object
readonly
Returns the value of attribute pressure_state.
-
#reading_date ⇒ Object
readonly
Returns the value of attribute reading_date.
-
#temperature ⇒ Object
readonly
Returns the value of attribute temperature.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
-
#wind_direction ⇒ Object
readonly
Returns the value of attribute wind_direction.
-
#wind_speed ⇒ Object
readonly
Returns the value of attribute wind_speed.
Attributes included from WeatherReportLocation
#country, #latitude, #longtitude, #name
Instance Method Summary collapse
-
#initialize(document) ⇒ WeatherReportObservation
constructor
Constructs the weather observation from an XML string or file containing the XML in BBC Backstage weather format.
Methods included from WeatherReportLocation
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def description @description end |
#humidity ⇒ Object (readonly)
Returns the value of attribute humidity.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def humidity @humidity end |
#pressure ⇒ Object (readonly)
Returns the value of attribute pressure.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def pressure @pressure end |
#pressure_state ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute reading_date.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def reading_date @reading_date end |
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def temperature @temperature end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def visibility @visibility end |
#wind_direction ⇒ Object (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_speed ⇒ Object (readonly)
Returns the value of attribute wind_speed.
95 96 97 |
# File 'lib/weather_report.rb', line 95 def wind_speed @wind_speed end |