Class: WeatherReport

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

Overview

Class containing weather observations and forecasts for the location specified by id in the constructor.

Defined Under Namespace

Classes: WeatherReportFormatError, WeatherReportNoResponseError

Constant Summary collapse

VERSION =
'0.0.4'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location_id) ⇒ WeatherReport

Requires a valid BBC Backstage weather id (or any call to the API will return a FormatError)



24
25
26
# File 'lib/weather_report.rb', line 24

def initialize(location_id)
  @id = location_id
end

Instance Attribute Details

#idObject (readonly)

The id is the number (1..9999) the BBC uses to identify cities for weather reports



13
14
15
# File 'lib/weather_report.rb', line 13

def id
  @id
end

Instance Method Details

#forecast(force_reload = false) ⇒ Object

Returns the weather forecast for the current id. If one is not currently loaded then this will go to the BBC Backstage API and download it. Alternatively, by specifying force_reload = true the observation will be loaded from the BBC regardless of whether one has already been downloaded.



37
38
39
40
# File 'lib/weather_report.rb', line 37

def forecast(force_reload = false) 
  @forecast = WeatherReportForecasts.new(fetch(forecast_url())) if force_reload or @forecast.nil?
  @forecast
end

#observation(force_reload = false) ⇒ Object

Returns the weather observation for the current id. If one is not currently loaded then this will go to the BBC Backstage API and download it. Alternatively, by specifying force_reload = true the observation will be loaded from the BBC regardless of whether one has already been downloaded.



30
31
32
33
# File 'lib/weather_report.rb', line 30

def observation(force_reload = false) 
  @observation = WeatherReportObservation.new(fetch(observation_url())) if force_reload or @observation.nil?
  @observation
end