Class: WeatherReportForecasts::WeatherReportForecast
- Inherits:
-
Object
- Object
- WeatherReportForecasts::WeatherReportForecast
- Defined in:
- lib/weather_report.rb
Overview
A forecast for a single day
Constant Summary collapse
- SUMMARY =
/([\w -\/]+): ([\w -]+|N\/A|NA|\(none\)), Max Temp: (.*)/m
- DESCRIPTION =
/Max Temp: ([-\d\.]+|N\/A|NA|\(none\))(.+)Min Temp: ([-\d\.]+|N\/A|NA|\(none\))(.+)Wind Direction: ([\w -\/\(\)]*), Wind Speed: ([-\d\.]+|N\/A|NA|\(none\))mph, Visibility: ([\w -\/]+), Pressure: ([\d\.]+|N\/A|NA|\(none\))mB, Humidity: ([\d\.]+|N\/A|NA|\(none\))(.*), (.+)/m
Instance Attribute Summary collapse
-
#advance_days ⇒ Object
readonly
Returns the value of attribute advance_days.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#humidity ⇒ Object
readonly
Returns the value of attribute humidity.
-
#max_temperature ⇒ Object
readonly
Returns the value of attribute max_temperature.
-
#min_temperature ⇒ Object
readonly
Returns the value of attribute min_temperature.
-
#pressure ⇒ Object
readonly
Returns the value of attribute pressure.
-
#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.
Instance Method Summary collapse
-
#initialize(item) ⇒ WeatherReportForecast
constructor
Constructs the single day forecast from an REXML element containing the forecast in BBC Backstage weather format.
Constructor Details
#initialize(item) ⇒ WeatherReportForecast
Constructs the single day forecast from an REXML element containing the forecast in BBC Backstage weather format
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/weather_report.rb', line 189 def initialize(item) item.elements.each("title[1]") { |element| md = SUMMARY.match(element.text) @description = md[2] @advance_days = day_diff(md[1]) raise(WeatherReport::WeatherReportFormatError, "WeatherReport Error: Day mismatch.") if @advance_days.nil? @date = Date.today+@advance_days } item.elements.each("description[1]") { |element| md = DESCRIPTION.match(element.text) @max_temperature = md[1].to_f @min_temperature = md[3].to_f @wind_direction = md[5] @wind_speed = md[6].to_f * 1.61 @visibility = md[7] @pressure = md[8].to_f @humidity = md[9].to_f } end |
Instance Attribute Details
#advance_days ⇒ Object (readonly)
Returns the value of attribute advance_days.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def advance_days @advance_days end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def date @date end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def description @description end |
#humidity ⇒ Object (readonly)
Returns the value of attribute humidity.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def humidity @humidity end |
#max_temperature ⇒ Object (readonly)
Returns the value of attribute max_temperature.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def max_temperature @max_temperature end |
#min_temperature ⇒ Object (readonly)
Returns the value of attribute min_temperature.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def min_temperature @min_temperature end |
#pressure ⇒ Object (readonly)
Returns the value of attribute pressure.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def pressure @pressure end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def visibility @visibility end |
#wind_direction ⇒ Object (readonly)
Returns the value of attribute wind_direction.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def wind_direction @wind_direction end |
#wind_speed ⇒ Object (readonly)
Returns the value of attribute wind_speed.
186 187 188 |
# File 'lib/weather_report.rb', line 186 def wind_speed @wind_speed end |