rcap 2.4.1 → 2.7.3
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 +5 -5
- data/.ruby-version +1 -0
- data/CHANGELOG.md +18 -0
- data/README.md +1 -0
- data/lib/rcap.rb +3 -1
- data/lib/rcap/alert.rb +30 -29
- data/lib/rcap/base/alert.rb +208 -205
- data/lib/rcap/base/area.rb +95 -91
- data/lib/rcap/base/circle.rb +45 -34
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +273 -272
- data/lib/rcap/base/parameter.rb +29 -28
- data/lib/rcap/base/point.rb +26 -24
- data/lib/rcap/base/polygon.rb +43 -35
- data/lib/rcap/base/resource.rb +65 -65
- data/lib/rcap/cap_1_0/alert.rb +85 -86
- data/lib/rcap/cap_1_0/area.rb +2 -2
- data/lib/rcap/cap_1_0/circle.rb +2 -1
- data/lib/rcap/cap_1_0/event_code.rb +3 -1
- data/lib/rcap/cap_1_0/geocode.rb +3 -1
- data/lib/rcap/cap_1_0/info.rb +3 -3
- data/lib/rcap/cap_1_0/parameter.rb +13 -13
- data/lib/rcap/cap_1_0/point.rb +2 -1
- data/lib/rcap/cap_1_0/polygon.rb +3 -3
- data/lib/rcap/cap_1_0/resource.rb +2 -3
- data/lib/rcap/cap_1_1/alert.rb +6 -6
- data/lib/rcap/cap_1_1/area.rb +2 -2
- data/lib/rcap/cap_1_1/circle.rb +2 -1
- data/lib/rcap/cap_1_1/event_code.rb +3 -1
- data/lib/rcap/cap_1_1/geocode.rb +3 -1
- data/lib/rcap/cap_1_1/info.rb +125 -132
- data/lib/rcap/cap_1_1/parameter.rb +2 -3
- data/lib/rcap/cap_1_1/point.rb +2 -1
- data/lib/rcap/cap_1_1/polygon.rb +3 -3
- data/lib/rcap/cap_1_1/resource.rb +37 -38
- data/lib/rcap/cap_1_2/alert.rb +6 -6
- data/lib/rcap/cap_1_2/area.rb +2 -2
- data/lib/rcap/cap_1_2/circle.rb +2 -1
- data/lib/rcap/cap_1_2/event_code.rb +3 -1
- data/lib/rcap/cap_1_2/geocode.rb +3 -1
- data/lib/rcap/cap_1_2/info.rb +120 -123
- data/lib/rcap/cap_1_2/parameter.rb +2 -3
- data/lib/rcap/cap_1_2/point.rb +2 -1
- data/lib/rcap/cap_1_2/polygon.rb +4 -4
- data/lib/rcap/cap_1_2/resource.rb +38 -38
- data/lib/rcap/config.rb +5 -3
- data/lib/rcap/custom_validators.rb +75 -78
- data/lib/rcap/extensions/array.rb +3 -1
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +5 -2
- data/lib/rcap/extensions/float.rb +2 -0
- data/lib/rcap/extensions/integer.rb +7 -0
- data/lib/rcap/extensions/nil_class.rb +2 -0
- data/lib/rcap/extensions/string.rb +6 -4
- data/lib/rcap/extensions/time.rb +5 -3
- data/lib/rcap/formatters/yaml.rb +5 -0
- data/lib/rcap/info.rb +6 -5
- data/lib/rcap/utilities.rb +27 -30
- data/lib/rcap/validation.rb +22 -21
- data/lib/rcap/version.rb +3 -1
- data/rcap.gemspec +5 -5
- data/spec/alert_spec.rb +141 -141
- data/spec/cap_1_0/alert_spec.rb +92 -94
- data/spec/cap_1_0/area_spec.rb +86 -86
- data/spec/cap_1_0/circle_spec.rb +48 -39
- data/spec/cap_1_0/event_code_spec.rb +15 -15
- data/spec/cap_1_0/geocode_spec.rb +16 -16
- data/spec/cap_1_0/info_spec.rb +175 -177
- data/spec/cap_1_0/parameter_spec.rb +27 -27
- data/spec/cap_1_0/point_spec.rb +18 -18
- data/spec/cap_1_0/polygon_spec.rb +43 -41
- data/spec/cap_1_0/resource_spec.rb +63 -64
- data/spec/cap_1_1/alert_spec.rb +107 -109
- data/spec/cap_1_1/area_spec.rb +90 -90
- data/spec/cap_1_1/circle_spec.rb +43 -34
- data/spec/cap_1_1/event_code_spec.rb +15 -16
- data/spec/cap_1_1/geocode_spec.rb +16 -16
- data/spec/cap_1_1/info_spec.rb +194 -196
- data/spec/cap_1_1/parameter_spec.rb +17 -17
- data/spec/cap_1_1/point_spec.rb +18 -18
- data/spec/cap_1_1/polygon_spec.rb +43 -41
- data/spec/cap_1_1/resource_spec.rb +106 -107
- data/spec/cap_1_2/alert_spec.rb +98 -99
- data/spec/cap_1_2/area_spec.rb +90 -90
- data/spec/cap_1_2/circle_spec.rb +52 -43
- data/spec/cap_1_2/event_code_spec.rb +19 -20
- data/spec/cap_1_2/geocode_spec.rb +20 -20
- data/spec/cap_1_2/info_spec.rb +196 -198
- data/spec/cap_1_2/parameter_spec.rb +19 -19
- data/spec/cap_1_2/point_spec.rb +21 -21
- data/spec/cap_1_2/polygon_spec.rb +55 -47
- data/spec/cap_1_2/resource_spec.rb +96 -97
- data/spec/extensions_spec.rb +29 -29
- data/spec/info_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -3
- data/spec/validations_spec.rb +73 -73
- metadata +12 -11
- data/lib/rcap/extensions/fixnum.rb +0 -5
data/lib/rcap/base/area.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module Base
|
3
5
|
class Area
|
4
6
|
include Validation
|
5
7
|
|
6
8
|
# @return [String] Textual description of area.
|
7
|
-
attr_accessor(
|
9
|
+
attr_accessor(:area_desc)
|
8
10
|
# @return [Numeric] Expressed in feet above sea level
|
9
|
-
attr_accessor(
|
11
|
+
attr_accessor(:altitude)
|
10
12
|
# @return [Numeric] Expressed in feet above sea level.
|
11
|
-
attr_accessor(
|
13
|
+
attr_accessor(:ceiling)
|
12
14
|
# @return [Array<Circle>]
|
13
|
-
attr_reader(
|
15
|
+
attr_reader(:circles)
|
14
16
|
# @return [Array<Geocode>]
|
15
|
-
attr_reader(
|
17
|
+
attr_reader(:geocodes)
|
16
18
|
# @return [Array<Polygon>]
|
17
|
-
attr_reader(
|
19
|
+
attr_reader(:polygons)
|
18
20
|
|
19
|
-
validates_presence_of(
|
20
|
-
validates_collection_of(
|
21
|
-
validates_dependency_of(
|
21
|
+
validates_presence_of(:area_desc)
|
22
|
+
validates_collection_of(:circles, :geocodes, :polygons, allow_empty: true)
|
23
|
+
validates_dependency_of(:ceiling, on: :altitude)
|
22
24
|
|
23
25
|
XML_ELEMENT_NAME = 'area'
|
24
26
|
AREA_DESC_ELEMENT_NAME = 'areaDesc'
|
25
27
|
ALTITUDE_ELEMENT_NAME = 'altitude'
|
26
28
|
CEILING_ELEMENT_NAME = 'ceiling'
|
27
29
|
|
28
|
-
XPATH = "cap:#{
|
29
|
-
AREA_DESC_XPATH = "cap:#{
|
30
|
-
ALTITUDE_XPATH = "cap:#{
|
31
|
-
CEILING_XPATH = "cap:#{
|
30
|
+
XPATH = "cap:#{XML_ELEMENT_NAME}"
|
31
|
+
AREA_DESC_XPATH = "cap:#{AREA_DESC_ELEMENT_NAME}"
|
32
|
+
ALTITUDE_XPATH = "cap:#{ALTITUDE_ELEMENT_NAME}"
|
33
|
+
CEILING_XPATH = "cap:#{CEILING_ELEMENT_NAME}"
|
32
34
|
|
33
35
|
# @example
|
34
36
|
# Area.new do |area|
|
@@ -42,15 +44,15 @@ module RCAP
|
|
42
44
|
@circles = []
|
43
45
|
@geocodes = []
|
44
46
|
@polygons = []
|
45
|
-
yield(
|
47
|
+
yield(self) if block_given?
|
46
48
|
end
|
47
49
|
|
48
50
|
# Creates a new {Polygon} object and adds it to the {#polygons} array.
|
49
51
|
#
|
50
52
|
# @return [Polygon]
|
51
53
|
def add_polygon
|
52
|
-
|
53
|
-
yield(
|
54
|
+
polygon_class.new.tap do |polygon|
|
55
|
+
yield(polygon) if block_given?
|
54
56
|
@polygons << polygon
|
55
57
|
end
|
56
58
|
end
|
@@ -59,8 +61,8 @@ module RCAP
|
|
59
61
|
#
|
60
62
|
# @return [Circle]
|
61
63
|
def add_circle
|
62
|
-
|
63
|
-
yield(
|
64
|
+
circle_class.new.tap do |circle|
|
65
|
+
yield(circle) if block_given?
|
64
66
|
@circles << circle
|
65
67
|
end
|
66
68
|
end
|
@@ -69,70 +71,69 @@ module RCAP
|
|
69
71
|
#
|
70
72
|
# @return [Geocode]
|
71
73
|
def add_geocode
|
72
|
-
|
73
|
-
yield(
|
74
|
+
geocode_class.new do |geocode|
|
75
|
+
yield(geocode) if block_given?
|
74
76
|
@geocodes << geocode
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
def self.from_xml_element(
|
79
|
-
|
80
|
-
area.area_desc = RCAP.xpath_text(
|
81
|
-
area.altitude = RCAP.to_f_if_given(
|
82
|
-
area.ceiling = RCAP.to_f_if_given(
|
80
|
+
def self.from_xml_element(area_xml_element)
|
81
|
+
new do |area|
|
82
|
+
area.area_desc = RCAP.xpath_text(area_xml_element, AREA_DESC_XPATH, area.xmlns)
|
83
|
+
area.altitude = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, ALTITUDE_XPATH, area.xmlns))
|
84
|
+
area.ceiling = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, CEILING_XPATH, area.xmlns))
|
83
85
|
|
84
|
-
RCAP.xpath_match(
|
85
|
-
area.circles << area.circle_class.from_xml_element(
|
86
|
+
RCAP.xpath_match(area_xml_element, area.circle_class::XPATH, area.xmlns).each do |circle_element|
|
87
|
+
area.circles << area.circle_class.from_xml_element(circle_element)
|
86
88
|
end
|
87
89
|
|
88
|
-
RCAP.xpath_match(
|
89
|
-
area.geocodes << area.geocode_class.from_xml_element(
|
90
|
+
RCAP.xpath_match(area_xml_element, area.geocode_class::XPATH, area.xmlns).each do |geocode_element|
|
91
|
+
area.geocodes << area.geocode_class.from_xml_element(geocode_element)
|
90
92
|
end
|
91
93
|
|
92
|
-
RCAP.xpath_match(
|
93
|
-
area.polygons << area.polygon_class.from_xml_element(
|
94
|
+
RCAP.xpath_match(area_xml_element, area.polygon_class::XPATH, area.xmlns).each do |polygon_element|
|
95
|
+
area.polygons << area.polygon_class.from_xml_element(polygon_element)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
100
|
# @return [REXML::Element]
|
99
101
|
def to_xml_element
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
REXML::Element.new(XML_ELEMENT_NAME).tap do |xml_element|
|
103
|
+
xml_element.add_element(AREA_DESC_ELEMENT_NAME).add_text(@area_desc.to_s)
|
104
|
+
add_to_xml_element = lambda do |element, object|
|
105
|
+
element.add_element(object.to_xml_element)
|
106
|
+
element
|
107
|
+
end
|
108
|
+
@polygons.inject(xml_element, &add_to_xml_element)
|
109
|
+
@circles.inject(xml_element, &add_to_xml_element)
|
110
|
+
@geocodes.inject(xml_element, &add_to_xml_element)
|
111
|
+
xml_element.add_element(ALTITUDE_ELEMENT_NAME).add_text(@altitude.to_s) unless @altitude.blank?
|
112
|
+
xml_element.add_element(CEILING_ELEMENT_NAME).add_text(@ceiling.to_s) unless @altitude.blank?
|
105
113
|
end
|
106
|
-
@polygons.inject( xml_element, &add_to_xml_element )
|
107
|
-
@circles.inject( xml_element, &add_to_xml_element )
|
108
|
-
@geocodes.inject( xml_element, &add_to_xml_element )
|
109
|
-
xml_element.add_element( ALTITUDE_ELEMENT_NAME ).add_text( @altitude.to_s ) unless @altitude.blank?
|
110
|
-
xml_element.add_element( CEILING_ELEMENT_NAME ).add_text( @ceiling.to_s ) unless @altitude.blank?
|
111
|
-
xml_element
|
112
114
|
end
|
113
115
|
|
114
116
|
# @return [String] XML representation of the Area
|
115
117
|
def to_xml
|
116
|
-
|
118
|
+
to_xml_element.to_s
|
117
119
|
end
|
118
120
|
|
119
121
|
# Implements an equality operator for the Area object. Two Area objects are equal if all their attributes are equal.
|
120
122
|
#
|
121
123
|
# @param [Area] other Area object to compare
|
122
124
|
# @return [true,false]
|
123
|
-
def ==(
|
124
|
-
comparison_attributes =
|
125
|
-
comparison_attributes.call(
|
125
|
+
def ==(other)
|
126
|
+
comparison_attributes = ->(area) { [area.area_desc, area.altitude, area.ceiling, area.circles, area.geocodes, area.polygons] }
|
127
|
+
comparison_attributes.call(self) == comparison_attributes.call(other)
|
126
128
|
end
|
127
129
|
|
128
130
|
# @return [String]
|
129
131
|
def inspect
|
130
|
-
area_inspect = "Area Description: #{
|
131
|
-
"Polygons:\n"+
|
132
|
-
@
|
133
|
-
"
|
134
|
-
|
135
|
-
RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
132
|
+
area_inspect = "Area Description: #{@area_desc}\n"\
|
133
|
+
"Polygons:\n" + @polygons.map { |polygon| ' ' + polygon.inspect }.join("\n") + "\n"\
|
134
|
+
"Circles: #{@circles.inspect}\n"\
|
135
|
+
"Geocodes: #{@geocodes.inspect}\n"
|
136
|
+
RCAP.format_lines_for_inspect('AREA', area_inspect)
|
136
137
|
end
|
137
138
|
|
138
139
|
# Returns the area description
|
@@ -142,7 +143,6 @@ module RCAP
|
|
142
143
|
@area_desc
|
143
144
|
end
|
144
145
|
|
145
|
-
|
146
146
|
AREA_DESC_YAML = 'Area Description'
|
147
147
|
ALTITUDE_YAML = 'Altitude'
|
148
148
|
CEILING_YAML = 'Ceiling'
|
@@ -150,42 +150,42 @@ module RCAP
|
|
150
150
|
GEOCODES_YAML = 'Geocodes'
|
151
151
|
POLYGONS_YAML = 'Polygons'
|
152
152
|
|
153
|
-
# @return [Hash]
|
153
|
+
# @return [Hash]
|
154
154
|
def to_yaml_data
|
155
|
-
RCAP.attribute_values_to_hash(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
155
|
+
RCAP.attribute_values_to_hash([AREA_DESC_YAML, @area_desc],
|
156
|
+
[ALTITUDE_YAML, @altitude],
|
157
|
+
[CEILING_YAML, @ceiling],
|
158
|
+
[CIRCLES_YAML, @circles.map(&:to_a)],
|
159
|
+
[GEOCODES_YAML, @geocodes.reduce({}) { |h, geocode| h.merge(geocode.name => geocode.value) }],
|
160
|
+
[POLYGONS_YAML, @polygons.map(&:to_yaml_data)])
|
161
161
|
end
|
162
162
|
|
163
163
|
# @return [String] YAML representation of object
|
164
|
-
def to_yaml(
|
165
|
-
|
164
|
+
def to_yaml(options = {})
|
165
|
+
to_yaml_data.to_yaml(options)
|
166
166
|
end
|
167
167
|
|
168
168
|
# @param [Hash] area_yaml_data
|
169
169
|
# @return [Area]
|
170
|
-
def self.from_yaml_data(
|
171
|
-
|
172
|
-
area.area_desc = area_yaml_data[
|
173
|
-
area.altitude = area_yaml_data[
|
174
|
-
area.ceiling = area_yaml_data[
|
175
|
-
|
176
|
-
Array(
|
177
|
-
area.circles << area.circle_class.from_yaml_data(
|
170
|
+
def self.from_yaml_data(area_yaml_data)
|
171
|
+
new do |area|
|
172
|
+
area.area_desc = area_yaml_data[AREA_DESC_YAML]
|
173
|
+
area.altitude = area_yaml_data[ALTITUDE_YAML]
|
174
|
+
area.ceiling = area_yaml_data[CEILING_YAML]
|
175
|
+
|
176
|
+
Array(area_yaml_data[CIRCLES_YAML]).each do |circle_yaml_data|
|
177
|
+
area.circles << area.circle_class.from_yaml_data(circle_yaml_data)
|
178
178
|
end
|
179
179
|
|
180
|
-
Array(
|
180
|
+
Array(area_yaml_data[GEOCODES_YAML]).each do |name, value|
|
181
181
|
area.add_geocode do |geocode|
|
182
182
|
geocode.name = name
|
183
183
|
geocode.value = value
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
Array(
|
188
|
-
area.polygons << area.polygon_class.from_yaml_data(
|
187
|
+
Array(area_yaml_data[POLYGONS_YAML]).each do |polyon_yaml_data|
|
188
|
+
area.polygons << area.polygon_class.from_yaml_data(polyon_yaml_data)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
@@ -199,34 +199,38 @@ module RCAP
|
|
199
199
|
|
200
200
|
# @param [Hash] area_hash
|
201
201
|
# @return [Area]
|
202
|
-
def self.from_h(
|
203
|
-
|
204
|
-
area.area_desc = area_hash[
|
205
|
-
area.altitude = area_hash[
|
206
|
-
area.ceiling = area_hash[
|
207
|
-
|
208
|
-
Array(
|
209
|
-
area.circles << area.circle_class.from_a(
|
202
|
+
def self.from_h(area_hash)
|
203
|
+
new do |area|
|
204
|
+
area.area_desc = area_hash[AREA_DESC_KEY]
|
205
|
+
area.altitude = area_hash[ALTITUDE_KEY]
|
206
|
+
area.ceiling = area_hash[CEILING_KEY]
|
207
|
+
|
208
|
+
Array(area_hash[CIRCLES_KEY]).each do |circle_array|
|
209
|
+
area.circles << area.circle_class.from_a(circle_array)
|
210
210
|
end
|
211
211
|
|
212
|
-
Array(
|
213
|
-
area.geocodes << area.geocode_class.from_h(
|
212
|
+
Array(area_hash[GEOCODES_KEY]).each do |geocode_hash|
|
213
|
+
area.geocodes << area.geocode_class.from_h(geocode_hash)
|
214
214
|
end
|
215
215
|
|
216
|
-
Array(
|
217
|
-
area.polygons << area.polygon_class.from_h(
|
216
|
+
Array(area_hash[POLYGONS_KEY]).each do |polygon_hash|
|
217
|
+
area.polygons << area.polygon_class.from_h(polygon_hash)
|
218
218
|
end
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
222
222
|
# @return [Hash]
|
223
223
|
def to_h
|
224
|
-
RCAP.attribute_values_to_hash(
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
224
|
+
RCAP.attribute_values_to_hash([AREA_DESC_KEY, @area_desc],
|
225
|
+
[ALTITUDE_KEY, @altitude],
|
226
|
+
[CEILING_KEY, @ceiling],
|
227
|
+
[CIRCLES_KEY, @circles.map(&:to_a)],
|
228
|
+
[GEOCODES_KEY, @geocodes.map(&:to_h)],
|
229
|
+
[POLYGONS_KEY, @polygons.map(&:to_h)])
|
230
|
+
end
|
231
|
+
|
232
|
+
def map_data?
|
233
|
+
@circles.any? || @polygons.any?
|
230
234
|
end
|
231
235
|
end
|
232
236
|
end
|
data/lib/rcap/base/circle.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module Base
|
3
5
|
class Circle < Point
|
4
6
|
include Validation
|
5
7
|
|
6
8
|
# @return [Numeric] Expresed in kilometers
|
7
|
-
attr_accessor(
|
9
|
+
attr_accessor(:radius)
|
8
10
|
|
9
|
-
validates_presence_of(
|
10
|
-
validates_numericality_of(
|
11
|
+
validates_presence_of(:radius)
|
12
|
+
validates_numericality_of(:radius, greater_than_or_equal: 0)
|
11
13
|
|
12
14
|
XML_ELEMENT_NAME = 'circle'
|
13
15
|
|
@@ -18,7 +20,16 @@ module RCAP
|
|
18
20
|
# @option attributes [Numeric] :longitude
|
19
21
|
# @option attributes [Numeric] :radius
|
20
22
|
def initialize
|
21
|
-
yield(
|
23
|
+
yield(self) if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns GeoJSON representation of the circle in the form of a Point
|
27
|
+
# with radius property
|
28
|
+
def to_geojson
|
29
|
+
{ 'type' => 'Feature',
|
30
|
+
'geometry' => { 'type' => 'Point',
|
31
|
+
'coordinates' => [@longitude, @lattitude] },
|
32
|
+
'properties' => { 'radius' => @radius } }.to_json
|
22
33
|
end
|
23
34
|
|
24
35
|
# Returns a string representation of the circle of the form
|
@@ -26,24 +37,24 @@ module RCAP
|
|
26
37
|
#
|
27
38
|
# @return [String]
|
28
39
|
def to_s
|
29
|
-
"#{
|
40
|
+
"#{@lattitude},#{@longitude} #{@radius}"
|
30
41
|
end
|
31
42
|
|
32
43
|
# @return [String]
|
33
44
|
def inspect
|
34
|
-
"(#{
|
45
|
+
"(#{self})"
|
35
46
|
end
|
36
47
|
|
37
48
|
# @return [REXML::Element]
|
38
49
|
def to_xml_element
|
39
|
-
xml_element = REXML::Element.new(
|
40
|
-
xml_element.add_text(
|
50
|
+
xml_element = REXML::Element.new(XML_ELEMENT_NAME)
|
51
|
+
xml_element.add_text(to_s)
|
41
52
|
xml_element
|
42
53
|
end
|
43
54
|
|
44
55
|
# @return [String]
|
45
56
|
def to_xml
|
46
|
-
|
57
|
+
to_xml_element.to_s
|
47
58
|
end
|
48
59
|
|
49
60
|
# Parses a circle string of the form
|
@@ -51,69 +62,69 @@ module RCAP
|
|
51
62
|
#
|
52
63
|
# @param [String] circle_string
|
53
64
|
# @return [Array(Float,Float,Float)]
|
54
|
-
def self.parse_circle_string(
|
55
|
-
coordinates, radius = circle_string.split(
|
56
|
-
lattitude, longitude = coordinates.split(
|
57
|
-
[
|
65
|
+
def self.parse_circle_string(circle_string)
|
66
|
+
coordinates, radius = circle_string.split(' ')
|
67
|
+
lattitude, longitude = coordinates.split(',')
|
68
|
+
[lattitude, longitude, radius].map(&:to_f)
|
58
69
|
end
|
59
70
|
|
60
71
|
# @param [REXML::Element] circle_xml_element
|
61
72
|
# @return [Circle]
|
62
|
-
def self.from_xml_element(
|
63
|
-
|
73
|
+
def self.from_xml_element(circle_xml_element)
|
74
|
+
from_a(parse_circle_string(circle_xml_element.text))
|
64
75
|
end
|
65
76
|
|
66
77
|
# Two circles are equivalent if their lattitude, longitude and radius are equal.
|
67
78
|
#
|
68
79
|
# @param [Circle] other
|
69
80
|
# @return [true,false]
|
70
|
-
def ==(
|
71
|
-
|
81
|
+
def ==(other)
|
82
|
+
to_a == other.to_a
|
72
83
|
end
|
73
84
|
|
74
85
|
# @param [Array(Numeric, Numeric, Numeric)] circle_yaml_data lattitude, longitude, radius
|
75
86
|
# @return [Circle]
|
76
|
-
def self.from_yaml_data(
|
87
|
+
def self.from_yaml_data(circle_yaml_data)
|
77
88
|
lattitude, longitude, radius = circle_yaml_data
|
78
|
-
|
89
|
+
new do |circle|
|
79
90
|
circle.lattitude = lattitude.to_f
|
80
91
|
circle.longitude = longitude.to_f
|
81
92
|
circle.radius = radius.to_f
|
82
93
|
end
|
83
94
|
end
|
84
95
|
|
85
|
-
RADIUS_KEY
|
96
|
+
RADIUS_KEY = 'radius'
|
86
97
|
# @return [Hash]
|
87
98
|
def to_h
|
88
|
-
RCAP.attribute_values_to_hash(
|
89
|
-
|
90
|
-
|
99
|
+
RCAP.attribute_values_to_hash([RADIUS_KEY, @radius],
|
100
|
+
[LATTITUDE_KEY, @lattitude],
|
101
|
+
[LONGITUDE_KEY, @longitude])
|
91
102
|
end
|
92
103
|
|
93
104
|
# @param [Hash] circle_hash
|
94
105
|
# @return [Circle]
|
95
|
-
def self.from_h(
|
96
|
-
|
97
|
-
circle.radius = circle_hash[
|
98
|
-
circle.lattitude = circle_hash[
|
99
|
-
circle.longitude = circle_hash[
|
106
|
+
def self.from_h(circle_hash)
|
107
|
+
new do |circle|
|
108
|
+
circle.radius = circle_hash[RADIUS_KEY].to_f
|
109
|
+
circle.lattitude = circle_hash[LATTITUDE_KEY].to_f
|
110
|
+
circle.longitude = circle_hash[LONGITUDE_KEY].to_f
|
100
111
|
end
|
101
112
|
end
|
102
113
|
|
103
114
|
# @return [Array(Numeric,Numeric,Numeric)]
|
104
115
|
def to_a
|
105
|
-
[
|
116
|
+
[@lattitude, @longitude, @radius]
|
106
117
|
end
|
107
118
|
|
108
119
|
RADIUS_INDEX = 2
|
109
120
|
|
110
121
|
# @param [Array] circle_array
|
111
122
|
# @return [Circle]
|
112
|
-
def self.from_a(
|
113
|
-
|
114
|
-
circle.longitude = circle_array[
|
115
|
-
circle.lattitude = circle_array[
|
116
|
-
circle.radius = circle_array[
|
123
|
+
def self.from_a(circle_array)
|
124
|
+
new do |circle|
|
125
|
+
circle.longitude = circle_array[LONGITUDE_INDEX].to_f
|
126
|
+
circle.lattitude = circle_array[LATTITUDE_INDEX].to_f
|
127
|
+
circle.radius = circle_array[RADIUS_INDEX].to_f
|
117
128
|
end
|
118
129
|
end
|
119
130
|
end
|