rcap 2.5.1 → 2.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e3471e557cf30f246f853bd2bd70f77b32e77da
4
- data.tar.gz: 1a4cc77192840baef8e4f562ab87260b29ed251c
3
+ metadata.gz: 6c06491f4a40f61743ca71921a056c7bccc85ee6
4
+ data.tar.gz: cc95caeb32f34167d42654727142d69058fbceb2
5
5
  SHA512:
6
- metadata.gz: c6135d4af1a059df7fce04ac0bb49206901d47aa1b2e5895811586d816bf40d673ab089addb02d775c6dd3922b516be6f9c34a13ca3da256eda2635e7b805bd5
7
- data.tar.gz: 012295cee65d5c4c3d441ba4f332cf144645d0293e629ac6eac7e006a43a6fb93b2212501293a27a15bfd58c25101a28f4d2fe66d4dc68a140532d0a034a039c
6
+ metadata.gz: 7a90ac3ef2225df636936d4eb3e91b622e76bb39e301378099ebf610da0e95d0c690d4b363abf2cc9b29307f98fbb275fccaac7bde8cc679d7f65121875f4014
7
+ data.tar.gz: 32b4642bb840d73051b40d42dcf076933190e6a502037e7444b13eb1e1014979a93acfd1ea554997d2360ef1553d5a4cb3961f009013f143d8891f4cd00c1771
@@ -1,6 +1,10 @@
1
1
  Change Log
2
2
  ==========
3
3
 
4
+ ## 2.6.0 - 30 October 2016
5
+
6
+ * Adds GeoJSON export to Polygon and Circle
7
+
4
8
  ## 2.5.1 - 3 November 2014
5
9
 
6
10
  * Allow the polygons to be empty.
data/README.md CHANGED
@@ -156,6 +156,7 @@ Authors
156
156
 
157
157
  * Earle Clubb - http://github.com/eclubb
158
158
  * David van Geest - https://github.com/DWvanGeest
159
+ * Seth Deckard - https://github.com/sethdeckard
159
160
 
160
161
  Change Log
161
162
  ----------
@@ -193,7 +193,8 @@ module RCAP
193
193
  'Codes:',
194
194
  @codes.map { |code| ' ' + code }.join("\n") + '',
195
195
  "Note: #{ @note }",
196
- "References: #{ @references.join(' ')}",
196
+ "References:",
197
+ @references.join("\n "),
197
198
  "Incidents: #{ @incidents.join(' ')}",
198
199
  'Information:',
199
200
  @infos.map { |info| ' ' + info.to_s }.join("\n")].join("\n")
@@ -21,6 +21,15 @@ module RCAP
21
21
  yield(self) if block_given?
22
22
  end
23
23
 
24
+ # Returns GeoJSON representation of the circle in the form of a Point
25
+ # with radius property
26
+ def to_geojson
27
+ { 'type' => 'Feature',
28
+ 'geometry' => { 'type' => 'Point',
29
+ 'coordinates' => [@longitude, @lattitude] },
30
+ 'properties' => { 'radius' => @radius } }.to_json
31
+ end
32
+
24
33
  # Returns a string representation of the circle of the form
25
34
  # lattitude,longitude radius
26
35
  #
@@ -27,6 +27,12 @@ module RCAP
27
27
  point
28
28
  end
29
29
 
30
+ # Returns GeoJSON representation of the polygon
31
+ def to_geojson
32
+ coordinates = @points.map { |point| [point.longitude, point.lattitude] }
33
+ { 'type' => 'Polygon', 'coordinates' => coordinates }.to_json
34
+ end
35
+
30
36
  # Returns a string representation of the polygon of the form
31
37
  # points[0] points[1] points[2] ...
32
38
  # where each point is formatted with Point#to_s
@@ -75,7 +75,8 @@ module RCAP
75
75
  'Codes:',
76
76
  @codes.map { |code| ' ' + code }.join("\n"),
