gull 0.2.5 → 0.2.6
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 +4 -4
- data/.travis.yml +0 -1
- data/Gemfile +3 -1
- data/README.md +3 -0
- data/lib/gull/alert.rb +55 -26
- data/lib/gull/polygon.rb +21 -14
- data/lib/gull/version.rb +1 -1
- data/spec/alert_spec.rb +15 -0
- data/spec/alerts.xml +3 -10
- data/spec/polygon_spec.rb +6 -1
- data/spec/spec_helper.rb +3 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f8ba1e8fee402da22e749c1bad3a124fc651a2f
|
4
|
+
data.tar.gz: 8f70d1c10a8d43c881fc8dea2dd72e2eb8f330b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6c4d5e252999784b82543286207c000ad73cda7e09f74528eb77323526707e636d1e5443f25e210c53ce47381d55bdc46c4604b501889feece09ba2579d33c
|
7
|
+
data.tar.gz: dc89faa462d182d3fbcc45da46c63d9e58ff6d7d6303d9e813778c152c8cfbb9e35aac23bd5b6a56bf2715c8ae141b6f1784327c561d862c5e26083549f3af56
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
[](http://badge.fury.io/rb/gull)
|
2
2
|
[](https://travis-ci.org/sethdeckard/gull)
|
3
|
+
[](https://coveralls.io/r/sethdeckard/gull)
|
4
|
+
[](https://codeclimate.com/github/sethdeckard/gull)
|
5
|
+
[](https://gemnasium.com/sethdeckard/gull)
|
3
6
|
# Gull
|
4
7
|
|
5
8
|
Ruby client for parsing NOAA/NWS alerts, warnings, and watches. The name comes from the type of bird featured on the NOAA logo.
|
data/lib/gull/alert.rb
CHANGED
@@ -3,8 +3,8 @@ require 'nokogiri'
|
|
3
3
|
|
4
4
|
module Gull
|
5
5
|
class Alert
|
6
|
-
attr_accessor :id, :title, :summary, :alert_type, :polygon, :area, :effective_at,
|
7
|
-
:urgency, :severity, :certainty, :geocode
|
6
|
+
attr_accessor :id, :title, :summary, :link, :alert_type, :polygon, :area, :effective_at,
|
7
|
+
:expires_at, :updated_at, :published_at, :urgency, :severity, :certainty, :geocode, :vtec
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
self.geocode = Geocode.new
|
@@ -17,40 +17,69 @@ module Gull
|
|
17
17
|
self.process document.css('feed/entry')
|
18
18
|
end
|
19
19
|
|
20
|
+
def parse element
|
21
|
+
self.id = element.css('id').inner_text
|
22
|
+
self.title = element.css('title').inner_text
|
23
|
+
self.summary = element.css('summary').inner_text
|
24
|
+
self.link = element.css('link').first.attributes["href"].value
|
25
|
+
self.alert_type = element.xpath('cap:event').inner_text
|
26
|
+
self.area = element.xpath('cap:areaDesc').inner_text
|
27
|
+
|
28
|
+
parse_times element
|
29
|
+
parse_categories element
|
30
|
+
|
31
|
+
parse_polygon element.xpath('cap:polygon').inner_text
|
32
|
+
parse_geocode element.xpath('cap:geocode')
|
33
|
+
parse_vtec element.xpath('cap:parameter')
|
34
|
+
end
|
35
|
+
|
20
36
|
private
|
21
37
|
|
22
38
|
def self.process entries
|
23
39
|
alerts = []
|
24
40
|
entries.each do |entry|
|
25
|
-
|
26
|
-
alert.id = entry.css('id').inner_text
|
27
|
-
alert.alert_type = entry.xpath('cap:event').inner_text
|
28
|
-
alert.title = entry.css('title').inner_text
|
29
|
-
alert.summary = entry.css('summary').inner_text
|
30
|
-
|
31
|
-
polygon = entry.xpath('cap:polygon').inner_text
|
32
|
-
unless polygon.empty?
|
33
|
-
alert.polygon = Polygon.new polygon
|
34
|
-
end
|
35
|
-
|
36
|
-
alert.area = entry.xpath('cap:areaDesc').inner_text
|
37
|
-
alert.effective_at = Time.parse(entry.xpath('cap:effective').inner_text).utc
|
38
|
-
alert.expires_at = Time.parse(entry.xpath('cap:expires').inner_text).utc
|
39
|
-
alert.urgency = code_to_symbol entry.xpath('cap:urgency').inner_text
|
40
|
-
alert.severity = code_to_symbol entry.xpath('cap:severity').inner_text
|
41
|
-
alert.certainty = code_to_symbol entry.xpath('cap:certainty').inner_text
|
42
|
-
|
43
|
-
geocode = entry.xpath('cap:geocode')
|
44
|
-
alert.geocode.fips6 = geocode.children.css('value').first.inner_text
|
45
|
-
alert.geocode.ugc = geocode.children.css('value').last.inner_text
|
46
|
-
|
47
|
-
alerts.push alert
|
41
|
+
alerts.push create_instance entry
|
48
42
|
end
|
49
43
|
|
50
44
|
alerts
|
51
45
|
end
|
52
46
|
|
53
|
-
def self.
|
47
|
+
def self.create_instance entry
|
48
|
+
alert = Alert.new
|
49
|
+
alert.parse entry
|
50
|
+
alert
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_times element
|
54
|
+
self.updated_at = Time.parse(element.css('updated').inner_text).utc
|
55
|
+
self.published_at = Time.parse(element.css('published').inner_text).utc
|
56
|
+
self.effective_at = Time.parse(element.xpath('cap:effective').inner_text).utc
|
57
|
+
self.expires_at = Time.parse(element.xpath('cap:expires').inner_text).utc
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_categories element
|
61
|
+
self.urgency = code_to_symbol element.xpath('cap:urgency').inner_text
|
62
|
+
self.severity = code_to_symbol element.xpath('cap:severity').inner_text
|
63
|
+
self.certainty = code_to_symbol element.xpath('cap:certainty').inner_text
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_polygon text
|
67
|
+
unless text.empty?
|
68
|
+
self.polygon = Polygon.new text
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_geocode element
|
73
|
+
self.geocode.fips6 = element.children.css('value').first.inner_text
|
74
|
+
self.geocode.ugc = element.children.css('value').last.inner_text
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_vtec element
|
78
|
+
value = element.children.css('value').inner_text
|
79
|
+
self.vtec = value.empty? ? nil : value
|
80
|
+
end
|
81
|
+
|
82
|
+
def code_to_symbol code
|
54
83
|
code.gsub(' ','_').downcase.to_sym
|
55
84
|
end
|
56
85
|
|
data/lib/gull/polygon.rb
CHANGED
@@ -7,22 +7,19 @@ module Gull
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def centroid
|
10
|
-
low_x
|
10
|
+
low_x = 0
|
11
|
+
low_y = 0
|
12
|
+
high_x = 0
|
13
|
+
high_y = 0
|
11
14
|
|
12
15
|
coordinates.each do |pair|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
longitude = pair.last
|
21
|
-
if longitude < low_y or low_y == 0
|
22
|
-
low_y = longitude
|
23
|
-
elsif longitude > high_y or high_y == 0
|
24
|
-
high_y = longitude
|
25
|
-
end
|
16
|
+
x_bounds = bounds pair.first, low_x, high_x
|
17
|
+
low_x = x_bounds.first
|
18
|
+
high_x = x_bounds.last
|
19
|
+
|
20
|
+
y_bounds = bounds pair.last, low_y, high_y
|
21
|
+
low_y = y_bounds.first
|
22
|
+
high_y = y_bounds.last
|
26
23
|
end
|
27
24
|
|
28
25
|
center_x = low_x + ((high_x - low_x) / 2)
|
@@ -48,6 +45,16 @@ module Gull
|
|
48
45
|
|
49
46
|
private
|
50
47
|
|
48
|
+
def bounds point, low, high
|
49
|
+
if point < low or low == 0
|
50
|
+
low = point
|
51
|
+
elsif point > high or high == 0
|
52
|
+
high = point
|
53
|
+
end
|
54
|
+
|
55
|
+
[low, high]
|
56
|
+
end
|
57
|
+
|
51
58
|
def coordinates_piped
|
52
59
|
coordinates.collect {|pair| pair.join "," }.join "|"
|
53
60
|
end
|
data/lib/gull/version.rb
CHANGED
data/spec/alert_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gull::Alert do
|
4
|
+
it "should initialize with geocode" do
|
5
|
+
alert = Gull::Alert.new
|
6
|
+
expect(alert.geocode).not_to be_nil
|
7
|
+
end
|
8
|
+
|
4
9
|
it "should fetch parsed alerts" do
|
5
10
|
xml = File.read "spec/alerts.xml"
|
6
11
|
|
@@ -13,6 +18,7 @@ describe Gull::Alert do
|
|
13
18
|
|
14
19
|
first = alerts.first
|
15
20
|
expect(first.id).to eq "http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory"
|
21
|
+
expect(first.link).to eq "http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory"
|
16
22
|
expect(first.alert_type).to eq "Heat Advisory"
|
17
23
|
expect(first.title).to eq "Heat Advisory issued October 01 at 8:40AM PDT until October 03 at 9:00PM PDT by NWS"
|
18
24
|
expect(first.summary).to eq "SUMMARY TEXT"
|
@@ -23,6 +29,9 @@ describe Gull::Alert do
|
|
23
29
|
|
24
30
|
expect(first.effective_at).to eq Time.parse("2014-10-01T08:40:00-07:00")
|
25
31
|
expect(first.expires_at).to eq Time.parse("2014-10-03T21:00:00-07:00")
|
32
|
+
expect(first.updated_at).to eq Time.parse("2014-10-01T08:40:00-07:05")
|
33
|
+
expect(first.published_at).to eq Time.parse("2014-10-01T08:40:00-07:06")
|
34
|
+
|
26
35
|
expect(first.area).to eq "Southern Salinas Valley, Arroyo Seco and Lake San Antonio"
|
27
36
|
expect(first.urgency).to eq :expected
|
28
37
|
expect(first.severity).to eq :minor
|
@@ -31,7 +40,13 @@ describe Gull::Alert do
|
|
31
40
|
expect(first.geocode.fips6).to eq "006001 006013 006041 006053 006055 006069 006075 006081 006085 006087 006097"
|
32
41
|
expect(first.geocode.ugc).to eq "CAZ006 CAZ505 CAZ506 CAZ507 CAZ508 CAZ509 CAZ510 CAZ511 CAZ512"
|
33
42
|
|
43
|
+
expect(first.vtec).to eq "/O.NEW.KMTR.HT.Y.0002.141002T1900Z-141004T0400Z/"
|
44
|
+
|
34
45
|
second = alerts[1]
|
35
46
|
expect(second.polygon).to be_nil
|
47
|
+
expect(second.vtec).to be_nil
|
48
|
+
|
49
|
+
third = alerts[2]
|
50
|
+
expect(third.vtec).to be_nil
|
36
51
|
end
|
37
52
|
end
|
data/spec/alerts.xml
CHANGED
@@ -30,13 +30,13 @@ xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
|
|
30
30
|
|
31
31
|
<entry>
|
32
32
|
<id>http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory</id>
|
33
|
-
<updated>2014-10-01T08:40:00-07:
|
34
|
-
<published>2014-10-01T08:40:00-07:
|
33
|
+
<updated>2014-10-01T08:40:00-07:05</updated>
|
34
|
+
<published>2014-10-01T08:40:00-07:06</published>
|
35
35
|
<author>
|
36
36
|
<name>w-nws.webmaster@noaa.gov</name>
|
37
37
|
</author>
|
38
38
|
<title>Heat Advisory issued October 01 at 8:40AM PDT until October 03 at 9:00PM PDT by NWS</title>
|
39
|
-
<link href='http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory
|
39
|
+
<link href='http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory'/>
|
40
40
|
<summary>SUMMARY TEXT</summary>
|
41
41
|
<cap:event>Heat Advisory</cap:event>
|
42
42
|
<cap:effective>2014-10-01T08:40:00-07:00</cap:effective>
|
@@ -61,7 +61,6 @@ xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
|
|
61
61
|
</cap:parameter>
|
62
62
|
</entry>
|
63
63
|
|
64
|
-
|
65
64
|
<entry>
|
66
65
|
<id>http://alerts.weather.gov/cap/wwacapget.php?x=CA125171381DD0.HeatAdvisory.125171642740CA.MTRNPWMTR.64d60221994d798a87b4862623e0d63c</id>
|
67
66
|
<updated>2014-10-01T08:40:00-07:00</updated>
|
@@ -90,8 +89,6 @@ xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
|
|
90
89
|
<value>CAZ006 CAZ505 CAZ506 CAZ507 CAZ508 CAZ509 CAZ510 CAZ511 CAZ512 CAZ513 CAZ516 CAZ517 CAZ518 CAZ528 CAZ529 CAZ530</value>
|
91
90
|
</cap:geocode>
|
92
91
|
<cap:parameter>
|
93
|
-
<valueName>VTEC</valueName>
|
94
|
-
<value>/O.NEW.KMTR.HT.Y.0002.141002T1900Z-141004T0400Z/</value>
|
95
92
|
</cap:parameter>
|
96
93
|
</entry>
|
97
94
|
|
@@ -122,9 +119,5 @@ xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
|
|
122
119
|
<valueName>UGC</valueName>
|
123
120
|
<value>CAZ006 CAZ505 CAZ506 CAZ507 CAZ508 CAZ509 CAZ510 CAZ511 CAZ512 CAZ513 CAZ516 CAZ517 CAZ518 CAZ528 CAZ529 CAZ530</value>
|
124
121
|
</cap:geocode>
|
125
|
-
<cap:parameter>
|
126
|
-
<valueName>VTEC</valueName>
|
127
|
-
<value>/O.NEW.KMTR.HT.Y.0002.141002T1900Z-141004T0400Z/</value>
|
128
|
-
</cap:parameter>
|
129
122
|
</entry>
|
130
123
|
</feed>
|
data/spec/polygon_spec.rb
CHANGED
@@ -4,8 +4,13 @@ describe Gull::Polygon do
|
|
4
4
|
it "should return centroid of polygon" do
|
5
5
|
polygon = Gull::Polygon.new "34.57,-97.56 34.77,-97.38 34.75,-97.17 34.64,-97.11 34.64,-97.14 " +
|
6
6
|
"34.62,-97.14 34.62,-97.2 34.6,-97.19 34.59,-97.17 34.57,-97.17 34.5,-97.3 34.51,-97.56 34.57,-97.56"
|
7
|
-
|
8
7
|
expect(polygon.centroid).to eq [34.635000000000005, -97.33500000000001]
|
8
|
+
|
9
|
+
polygon = Gull::Polygon.new "30.71,-86.4 30.78,-86.04 30.27,-86.01 30.35,-86.28 30.37,-86.4 30.39,-86.4 30.4,-86.4 30.4,-86.34 30.43,-86.32 30.4,-86.29 30.43,-86.25 30.39,-86.16 30.39,-86.13 30.47,-86.21 30.48,-86.26 30.46,-86.4 30.71,-86.4"
|
10
|
+
expect(polygon.centroid).to eq [30.525, -86.20500000000001]
|
11
|
+
|
12
|
+
polygon = Gull::Polygon.new "30.39,-86.59 30.38,-86.8 30.79,-86.72 30.78,-86.38 30.45,-86.39 30.44,-86.42 30.48,-86.46 30.45,-86.49 30.42,-86.59 30.4,-86.58 30.4,-86.53 30.42,-86.49 30.42,-86.44 30.41,-86.4 30.38,-86.39 30.37,-86.4 30.39,-86.59"
|
13
|
+
expect(polygon.centroid).to eq [30.58, -86.59]
|
9
14
|
end
|
10
15
|
|
11
16
|
it "should return static map image url" do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,9 @@ require 'gull/polygon'
|
|
3
3
|
require 'gull/geocode'
|
4
4
|
require 'webmock/rspec'
|
5
5
|
|
6
|
+
require 'coveralls'
|
7
|
+
Coveralls.wear!
|
8
|
+
|
6
9
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
10
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
11
|
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Deckard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|