Class: ShippingForecast
- Inherits:
-
Object
- Object
- ShippingForecast
- 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
-
.[](location) ⇒ Object
Public: Returns a forecast for a particular location.
-
.all ⇒ Object
Public: Returns all forecasts.
-
.locations ⇒ Object
Public: Returns an array of strings of each available location.
-
.report ⇒ Object
Public: Returns a hash of OpenStruct objects, each representing a location report.
Instance Method Summary collapse
-
#initialize ⇒ ShippingForecast
constructor
A new instance of ShippingForecast.
- #raw_report ⇒ Object
Constructor Details
#initialize ⇒ ShippingForecast
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 |
.all ⇒ Object
Public: Returns all forecasts
27 28 29 |
# File 'lib/shipping_forecast.rb', line 27 def self.all report end |
.locations ⇒ Object
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 |
.report ⇒ Object
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_report ⇒ Object
41 42 43 44 |
# File 'lib/shipping_forecast.rb', line 41 def raw_report build_data unless @built @data end |