77
77
  "Note: #{ @note }",
78
- "References: #{ @references.join(' ')}",
78
+ "References:",
79
+ @references.join("\n "),
79
80
  "Incidents: #{ @incidents.join(' ')}",
80
81
  'Information:',
81
82
  @infos.map { |info| ' ' + info.to_s }.join("\n")].join("\n")
@@ -2,7 +2,6 @@ module RCAP
2
2
  module CAP_1_0
3
3
  # A Parameter object is valid if
4
4
  # * it has a name
5
- # * it has a value
6
5
  class Parameter < RCAP::Base::Parameter
7
6
  # @return [REXML::Element]
8
7
  def to_xml_element
@@ -1,7 +1,7 @@
1
1
  module RCAP
2
2
  module CAP_1_0
3
3
  # A Polygon object is valid if
4
- # * it has a minimum of three points
4
+ # * if points are given it has a minimum of three points
5
5
  # * each Point object in the points collection is valid
6
6
  class Polygon < RCAP::Base::Polygon
7
7
  # @return [Class]
@@ -2,7 +2,6 @@ module RCAP
2
2
  module CAP_1_1
3
3
  # A Parameter object is valid if
4
4
  # * it has a name
5
- # * it has a value
6
5
  class Parameter < RCAP::Base::Parameter
7
6
  # @return [String]
8
7
  def xmlns
@@ -1,7 +1,7 @@
1
1
  module RCAP
2
2
  module CAP_1_1
3
3
  # A Polygon object is valid if
4
- # * it has a minimum of three points
4
+ # * if points are given it has a minimum of three points
5
5
  # * each Point object in the points collection is valid
6
6
  class Polygon < RCAP::Base::Polygon
7
7
  # @return [Class]
@@ -11,7 +11,6 @@ module RCAP
11
11
 
12
12
  # @return [REXML::Element]
13
13
  def to_xml_element
14
- xml_element = super
15
14
  xml_element = REXML::Element.new(XML_ELEMENT_NAME)
16
15
  xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
17
16
  xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
@@ -2,7 +2,6 @@ module RCAP
2
2
  module CAP_1_2
3
3
  # A Parameter object is valid if
4
4
  # * it has a name
5
- # * it has a value
6
5
  class Parameter < RCAP::Base::Parameter
7
6
  # @return [String]
8
7
  def xmlns
@@ -1,7 +1,7 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
3
  # A Polygon object is valid if
4
- # * it has a minimum of three points
4
+ # * if points are given it has a minimum of three points
5
5
  # * each Point object in the points collection is valid
6
6
  class Polygon < RCAP::Base::Polygon
7
7
  validates_length_of(:points, minimum: 4, allow_blank: true)
@@ -15,7 +15,6 @@ module RCAP
15
15
 
16
16
  # @return [REXML::Element]
17
17
  def to_xml_element
18
- xml_element = super
19
18
  xml_element = REXML::Element.new(XML_ELEMENT_NAME)
20
19
  xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
21
20
  xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
@@ -0,0 +1,4 @@
1
+ class RCAP::Base::Alert
2
+ def to_yaml
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module RCAP
2
- VERSION = '2.5.1'
2
+ VERSION = '2.6.0'
3
3
  end
@@ -99,6 +99,15 @@ describe(RCAP::CAP_1_0::Circle) do
99
99
  end
100
100
  end
101
101
 
102
+ context('to geojson') do
103
+ it('should be valid geojson') do
104
+ @circle.longitude = 5.6
105
+ expected = '{"type":"Feature","geometry":{"type":"Point",' \
106
+ '"coordinates":[5.6,30]},"properties":{"radius":10.5}}'
107
+ expect(@circle.to_geojson).to eq expected
108
+ end
109
+ end
110
+
102
111
  context('to hash') do
103
112
  it('should be correct') do
104
113
  @circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
