Class: ShippingForecast

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

Constant Summary collapse

URL =
"http://www.bbc.co.uk/weather/coast_and_sea/shipping_forecast"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShippingForecast

Returns a new instance of ShippingForecast.



36
37
38
39
# File 'lib/shipping_forecast.rb', line 36

def initialize
  @built = false
  @data  = nil
end

Class Method Details

.[](location) ⇒ Object

Public: Returns a forecast for a particular location



22
23
24
# File 'lib/shipping_forecast.rb', line 22

def self.[] location
  report[location]
end

.allObject

Public: Returns all forecasts



27
28
29
# File 'lib/shipping_forecast.rb', line 27

def self.all
  report
end

.locationsObject

Public: Returns an array of strings of each available location



32
33
34
# File 'lib/shipping_forecast.rb', line 32

def self.locations
  report.keys.sort
end

.reportObject

Public: Returns a hash of OpenStruct objects, each representing a location report.

Contents of each report:

warning    — If there is a warning in effect, returns an OpenStruct object with attributes:
title      – The title of the warning, e.g., "Gale Warning"
issued     – When the warning was issued
summary    – The text summary of the warning
wind       – The wind conditions
seas       – The current sea conditions
visibility – The current visibility report


17
18
19
# File 'lib/shipping_forecast.rb', line 17

def self.report
  @raw_report ||= new.raw_report
end

Instance Method Details

#raw_reportObject



41
42
43
44
# File 'lib/shipping_forecast.rb', line 41

def raw_report
  build_data unless @built
  @data
end