gull 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/lib/gull.rb +3 -2
- data/lib/gull/alert.rb +2 -2
- data/lib/gull/polygon.rb +55 -0
- data/lib/gull/version.rb +1 -1
- data/spec/alert_spec.rb +5 -2
- data/spec/polygon_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b71dcd8c218e39baaffae9d2162bd6e8b1f7f41a
|
4
|
+
data.tar.gz: d46c989dcfd01455ae509db7577ee1f9ce6e8746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4783c7343fe5b92a2e16750f284d08bee542d7704cb0ab44735fbd2f4db4f6d4f1c03108fec976cefd445f0e00514e08cdabc0f5f0fed31d6190a4519b32b87
|
7
|
+
data.tar.gz: 226fbdd9b111f73411f3818805aeee29a24354a6a65856bf9307ba6f75b314a67acc0559140822095abb49f474cab78e9130fa5ddbfec3755b38f8004b9a8a75
|
data/README.md
CHANGED
@@ -21,7 +21,22 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
require 'gull/alert'
|
23
23
|
|
24
|
-
Gull::Alert.fetch
|
24
|
+
alerts = Gull::Alert.fetch
|
25
|
+
alert = alert.first
|
26
|
+
|
27
|
+
#Generate map of polygon (if alert has one)
|
28
|
+
#requires Google Static Maps API Key
|
29
|
+
url = alert.polygon.image_url "your_api_key"
|
30
|
+
|
31
|
+
puts url
|
32
|
+
=> "http://maps.googleapis.com/maps/api/staticmap?size=640x640&maptype=roadmap&path=color:0xff0000|weight:3|fillcolor:0xff000060|38.73,-94.22|38.75,-94.16|38.57,-93.94|38.4,-93.84|38.4,-93.91|38.73,-94.22&key=your_api_key"
|
33
|
+
|
34
|
+
#options can be passed for map to override defaults
|
35
|
+
options = { :width => 600, :height => 300, :color => "0xfbf000", :weight => 4, :fillcolor => "0xfbf00070" }
|
36
|
+
|
37
|
+
alert.polygon.image_url "your_api_key", options
|
38
|
+
|
39
|
+
|
25
40
|
|
26
41
|
### Urgency
|
27
42
|
|
data/lib/gull.rb
CHANGED
data/lib/gull/alert.rb
CHANGED
@@ -25,8 +25,8 @@ module Gull
|
|
25
25
|
alert.summary = entry.css('summary').inner_text
|
26
26
|
|
27
27
|
polygon = entry.xpath('cap:polygon').inner_text
|
28
|
-
unless polygon.
|
29
|
-
alert.polygon =
|
28
|
+
unless polygon.empty?
|
29
|
+
alert.polygon = Polygon.new polygon
|
30
30
|
end
|
31
31
|
|
32
32
|
alert.area = entry.xpath('cap:areaDesc').inner_text
|
data/lib/gull/polygon.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Gull
|
2
|
+
class Polygon
|
3
|
+
attr_accessor :coordinates
|
4
|
+
|
5
|
+
def initialize polygon
|
6
|
+
self.coordinates = polygon.split(" ").collect {|coords| coords.split(",").collect {|coord| coord.to_f} }
|
7
|
+
end
|
8
|
+
|
9
|
+
def centroid
|
10
|
+
low_x, low_y, high_x, high_y = 0, 0, 0, 0
|
11
|
+
|
12
|
+
coordinates.each do |pair|
|
13
|
+
latitude = pair.first
|
14
|
+
if latitude < low_x or low_x == 0
|
15
|
+
low_x = latitude
|
16
|
+
elsif latitude > high_x or high_x == 0
|
17
|
+
high_x = latitude
|
18
|
+
end
|
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
|
26
|
+
end
|
27
|
+
|
28
|
+
center_x = low_x + ((high_x - low_x) / 2)
|
29
|
+
center_y = low_y + ((high_y - low_y) / 2)
|
30
|
+
|
31
|
+
[center_x, center_y]
|
32
|
+
end
|
33
|
+
|
34
|
+
def image_url api_key, options={}
|
35
|
+
opts = {
|
36
|
+
:width => 640,
|
37
|
+
:height => 640,
|
38
|
+
:color => "0xff0000",
|
39
|
+
:weight => 3,
|
40
|
+
:fillcolor => "0xff000060"
|
41
|
+
}.merge(options)
|
42
|
+
|
43
|
+
url_base = "http://maps.googleapis.com/maps/api/staticmap"
|
44
|
+
"#{url_base}?size=#{opts[:width]}x#{opts[:height]}&maptype=roadmap&path=color:#{opts[:color]}" +
|
45
|
+
"|weight:#{opts[:weight]}|fillcolor:#{opts[:fillcolor]}|#{coordinates_piped}&key=#{api_key}"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def coordinates_piped
|
51
|
+
coordinates.collect {|pair| pair.join "," }.join "|"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/gull/version.rb
CHANGED
data/spec/alert_spec.rb
CHANGED
@@ -17,9 +17,9 @@ describe Gull::Alert do
|
|
17
17
|
expect(first.title).to eq "Heat Advisory issued October 01 at 8:40AM PDT until October 03 at 9:00PM PDT by NWS"
|
18
18
|
expect(first.summary).to eq "SUMMARY TEXT"
|
19
19
|
|
20
|
-
|
20
|
+
coordinates = [[27.35,-81.79], [27.14,-81.89], [27.04,-81.97], [27.04,-82.02], [27.14,-81.97], [27.35,-81.86],
|
21
21
|
[27.35,-81.79]]
|
22
|
-
expect(first.polygon).to eq
|
22
|
+
expect(first.polygon.coordinates).to eq coordinates
|
23
23
|
|
24
24
|
expect(first.effective_at).to eq Time.parse("2014-10-01T08:40:00-07:00")
|
25
25
|
expect(first.expires_at).to eq Time.parse("2014-10-03T21:00:00-07:00")
|
@@ -27,5 +27,8 @@ describe Gull::Alert do
|
|
27
27
|
expect(first.urgency).to eq :expected
|
28
28
|
expect(first.severity).to eq :minor
|
29
29
|
expect(first.certainty).to eq :very_likely
|
30
|
+
|
31
|
+
second = alerts[1]
|
32
|
+
expect(second.polygon).to be_nil
|
30
33
|
end
|
31
34
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gull::Polygon do
|
4
|
+
it "should return centroid of polygon" do
|
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
|
+
"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
|
+
expect(polygon.centroid).to eq [34.635000000000005, -97.33500000000001]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return static map image url" do
|
12
|
+
polygon = Gull::Polygon.new "34.57,-97.56 34.77,-97.38 34.75,-97.17"
|
13
|
+
|
14
|
+
api_key = "testkey"
|
15
|
+
options = { :width => 600, :height => 300, :color => "0xfbf000", :weight => 4, :fillcolor => "0xfbf00070" }
|
16
|
+
url = polygon.image_url api_key, options
|
17
|
+
expected_url = "http://maps.googleapis.com/maps/api/staticmap?" +
|
18
|
+
"size=600x300&maptype=roadmap&path=color:0xfbf000" +
|
19
|
+
"|weight:4|fillcolor:0xfbf00070|34.57,-97.56|34.77,-97.38|34.75,-97.17&key=testkey"
|
20
|
+
expect(url).to eq expected_url
|
21
|
+
|
22
|
+
url = polygon.image_url api_key
|
23
|
+
expected_url = "http://maps.googleapis.com/maps/api/staticmap?" +
|
24
|
+
"size=640x640&maptype=roadmap&path=color:0xff0000" +
|
25
|
+
"|weight:3|fillcolor:0xff000060|34.57,-97.56|34.77,-97.38|34.75,-97.17&key=testkey"
|
26
|
+
expect(url).to eq expected_url
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Deckard
|
@@ -111,9 +111,11 @@ files:
|
|
111
111
|
- gull.gemspec
|
112
112
|
- lib/gull.rb
|
113
113
|
- lib/gull/alert.rb
|
114
|
+
- lib/gull/polygon.rb
|
114
115
|
- lib/gull/version.rb
|
115
116
|
- spec/alert_spec.rb
|
116
117
|
- spec/alerts.xml
|
118
|
+
- spec/polygon_spec.rb
|
117
119
|
- spec/spec_helper.rb
|
118
120
|
homepage: https://github.com/sethdeckard/gull
|
119
121
|
licenses:
|
@@ -142,4 +144,5 @@ summary: Client for parsing NOAA/NWS alerts, warnings, and watches.
|
|
142
144
|
test_files:
|
143
145
|
- spec/alert_spec.rb
|
144
146
|
- spec/alerts.xml
|
147
|
+
- spec/polygon_spec.rb
|
145
148
|
- spec/spec_helper.rb
|