@@ -101,6 +101,13 @@ describe(RCAP::CAP_1_0::Polygon) do
101
101
  end
102
102
  end
103
103
 
104
+ context('to geojson') do
105
+ it('should be valid geojson') do
106
+ expected = '{"type":"Polygon","coordinates":[[0,0],[1,1],[2,2]]}'
107
+ expect(@polygon.to_geojson).to eq expected
108
+ end
109
+ end
110
+
104
111
  context('to a hash') do
105
112
  it('should export correctly') do
106
113
  @polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
@@ -102,6 +102,15 @@ describe(RCAP::CAP_1_1::Circle) do
102
102
  end
103
103
  end
104
104
 
105
+ context('to geojson') do
106
+ it('should be valid geojson') do
107
+ @circle.longitude = 5.6
108
+ expected = '{"type":"Feature","geometry":{"type":"Point",' \
109
+ '"coordinates":[5.6,30]},"properties":{"radius":10.5}}'
110
+ expect(@circle.to_geojson).to eq expected
111
+ end
112
+ end
113
+
105
114
  context('to hash') do
106
115
  it('should be correct') do
107
116
  @circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
@@ -97,6 +97,13 @@ describe(RCAP::CAP_1_1::Polygon) do
97
97
  end
98
98
  end
99
99
 
100
+ context('to geojson') do
101
+ it('should be valid geojson') do
102
+ expected = '{"type":"Polygon","coordinates":[[0,0],[1,1],[2,2]]}'
103
+ expect(@polygon.to_geojson).to eq expected
104
+ end
105
+ end
106
+
100
107
  context('to a hash') do
101
108
  it('should export correctly') do
102
109
  @polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
@@ -93,6 +93,15 @@ describe(RCAP::CAP_1_2::Circle) do
93
93
  @circle = RCAP::CAP_1_2::Circle.new(&@circle_builder)
94
94
  end
95
95
 
96
+ context('to geojson') do
97
+ it('should be valid geojson') do
98
+ @circle.longitude = 5.6
99
+ expected = '{"type":"Feature","geometry":{"type":"Point",' \
100
+ '"coordinates":[5.6,0]},"properties":{"radius":1}}'
101
+ expect(@circle.to_geojson).to eq expected
102
+ end
103
+ end
104
+
96
105
  context('to hash') do
97
106
  it('should be correct') do
98
107
  @circle.to_h.should == { 'radius' => 1, 'lattitude' => 0, 'longitude' => 0 }
@@ -83,6 +83,14 @@ describe(RCAP::CAP_1_2::Polygon) do
83
83
  @polygon = RCAP::CAP_1_2::Polygon.new(&@polygon_builder)
84
84
  end
85
85
 
86
+ context('to geojson') do
87
+ it('should be valid geojson') do
88
+ expected = '{"type":"Polygon","coordinates":[[0,0],[1,1],[2,2],' \
89
+ '[0,0]]}'
90
+ expect(@polygon.to_geojson).to eq expected
91
+ end
92
+ end
93
+
86
94
  context('to a hash') do
87
95
  it('should export correctly') do
88
96
  @polygon.to_h.should == { RCAP::CAP_1_2::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Farrel Lifson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2016-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -147,6 +147,7 @@ files:
147
147
  - lib/rcap/extensions/nil_class.rb
148
148
  - lib/rcap/extensions/string.rb
149
149
  - lib/rcap/extensions/time.rb
150
+ - lib/rcap/formatters/yaml.rb
150
151
  - lib/rcap/info.rb
151
152
  - lib/rcap/utilities.rb
152
153
  - lib/rcap/validation.rb
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
221
  version: '0'
221
222
  requirements: []
222
223
  rubyforge_project: rcap
223
- rubygems_version: 2.2.0
224
+ rubygems_version: 2.5.1
224
225
  signing_key:
225
226
  specification_version: 4
226
227
  summary: CAP(Common Alerting Protocol) API