shipping-forecast 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/shipping_forecast.rb +73 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44ab3dff9fe31c2e2457decacab42dbbb9d807d1
|
4
|
+
data.tar.gz: 60fc5367c05599971be2e3e52b437059b6a03436
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8bfc1018065308325ffc58a277f93bb1488044f83664ca03399263c139b213ae26bd471154f407a380c22ff27ed6fee97b1b84d7bbe22cc1aa5707935b05c84
|
7
|
+
data.tar.gz: 6de1341cb3c9d2d6fe2c892929717a572b01ca0ab26b4880d850a3a3cc0b55b84e1a071ff0ee5ea5ccc2d2c75772d6ff64f74483fa635219b221101962c52b78
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
class ShippingForecast
|
5
|
+
URL = "http://www.bbc.co.uk/weather/coast_and_sea/shipping_forecast"
|
6
|
+
|
7
|
+
# Public: Returns a hash of OpenStruct objects, each representint a location report
|
8
|
+
def self.report
|
9
|
+
@raw_report ||= new.raw_report
|
10
|
+
end
|
11
|
+
|
12
|
+
# Public: Returns a forecast for a particular location
|
13
|
+
def self.[] location
|
14
|
+
report[location]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Public: Returns all forecasts
|
18
|
+
def self.all
|
19
|
+
report
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Returns an array of strings of each available location
|
23
|
+
def self.locations
|
24
|
+
report.keys.sort
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@built = false
|
29
|
+
@data = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def raw_report
|
33
|
+
build_data unless @built
|
34
|
+
@data
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def build_data
|
40
|
+
agent = Mechanize.new
|
41
|
+
page = agent.get(URL)
|
42
|
+
|
43
|
+
locations = {}
|
44
|
+
|
45
|
+
1.upto(31) do |i|
|
46
|
+
area = page.search("#area-#{i}")
|
47
|
+
location = area.search("h2").text
|
48
|
+
|
49
|
+
# Warnings, if any
|
50
|
+
warning = OpenStruct.new
|
51
|
+
warning_detail = area.search(".warning-detail")
|
52
|
+
warning[:title] = warning_detail.search("strong").text.gsub(':', '')
|
53
|
+
warning[:issued] = warning_detail.search(".issued").text
|
54
|
+
warning[:summary] = warning_detail.search(".summary").text
|
55
|
+
|
56
|
+
# Build the hash
|
57
|
+
area_hash = OpenStruct.new
|
58
|
+
breakdown = area.search("ul").children.search("span")
|
59
|
+
|
60
|
+
area_hash[:warning] = warning
|
61
|
+
area_hash[:location] = location
|
62
|
+
area_hash[:wind] = breakdown[0].text
|
63
|
+
area_hash[:seas] = breakdown[1].text
|
64
|
+
area_hash[:weather] = breakdown[2].text
|
65
|
+
area_hash[:visibility] = breakdown[3].text
|
66
|
+
|
67
|
+
locations[location] = area_hash
|
68
|
+
end
|
69
|
+
|
70
|
+
@data = locations
|
71
|
+
@built = true
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shipping-forecast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ted Nyman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/shipping_forecast.rb
|
34
|
+
homepage: https://github.com/tnm/shipping-forecast
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.0.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Ruby wrapper for the BBC's shipping forecast
|
58
|
+
test_files: []
|