Class: WeatherReportForecasts::WeatherReportForecast

Inherits:
Object
  • Object
show all
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\))m([bB]), Humidity: ([\d\.]+|N\/A|NA|\(none\))(.*), (.+)/m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ WeatherReportForecast

Constructs the single day forecast from an REXML element containing the forecast in BBC Backstage weather format



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/weather_report.rb', line 191

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[10].to_f
  }
end

Instance Attribute Details

#advance_daysObject (readonly)

Returns the value of attribute advance_days.



188
189
190
# File 'lib/weather_report.rb', line 188

def advance_days
  @advance_days
end

#dateObject (readonly)

Returns the value of attribute date.



188
189
190
# File 'lib/weather_report.rb', line 188

def date
  @date
end

#descriptionObject (readonly)

Returns the value of attribute description.



188
189
190
# File 'lib/weather_report.rb', line 188

def description
  @description
end

#humidityObject (readonly)

Returns the value of attribute humidity.



188
189
190
# File 'lib/weather_report.rb', line 188

def humidity
  @humidity
end

#max_temperatureObject (readonly)

Returns the value of attribute max_temperature.



188
189
190
# File 'lib/weather_report.rb', line 188

def max_temperature
  @max_temperature
end

#min_temperatureObject (readonly)

Returns the value of attribute min_temperature.



188
189
190
# File 'lib/weather_report.rb', line 188

def min_temperature
  @min_temperature
end

#pressureObject (readonly)

Returns the value of attribute pressure.



188
189
190
# File 'lib/weather_report.rb', line 188

def pressure
  @pressure
end

#visibilityObject (readonly)

Returns the value of attribute visibility.



188
189
190
# File 'lib/weather_report.rb', line 188

def visibility
  @visibility
end

#wind_directionObject (readonly)

Returns the value of attribute wind_direction.



188
189
190
# File 'lib/weather_report.rb', line 188

def wind_direction
  @wind_direction
end

#wind_speedObject (readonly)

Returns the value of attribute wind_speed.



188
189
190
# File 'lib/weather_report.rb', line 188

def wind_speed
  @wind_speed
end