rcap 2.4.1 → 2.5.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rcap/alert.rb +28 -29
- data/lib/rcap/base/alert.rb +192 -192
- data/lib/rcap/base/area.rb +84 -86
- data/lib/rcap/base/circle.rb +32 -32
- data/lib/rcap/base/info.rb +248 -253
- data/lib/rcap/base/parameter.rb +23 -24
- data/lib/rcap/base/point.rb +23 -23
- data/lib/rcap/base/polygon.rb +32 -32
- data/lib/rcap/base/resource.rb +57 -57
- data/lib/rcap/cap_1_0/alert.rb +79 -83
- data/lib/rcap/cap_1_0/area.rb +0 -2
- data/lib/rcap/cap_1_0/circle.rb +0 -1
- data/lib/rcap/cap_1_0/info.rb +1 -3
- data/lib/rcap/cap_1_0/parameter.rb +11 -12
- data/lib/rcap/cap_1_0/point.rb +0 -1
- data/lib/rcap/cap_1_0/polygon.rb +0 -2
- data/lib/rcap/cap_1_0/resource.rb +0 -3
- data/lib/rcap/cap_1_1/alert.rb +4 -6
- data/lib/rcap/cap_1_1/area.rb +0 -2
- data/lib/rcap/cap_1_1/circle.rb +0 -1
- data/lib/rcap/cap_1_1/info.rb +120 -129
- data/lib/rcap/cap_1_1/parameter.rb +0 -2
- data/lib/rcap/cap_1_1/point.rb +0 -1
- data/lib/rcap/cap_1_1/polygon.rb +0 -2
- data/lib/rcap/cap_1_1/resource.rb +32 -34
- data/lib/rcap/cap_1_2/alert.rb +4 -6
- data/lib/rcap/cap_1_2/area.rb +0 -2
- data/lib/rcap/cap_1_2/circle.rb +0 -1
- data/lib/rcap/cap_1_2/info.rb +114 -121
- data/lib/rcap/cap_1_2/parameter.rb +0 -2
- data/lib/rcap/cap_1_2/point.rb +0 -1
- data/lib/rcap/cap_1_2/polygon.rb +1 -3
- data/lib/rcap/cap_1_2/resource.rb +32 -34
- data/lib/rcap/config.rb +3 -3
- data/lib/rcap/custom_validators.rb +72 -76
- data/lib/rcap/extensions/array.rb +1 -1
- data/lib/rcap/extensions/date.rb +2 -2
- data/lib/rcap/extensions/date_time.rb +3 -3
- data/lib/rcap/extensions/string.rb +3 -3
- data/lib/rcap/extensions/time.rb +2 -3
- data/lib/rcap/info.rb +4 -5
- data/lib/rcap/utilities.rb +24 -25
- data/lib/rcap/validation.rb +19 -20
- data/lib/rcap/version.rb +1 -1
- 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 +39 -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 +38 -38
- 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 +34 -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 +36 -36
- 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 +43 -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 +47 -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 +2 -2
data/lib/rcap/base/area.rb
CHANGED
|
@@ -4,21 +4,21 @@ module RCAP
|
|
|
4
4
|
include Validation
|
|
5
5
|
|
|
6
6
|
# @return [String] Textual description of area.
|
|
7
|
-
attr_accessor(
|
|
7
|
+
attr_accessor(:area_desc)
|
|
8
8
|
# @return [Numeric] Expressed in feet above sea level
|
|
9
|
-
attr_accessor(
|
|
9
|
+
attr_accessor(:altitude)
|
|
10
10
|
# @return [Numeric] Expressed in feet above sea level.
|
|
11
|
-
attr_accessor(
|
|
11
|
+
attr_accessor(:ceiling)
|
|
12
12
|
# @return [Array<Circle>]
|
|
13
|
-
attr_reader(
|
|
13
|
+
attr_reader(:circles)
|
|
14
14
|
# @return [Array<Geocode>]
|
|
15
|
-
attr_reader(
|
|
15
|
+
attr_reader(:geocodes)
|
|
16
16
|
# @return [Array<Polygon>]
|
|
17
|
-
attr_reader(
|
|
17
|
+
attr_reader(:polygons)
|
|
18
18
|
|
|
19
|
-
validates_presence_of(
|
|
20
|
-
validates_collection_of(
|
|
21
|
-
validates_dependency_of(
|
|
19
|
+
validates_presence_of(:area_desc)
|
|
20
|
+
validates_collection_of(:circles, :geocodes, :polygons, allow_empty: true)
|
|
21
|
+
validates_dependency_of(:ceiling, on: :altitude)
|
|
22
22
|
|
|
23
23
|
XML_ELEMENT_NAME = 'area'
|
|
24
24
|
AREA_DESC_ELEMENT_NAME = 'areaDesc'
|
|
@@ -42,15 +42,15 @@ module RCAP
|
|
|
42
42
|
@circles = []
|
|
43
43
|
@geocodes = []
|
|
44
44
|
@polygons = []
|
|
45
|
-
yield(
|
|
45
|
+
yield(self) if block_given?
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
# Creates a new {Polygon} object and adds it to the {#polygons} array.
|
|
49
49
|
#
|
|
50
50
|
# @return [Polygon]
|
|
51
51
|
def add_polygon
|
|
52
|
-
|
|
53
|
-
yield(
|
|
52
|
+
polygon_class.new.tap do |polygon|
|
|
53
|
+
yield(polygon) if block_given?
|
|
54
54
|
@polygons << polygon
|
|
55
55
|
end
|
|
56
56
|
end
|
|
@@ -59,8 +59,8 @@ module RCAP
|
|
|
59
59
|
#
|
|
60
60
|
# @return [Circle]
|
|
61
61
|
def add_circle
|
|
62
|
-
|
|
63
|
-
yield(
|
|
62
|
+
circle_class.new.tap do |circle|
|
|
63
|
+
yield(circle) if block_given?
|
|
64
64
|
@circles << circle
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -69,70 +69,69 @@ module RCAP
|
|
|
69
69
|
#
|
|
70
70
|
# @return [Geocode]
|
|
71
71
|
def add_geocode
|
|
72
|
-
|
|
73
|
-
yield(
|
|
72
|
+
geocode_class.new do |geocode|
|
|
73
|
+
yield(geocode) if block_given?
|
|
74
74
|
@geocodes << geocode
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
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(
|
|
78
|
+
def self.from_xml_element(area_xml_element)
|
|
79
|
+
new do |area|
|
|
80
|
+
area.area_desc = RCAP.xpath_text(area_xml_element, AREA_DESC_XPATH, area.xmlns)
|
|
81
|
+
area.altitude = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, ALTITUDE_XPATH, area.xmlns))
|
|
82
|
+
area.ceiling = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, CEILING_XPATH, area.xmlns))
|
|
83
83
|
|
|
84
|
-
RCAP.xpath_match(
|
|
85
|
-
area.circles << area.circle_class.from_xml_element(
|
|
84
|
+
RCAP.xpath_match(area_xml_element, area.circle_class::XPATH, area.xmlns).each do |circle_element|
|
|
85
|
+
area.circles << area.circle_class.from_xml_element(circle_element)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
RCAP.xpath_match(
|
|
89
|
-
area.geocodes << area.geocode_class.from_xml_element(
|
|
88
|
+
RCAP.xpath_match(area_xml_element, area.geocode_class::XPATH, area.xmlns).each do |geocode_element|
|
|
89
|
+
area.geocodes << area.geocode_class.from_xml_element(geocode_element)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
RCAP.xpath_match(
|
|
93
|
-
area.polygons << area.polygon_class.from_xml_element(
|
|
92
|
+
RCAP.xpath_match(area_xml_element, area.polygon_class::XPATH, area.xmlns).each do |polygon_element|
|
|
93
|
+
area.polygons << area.polygon_class.from_xml_element(polygon_element)
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
# @return [REXML::Element]
|
|
99
99
|
def to_xml_element
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
REXML::Element.new(XML_ELEMENT_NAME).tap do |xml_element|
|
|
101
|
+
xml_element.add_element(AREA_DESC_ELEMENT_NAME).add_text(@area_desc.to_s)
|
|
102
|
+
add_to_xml_element = lambda do |element, object|
|
|
103
|
+
element.add_element(object.to_xml_element)
|
|
104
|
+
element
|
|
105
|
+
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?
|
|
105
111
|
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
112
|
end
|
|
113
113
|
|
|
114
114
|
# @return [String] XML representation of the Area
|
|
115
115
|
def to_xml
|
|
116
|
-
|
|
116
|
+
to_xml_element.to_s
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
# Implements an equality operator for the Area object. Two Area objects are equal if all their attributes are equal.
|
|
120
120
|
#
|
|
121
121
|
# @param [Area] other Area object to compare
|
|
122
122
|
# @return [true,false]
|
|
123
|
-
def ==(
|
|
124
|
-
comparison_attributes = lambda{ |area| [
|
|
125
|
-
comparison_attributes.call(
|
|
123
|
+
def ==(other)
|
|
124
|
+
comparison_attributes = lambda { |area| [area.area_desc, area.altitude, area.ceiling, area.circles, area.geocodes, area.polygons] }
|
|
125
|
+
comparison_attributes.call(self) == comparison_attributes.call(other)
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
# @return [String]
|
|
129
129
|
def inspect
|
|
130
|
-
area_inspect = "Area Description: #{ @area_desc }\n"
|
|
131
|
-
"Polygons:\n"+
|
|
132
|
-
|
|
133
|
-
"Circles: #{ @circles.inspect }\n"+
|
|
130
|
+
area_inspect = "Area Description: #{ @area_desc }\n"\
|
|
131
|
+
"Polygons:\n" + @polygons.map { |polygon| ' ' + polygon.inspect }.join("\n") + "\n"\
|
|
132
|
+
"Circles: #{ @circles.inspect }\n"\
|
|
134
133
|
"Geocodes: #{ @geocodes.inspect }\n"
|
|
135
|
-
RCAP.format_lines_for_inspect(
|
|
134
|
+
RCAP.format_lines_for_inspect('AREA', area_inspect)
|
|
136
135
|
end
|
|
137
136
|
|
|
138
137
|
# Returns the area description
|
|
@@ -142,7 +141,6 @@ module RCAP
|
|
|
142
141
|
@area_desc
|
|
143
142
|
end
|
|
144
143
|
|
|
145
|
-
|
|
146
144
|
AREA_DESC_YAML = 'Area Description'
|
|
147
145
|
ALTITUDE_YAML = 'Altitude'
|
|
148
146
|
CEILING_YAML = 'Ceiling'
|
|
@@ -150,42 +148,42 @@ module RCAP
|
|
|
150
148
|
GEOCODES_YAML = 'Geocodes'
|
|
151
149
|
POLYGONS_YAML = 'Polygons'
|
|
152
150
|
|
|
153
|
-
# @return [Hash]
|
|
151
|
+
# @return [Hash]
|
|
154
152
|
def to_yaml_data
|
|
155
|
-
RCAP.attribute_values_to_hash(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
RCAP.attribute_values_to_hash([AREA_DESC_YAML, @area_desc],
|
|
154
|
+
[ALTITUDE_YAML, @altitude],
|
|
155
|
+
[CEILING_YAML, @ceiling],
|
|
156
|
+
[CIRCLES_YAML, @circles.map { |circle| circle.to_a }],
|
|
157
|
+
[GEOCODES_YAML, @geocodes.reduce({}) { |h, geocode| h.merge(geocode.name => geocode.value) }],
|
|
158
|
+
[POLYGONS_YAML, @polygons.map(&:to_yaml_data)])
|
|
161
159
|
end
|
|
162
160
|
|
|
163
161
|
# @return [String] YAML representation of object
|
|
164
|
-
def to_yaml(
|
|
165
|
-
|
|
162
|
+
def to_yaml(options = {})
|
|
163
|
+
to_yaml_data.to_yaml(options)
|
|
166
164
|
end
|
|
167
165
|
|
|
168
166
|
# @param [Hash] area_yaml_data
|
|
169
167
|
# @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(
|
|
168
|
+
def self.from_yaml_data(area_yaml_data)
|
|
169
|
+
new do |area|
|
|
170
|
+
area.area_desc = area_yaml_data[AREA_DESC_YAML]
|
|
171
|
+
area.altitude = area_yaml_data[ALTITUDE_YAML]
|
|
172
|
+
area.ceiling = area_yaml_data[CEILING_YAML]
|
|
173
|
+
|
|
174
|
+
Array(area_yaml_data[CIRCLES_YAML]).each do |circle_yaml_data|
|
|
175
|
+
area.circles << area.circle_class.from_yaml_data(circle_yaml_data)
|
|
178
176
|
end
|
|
179
177
|
|
|
180
|
-
Array(
|
|
178
|
+
Array(area_yaml_data[GEOCODES_YAML]).each do |name, value|
|
|
181
179
|
area.add_geocode do |geocode|
|
|
182
180
|
geocode.name = name
|
|
183
181
|
geocode.value = value
|
|
184
182
|
end
|
|
185
183
|
end
|
|
186
184
|
|
|
187
|
-
Array(
|
|
188
|
-
area.polygons << area.polygon_class.from_yaml_data(
|
|
185
|
+
Array(area_yaml_data[POLYGONS_YAML]).each do |polyon_yaml_data|
|
|
186
|
+
area.polygons << area.polygon_class.from_yaml_data(polyon_yaml_data)
|
|
189
187
|
end
|
|
190
188
|
end
|
|
191
189
|
end
|
|
@@ -199,34 +197,34 @@ module RCAP
|
|
|
199
197
|
|
|
200
198
|
# @param [Hash] area_hash
|
|
201
199
|
# @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(
|
|
200
|
+
def self.from_h(area_hash)
|
|
201
|
+
new do |area|
|
|
202
|
+
area.area_desc = area_hash[AREA_DESC_KEY]
|
|
203
|
+
area.altitude = area_hash[ALTITUDE_KEY]
|
|
204
|
+
area.ceiling = area_hash[CEILING_KEY]
|
|
205
|
+
|
|
206
|
+
Array(area_hash[CIRCLES_KEY]).each do |circle_array|
|
|
207
|
+
area.circles << area.circle_class.from_a(circle_array)
|
|
210
208
|
end
|
|
211
209
|
|
|
212
|
-
Array(
|
|
213
|
-
area.geocodes << area.geocode_class.from_h(
|
|
210
|
+
Array(area_hash[GEOCODES_KEY]).each do |geocode_hash|
|
|
211
|
+
area.geocodes << area.geocode_class.from_h(geocode_hash)
|
|
214
212
|
end
|
|
215
213
|
|
|
216
|
-
Array(
|
|
217
|
-
area.polygons << area.polygon_class.from_h(
|
|
214
|
+
Array(area_hash[POLYGONS_KEY]).each do |polygon_hash|
|
|
215
|
+
area.polygons << area.polygon_class.from_h(polygon_hash)
|
|
218
216
|
end
|
|
219
217
|
end
|
|
220
218
|
end
|
|
221
219
|
|
|
222
220
|
# @return [Hash]
|
|
223
221
|
def to_h
|
|
224
|
-
RCAP.attribute_values_to_hash(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
222
|
+
RCAP.attribute_values_to_hash([AREA_DESC_KEY, @area_desc],
|
|
223
|
+
[ALTITUDE_KEY, @altitude],
|
|
224
|
+
[CEILING_KEY, @ceiling],
|
|
225
|
+
[CIRCLES_KEY, @circles.map { |circle| circle.to_a }],
|
|
226
|
+
[GEOCODES_KEY, @geocodes.map { |geocode| geocode.to_h }],
|
|
227
|
+
[POLYGONS_KEY, @polygons.map { |polygon| polygon.to_h }])
|
|
230
228
|
end
|
|
231
229
|
end
|
|
232
230
|
end
|
data/lib/rcap/base/circle.rb
CHANGED
|
@@ -4,10 +4,10 @@ module RCAP
|
|
|
4
4
|
include Validation
|
|
5
5
|
|
|
6
6
|
# @return [Numeric] Expresed in kilometers
|
|
7
|
-
attr_accessor(
|
|
7
|
+
attr_accessor(:radius)
|
|
8
8
|
|
|
9
|
-
validates_presence_of(
|
|
10
|
-
validates_numericality_of(
|
|
9
|
+
validates_presence_of(:radius)
|
|
10
|
+
validates_numericality_of(:radius, greater_than_or_equal: 0)
|
|
11
11
|
|
|
12
12
|
XML_ELEMENT_NAME = 'circle'
|
|
13
13
|
|
|
@@ -18,7 +18,7 @@ module RCAP
|
|
|
18
18
|
# @option attributes [Numeric] :longitude
|
|
19
19
|
# @option attributes [Numeric] :radius
|
|
20
20
|
def initialize
|
|
21
|
-
yield(
|
|
21
|
+
yield(self) if block_given?
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# Returns a string representation of the circle of the form
|
|
@@ -31,19 +31,19 @@ module RCAP
|
|
|
31
31
|
|
|
32
32
|
# @return [String]
|
|
33
33
|
def inspect
|
|
34
|
-
"(#{ self
|
|
34
|
+
"(#{ self })"
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# @return [REXML::Element]
|
|
38
38
|
def to_xml_element
|
|
39
|
-
xml_element = REXML::Element.new(
|
|
40
|
-
xml_element.add_text(
|
|
39
|
+
xml_element = REXML::Element.new(XML_ELEMENT_NAME)
|
|
40
|
+
xml_element.add_text(to_s)
|
|
41
41
|
xml_element
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
# @return [String]
|
|
45
45
|
def to_xml
|
|
46
|
-
|
|
46
|
+
to_xml_element.to_s
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
# Parses a circle string of the form
|
|
@@ -51,31 +51,31 @@ module RCAP
|
|
|
51
51
|
#
|
|
52
52
|
# @param [String] circle_string
|
|
53
53
|
# @return [Array(Float,Float,Float)]
|
|
54
|
-
def self.parse_circle_string(
|
|
55
|
-
coordinates, radius = circle_string.split(
|
|
56
|
-
lattitude, longitude = coordinates.split(
|
|
57
|
-
[
|
|
54
|
+
def self.parse_circle_string(circle_string)
|
|
55
|
+
coordinates, radius = circle_string.split(' ')
|
|
56
|
+
lattitude, longitude = coordinates.split(',')
|
|
57
|
+
[lattitude, longitude, radius].map { |e| e.to_f }
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
# @param [REXML::Element] circle_xml_element
|
|
61
61
|
# @return [Circle]
|
|
62
|
-
def self.from_xml_element(
|
|
63
|
-
|
|
62
|
+
def self.from_xml_element(circle_xml_element)
|
|
63
|
+
from_a(parse_circle_string(circle_xml_element.text))
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Two circles are equivalent if their lattitude, longitude and radius are equal.
|
|
67
67
|
#
|
|
68
68
|
# @param [Circle] other
|
|
69
69
|
# @return [true,false]
|
|
70
|
-
def ==(
|
|
71
|
-
|
|
70
|
+
def ==(other)
|
|
71
|
+
to_a == other.to_a
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# @param [Array(Numeric, Numeric, Numeric)] circle_yaml_data lattitude, longitude, radius
|
|
75
75
|
# @return [Circle]
|
|
76
|
-
def self.from_yaml_data(
|
|
76
|
+
def self.from_yaml_data(circle_yaml_data)
|
|
77
77
|
lattitude, longitude, radius = circle_yaml_data
|
|
78
|
-
|
|
78
|
+
new do |circle|
|
|
79
79
|
circle.lattitude = lattitude.to_f
|
|
80
80
|
circle.longitude = longitude.to_f
|
|
81
81
|
circle.radius = radius.to_f
|
|
@@ -85,35 +85,35 @@ module RCAP
|
|
|
85
85
|
RADIUS_KEY = 'radius'
|
|
86
86
|
# @return [Hash]
|
|
87
87
|
def to_h
|
|
88
|
-
RCAP.attribute_values_to_hash(
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
RCAP.attribute_values_to_hash([RADIUS_KEY, @radius],
|
|
89
|
+
[LATTITUDE_KEY, @lattitude],
|
|
90
|
+
[LONGITUDE_KEY, @longitude])
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
# @param [Hash] circle_hash
|
|
94
94
|
# @return [Circle]
|
|
95
|
-
def self.from_h(
|
|
96
|
-
|
|
97
|
-
circle.radius = circle_hash[
|
|
98
|
-
circle.lattitude = circle_hash[
|
|
99
|
-
circle.longitude = circle_hash[
|
|
95
|
+
def self.from_h(circle_hash)
|
|
96
|
+
new do |circle|
|
|
97
|
+
circle.radius = circle_hash[RADIUS_KEY].to_f
|
|
98
|
+
circle.lattitude = circle_hash[LATTITUDE_KEY].to_f
|
|
99
|
+
circle.longitude = circle_hash[LONGITUDE_KEY].to_f
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
# @return [Array(Numeric,Numeric,Numeric)]
|
|
104
104
|
def to_a
|
|
105
|
-
[
|
|
105
|
+
[@lattitude, @longitude, @radius]
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
RADIUS_INDEX = 2
|
|
109
109
|
|
|
110
110
|
# @param [Array] circle_array
|
|
111
111
|
# @return [Circle]
|
|
112
|
-
def self.from_a(
|
|
113
|
-
|
|
114
|
-
circle.longitude = circle_array[
|
|
115
|
-
circle.lattitude = circle_array[
|
|
116
|
-
circle.radius = circle_array[
|
|
112
|
+
def self.from_a(circle_array)
|
|
113
|
+
new do |circle|
|
|
114
|
+
circle.longitude = circle_array[LONGITUDE_INDEX].to_f
|
|
115
|
+
circle.lattitude = circle_array[LATTITUDE_INDEX].to_f
|
|
116
|
+
circle.radius = circle_array[RADIUS_INDEX].to_f
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
end
|
data/lib/rcap/base/info.rb
CHANGED
|
@@ -3,50 +3,50 @@ module RCAP
|
|
|
3
3
|
class Info
|
|
4
4
|
include Validation
|
|
5
5
|
|
|
6
|
-
CATEGORY_GEO =
|
|
7
|
-
CATEGORY_MET =
|
|
8
|
-
CATEGORY_SAFETY =
|
|
9
|
-
CATEGORY_SECURITY =
|
|
10
|
-
CATEGORY_RESCUE =
|
|
11
|
-
CATEGORY_FIRE =
|
|
12
|
-
CATEGORY_HEALTH =
|
|
13
|
-
CATEGORY_ENV =
|
|
14
|
-
CATEGORY_TRANSPORT =
|
|
15
|
-
CATEGORY_INFRA =
|
|
16
|
-
CATEGORY_CBRNE =
|
|
17
|
-
CATEGORY_OTHER =
|
|
6
|
+
CATEGORY_GEO = 'Geo'
|
|
7
|
+
CATEGORY_MET = 'Met'
|
|
8
|
+
CATEGORY_SAFETY = 'Safety'
|
|
9
|
+
CATEGORY_SECURITY = 'Security'
|
|
10
|
+
CATEGORY_RESCUE = 'Rescue'
|
|
11
|
+
CATEGORY_FIRE = 'Fire'
|
|
12
|
+
CATEGORY_HEALTH = 'Health'
|
|
13
|
+
CATEGORY_ENV = 'Env'
|
|
14
|
+
CATEGORY_TRANSPORT = 'Transport'
|
|
15
|
+
CATEGORY_INFRA = 'Infra'
|
|
16
|
+
CATEGORY_CBRNE = 'CBRNE'
|
|
17
|
+
CATEGORY_OTHER = 'Other'
|
|
18
18
|
# Valid values for categories
|
|
19
|
-
VALID_CATEGORIES = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
URGENCY_IMMEDIATE =
|
|
25
|
-
URGENCY_EXPECTED =
|
|
26
|
-
URGENCY_FUTURE =
|
|
27
|
-
URGENCY_PAST =
|
|
28
|
-
URGENCY_UNKNOWN =
|
|
19
|
+
VALID_CATEGORIES = [CATEGORY_GEO, CATEGORY_MET, CATEGORY_SAFETY,
|
|
20
|
+
CATEGORY_SECURITY, CATEGORY_RESCUE, CATEGORY_FIRE, CATEGORY_HEALTH,
|
|
21
|
+
CATEGORY_ENV, CATEGORY_TRANSPORT, CATEGORY_INFRA, CATEGORY_CBRNE,
|
|
22
|
+
CATEGORY_OTHER]
|
|
23
|
+
|
|
24
|
+
URGENCY_IMMEDIATE = 'Immediate'
|
|
25
|
+
URGENCY_EXPECTED = 'Expected'
|
|
26
|
+
URGENCY_FUTURE = 'Future'
|
|
27
|
+
URGENCY_PAST = 'Past'
|
|
28
|
+
URGENCY_UNKNOWN = 'Unknown'
|
|
29
29
|
# Valid values for urgency
|
|
30
|
-
VALID_URGENCIES = [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
SEVERITY_EXTREME =
|
|
34
|
-
SEVERITY_SEVERE =
|
|
35
|
-
SEVERITY_MODERATE =
|
|
36
|
-
SEVERITY_MINOR =
|
|
37
|
-
SEVERITY_UNKNOWN =
|
|
30
|
+
VALID_URGENCIES = [URGENCY_IMMEDIATE, URGENCY_EXPECTED, URGENCY_FUTURE,
|
|
31
|
+
URGENCY_PAST, URGENCY_UNKNOWN]
|
|
32
|
+
|
|
33
|
+
SEVERITY_EXTREME = 'Extreme'
|
|
34
|
+
SEVERITY_SEVERE = 'Severe'
|
|
35
|
+
SEVERITY_MODERATE = 'Moderate'
|
|
36
|
+
SEVERITY_MINOR = 'Minor'
|
|
37
|
+
SEVERITY_UNKNOWN = 'Unknown'
|
|
38
38
|
# Valid values for severity
|
|
39
|
-
VALID_SEVERITIES = [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
CERTAINTY_VERY_LIKELY =
|
|
43
|
-
CERTAINTY_LIKELY =
|
|
44
|
-
CERTAINTY_POSSIBLE =
|
|
45
|
-
CERTAINTY_UNLIKELY =
|
|
46
|
-
CERTAINTY_UNKNOWN =
|
|
39
|
+
VALID_SEVERITIES = [SEVERITY_EXTREME, SEVERITY_SEVERE, SEVERITY_MODERATE,
|
|
40
|
+
SEVERITY_MINOR, SEVERITY_UNKNOWN]
|
|
41
|
+
|
|
42
|
+
CERTAINTY_VERY_LIKELY = 'Very Likely'
|
|
43
|
+
CERTAINTY_LIKELY = 'Likely'
|
|
44
|
+
CERTAINTY_POSSIBLE = 'Possible'
|
|
45
|
+
CERTAINTY_UNLIKELY = 'Unlikely'
|
|
46
|
+
CERTAINTY_UNKNOWN = 'Unknown'
|
|
47
47
|
# Valid valies for certainty
|
|
48
|
-
VALID_CERTAINTIES = [
|
|
49
|
-
|
|
48
|
+
VALID_CERTAINTIES = [CERTAINTY_VERY_LIKELY, CERTAINTY_LIKELY,
|
|
49
|
+
CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN]
|
|
50
50
|
|
|
51
51
|
XML_ELEMENT_NAME = 'info'
|
|
52
52
|
LANGUAGE_ELEMENT_NAME = 'language'
|
|
@@ -88,57 +88,56 @@ module RCAP
|
|
|
88
88
|
|
|
89
89
|
DEFAULT_LANGUAGE = 'en-US'
|
|
90
90
|
|
|
91
|
-
validates_presence_of(
|
|
92
|
-
validates_presence_of(
|
|
93
|
-
validates_presence_of(
|
|
94
|
-
validates_presence_of(
|
|
95
|
-
validates_inclusion_of(
|
|
96
|
-
validates_inclusion_of(
|
|
97
|
-
validates_inclusion_of_members_of(
|
|
98
|
-
validates_collection_of(
|
|
91
|
+
validates_presence_of(:event)
|
|
92
|
+
validates_presence_of(:urgency)
|
|
93
|
+
validates_presence_of(:severity)
|
|
94
|
+
validates_presence_of(:certainty)
|
|
95
|
+
validates_inclusion_of(:severity, allow_nil: true, in: VALID_SEVERITIES, message: "can only be assigned the following values: #{ VALID_SEVERITIES.join(', ') }")
|
|
96
|
+
validates_inclusion_of(:urgency, allow_nil: true, in: VALID_URGENCIES, message: "can only be assigned the following values: #{ VALID_URGENCIES.join(', ') }")
|
|
97
|
+
validates_inclusion_of_members_of(:categories, in: VALID_CATEGORIES, allow_blank: true)
|
|
98
|
+
validates_collection_of(:resources, :areas, :event_codes, :parameters)
|
|
99
99
|
|
|
100
100
|
# @return [String]
|
|
101
|
-
attr_accessor(
|
|
101
|
+
attr_accessor(:event)
|
|
102
102
|
# @return [String] Value can only be one of {VALID_URGENCIES}
|
|
103
|
-
attr_accessor(
|
|
103
|
+
attr_accessor(:urgency)
|
|
104
104
|
# @return [String] Value can only be one of {VALID_SEVERITIES}
|
|
105
|
-
attr_accessor(
|
|
105
|
+
attr_accessor(:severity)
|
|
106
106
|
# @return [String] Value can only be one of {VALID_CERTAINTIES}
|
|
107
|
-
attr_accessor(
|
|
107
|
+
attr_accessor(:certainty)
|
|
108
108
|
# @return [String]
|
|
109
|
-
attr_accessor(
|
|
109
|
+
attr_accessor(:language)
|
|
110
110
|
# @return [String]
|
|
111
|
-
attr_accessor(
|
|
111
|
+
attr_accessor(:audience)
|
|
112
112
|
# @return [DateTime] Effective start time of information
|
|
113
|
-
attr_accessor(
|
|
113
|
+
attr_accessor(:effective)
|
|
114
114
|
# @return [DateTime] Expected start of event
|
|
115
|
-
attr_accessor(
|
|
115
|
+
attr_accessor(:onset)
|
|
116
116
|
# @return [DateTime] Effective expiry time of information
|
|
117
|
-
attr_accessor(
|
|
117
|
+
attr_accessor(:expires)
|
|
118
118
|
# @return [String]
|
|
119
|
-
attr_accessor(
|
|
119
|
+
attr_accessor(:sender_name)
|
|
120
120
|
# @return [String]
|
|
121
|
-
attr_accessor(
|
|
121
|
+
attr_accessor(:headline)
|
|
122
122
|
# @return [String]
|
|
123
|
-
attr_accessor(
|
|
123
|
+
attr_accessor(:description)
|
|
124
124
|
# @return [String]
|
|
125
|
-
attr_accessor(
|
|
125
|
+
attr_accessor(:instruction)
|
|
126
126
|
# @return [String]
|
|
127
|
-
attr_accessor(
|
|
127
|
+
attr_accessor(:web)
|
|
128
128
|
# @return [String]
|
|
129
|
-
attr_accessor(
|
|
129
|
+
attr_accessor(:contact)
|
|
130
130
|
|
|
131
131
|
# @return [Array<String>] Collection of textual categories; elements can be one of {VALID_CATEGORIES}
|
|
132
|
-
attr_reader(
|
|
132
|
+
attr_reader(:categories)
|
|
133
133
|
# @return [Array<EventCode>] Collection of {EventCode} objects
|
|
134
|
-
attr_reader(
|
|
134
|
+
attr_reader(:event_codes)
|
|
135
135
|
# @return [Array<Parameter>] Collection of {Parameter} objects
|
|
136
|
-
attr_reader(
|
|
136
|
+
attr_reader(:parameters)
|
|
137
137
|
# @return [Array<Resource> Collection of {Resource} objects
|
|
138
|
-
attr_reader(
|
|
138
|
+
attr_reader(:resources)
|
|
139
139
|
# @return [Array<Area>] Collection of {Area} objects
|
|
140
|
-
attr_reader(
|
|
141
|
-
|
|
140
|
+
attr_reader(:areas)
|
|
142
141
|
|
|
143
142
|
# Initialises a new Info object which will be yielded to an attached block if given
|
|
144
143
|
#
|
|
@@ -150,15 +149,15 @@ module RCAP
|
|
|
150
149
|
@parameters = []
|
|
151
150
|
@resources = []
|
|
152
151
|
@areas = []
|
|
153
|
-
yield(
|
|
152
|
+
yield(self) if block_given?
|
|
154
153
|
end
|
|
155
154
|
|
|
156
155
|
# Creates a new EventCode object and adds it to the event_codes array.
|
|
157
156
|
#
|
|
158
157
|
# @return [EventCode]
|
|
159
158
|
def add_event_code
|
|
160
|
-
event_code =
|
|
161
|
-
yield(
|
|
159
|
+
event_code = event_code_class.new
|
|
160
|
+
yield(event_code) if block_given?
|
|
162
161
|
@event_codes << event_code
|
|
163
162
|
event_code
|
|
164
163
|
end
|
|
@@ -167,8 +166,8 @@ module RCAP
|
|
|
167
166
|
#
|
|
168
167
|
# @return [Parameter]
|
|
169
168
|
def add_parameter
|
|
170
|
-
parameter =
|
|
171
|
-
yield(
|
|
169
|
+
parameter = parameter_class.new
|
|
170
|
+
yield(parameter) if block_given?
|
|
172
171
|
@parameters << parameter
|
|
173
172
|
parameter
|
|
174
173
|
end
|
|
@@ -177,8 +176,8 @@ module RCAP
|
|
|
177
176
|
#
|
|
178
177
|
# @return [Resource]
|
|
179
178
|
def add_resource
|
|
180
|
-
resource =
|
|
181
|
-
yield(
|
|
179
|
+
resource = resource_class.new
|
|
180
|
+
yield(resource) if block_given?
|
|
182
181
|
@resources << resource
|
|
183
182
|
resource
|
|
184
183
|
end
|
|
@@ -187,123 +186,119 @@ module RCAP
|
|
|
187
186
|
#
|
|
188
187
|
# @return [Area]
|
|
189
188
|
def add_area
|
|
190
|
-
area =
|
|
191
|
-
yield(
|
|
189
|
+
area = area_class.new
|
|
190
|
+
yield(area) if block_given?
|
|
192
191
|
@areas << area
|
|
193
192
|
area
|
|
194
193
|
end
|
|
195
194
|
|
|
196
195
|
# @return [REXML::Element]
|
|
197
196
|
def to_xml_element
|
|
198
|
-
xml_element = REXML::Element.new(
|
|
199
|
-
xml_element.add_element(
|
|
197
|
+
xml_element = REXML::Element.new(XML_ELEMENT_NAME)
|
|
198
|
+
xml_element.add_element(LANGUAGE_ELEMENT_NAME).add_text(@language) if @language
|
|
200
199
|
@categories.each do |category|
|
|
201
|
-
xml_element.add_element(
|
|
200
|
+
xml_element.add_element(CATEGORY_ELEMENT_NAME).add_text(category)
|
|
202
201
|
end
|
|
203
|
-
xml_element.add_element(
|
|
204
|
-
xml_element.add_element(
|
|
205
|
-
xml_element.add_element(
|
|
206
|
-
xml_element.add_element(
|
|
207
|
-
xml_element.add_element(
|
|
202
|
+
xml_element.add_element(EVENT_ELEMENT_NAME).add_text(@event)
|
|
203
|
+
xml_element.add_element(URGENCY_ELEMENT_NAME).add_text(@urgency)
|
|
204
|
+
xml_element.add_element(SEVERITY_ELEMENT_NAME).add_text(@severity)
|
|
205
|
+
xml_element.add_element(CERTAINTY_ELEMENT_NAME).add_text(@certainty)
|
|
206
|
+
xml_element.add_element(AUDIENCE_ELEMENT_NAME).add_text(@audience) if @audience
|
|
208
207
|
@event_codes.each do |event_code|
|
|
209
|
-
xml_element.add_element(
|
|
208
|
+
xml_element.add_element(event_code.to_xml_element)
|
|
210
209
|
end
|
|
211
|
-
xml_element.add_element(
|
|
212
|
-
xml_element.add_element(
|
|
213
|
-
xml_element.add_element(
|
|
214
|
-
xml_element.add_element(
|
|
215
|
-
xml_element.add_element(
|
|
216
|
-
xml_element.add_element(
|
|
217
|
-
xml_element.add_element(
|
|
218
|
-
xml_element.add_element(
|
|
219
|
-
xml_element.add_element(
|
|
210
|
+
xml_element.add_element(EFFECTIVE_ELEMENT_NAME).add_text(@effective.to_s_for_cap) if @effective
|
|
211
|
+
xml_element.add_element(ONSET_ELEMENT_NAME).add_text(@onset.to_s_for_cap) if @onset
|
|
212
|
+
xml_element.add_element(EXPIRES_ELEMENT_NAME).add_text(@expires.to_s_for_cap) if @expires
|
|
213
|
+
xml_element.add_element(SENDER_NAME_ELEMENT_NAME).add_text(@sender_name) if @sender_name
|
|
214
|
+
xml_element.add_element(HEADLINE_ELEMENT_NAME).add_text(@headline) if @headline
|
|
215
|
+
xml_element.add_element(DESCRIPTION_ELEMENT_NAME).add_text(@description) if @description
|
|
216
|
+
xml_element.add_element(INSTRUCTION_ELEMENT_NAME).add_text(@instruction) if @instruction
|
|
217
|
+
xml_element.add_element(WEB_ELEMENT_NAME).add_text(@web) if @web
|
|
218
|
+
xml_element.add_element(CONTACT_ELEMENT_NAME).add_text(@contact) if @contact
|
|
220
219
|
@parameters.each do |parameter|
|
|
221
|
-
xml_element.add_element(
|
|
220
|
+
xml_element.add_element(parameter.to_xml_element)
|
|
222
221
|
end
|
|
223
222
|
@resources.each do |resource|
|
|
224
|
-
xml_element.add_element(
|
|
223
|
+
xml_element.add_element(resource.to_xml_element)
|
|
225
224
|
end
|
|
226
225
|
@areas.each do |area|
|
|
227
|
-
xml_element.add_element(
|
|
226
|
+
xml_element.add_element(area.to_xml_element)
|
|
228
227
|
end
|
|
229
228
|
xml_element
|
|
230
229
|
end
|
|
231
230
|
|
|
232
231
|
# @return [String]
|
|
233
232
|
def to_xml
|
|
234
|
-
|
|
233
|
+
to_xml_element.to_s
|
|
235
234
|
end
|
|
236
235
|
|
|
237
236
|
# @param [REXML::Element] info_xml_element
|
|
238
237
|
# @return [Info]
|
|
239
|
-
def self.from_xml_element(
|
|
240
|
-
|
|
241
|
-
info.language = RCAP.xpath_text(
|
|
238
|
+
def self.from_xml_element(info_xml_element)
|
|
239
|
+
new do |info|
|
|
240
|
+
info.language = RCAP.xpath_text(info_xml_element, LANGUAGE_XPATH, info.xmlns) || DEFAULT_LANGUAGE
|
|
242
241
|
|
|
243
|
-
RCAP.xpath_match(
|
|
242
|
+
RCAP.xpath_match(info_xml_element, CATEGORY_XPATH, info.xmlns).each do |element|
|
|
244
243
|
info.categories << element.text
|
|
245
244
|
end
|
|
246
245
|
|
|
247
|
-
info.event = RCAP.xpath_text(
|
|
248
|
-
info.urgency = RCAP.xpath_text(
|
|
249
|
-
info.severity = RCAP.xpath_text(
|
|
250
|
-
info.certainty = RCAP.xpath_text(
|
|
251
|
-
info.audience = RCAP.xpath_text(
|
|
252
|
-
info.effective = RCAP.parse_datetime(
|
|
253
|
-
info.onset = RCAP.parse_datetime(
|
|
254
|
-
info.expires = RCAP.parse_datetime(
|
|
255
|
-
info.sender_name = RCAP.xpath_text(
|
|
256
|
-
info.headline = RCAP.xpath_text(
|
|
257
|
-
info.description = RCAP.xpath_text(
|
|
258
|
-
info.instruction = RCAP.xpath_text(
|
|
259
|
-
info.web = RCAP.xpath_text(
|
|
260
|
-
info.contact = RCAP.xpath_text(
|
|
261
|
-
|
|
262
|
-
RCAP.xpath_match(
|
|
263
|
-
info.event_codes << info.event_code_class.from_xml_element(
|
|
246
|
+
info.event = RCAP.xpath_text(info_xml_element, EVENT_XPATH, info.xmlns)
|
|
247
|
+
info.urgency = RCAP.xpath_text(info_xml_element, URGENCY_XPATH, info.xmlns)
|
|
248
|
+
info.severity = RCAP.xpath_text(info_xml_element, SEVERITY_XPATH, info.xmlns)
|
|
249
|
+
info.certainty = RCAP.xpath_text(info_xml_element, CERTAINTY_XPATH, info.xmlns)
|
|
250
|
+
info.audience = RCAP.xpath_text(info_xml_element, AUDIENCE_XPATH, info.xmlns)
|
|
251
|
+
info.effective = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, EFFECTIVE_XPATH, info.xmlns))
|
|
252
|
+
info.onset = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, ONSET_XPATH, info.xmlns))
|
|
253
|
+
info.expires = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, EXPIRES_XPATH, info.xmlns))
|
|
254
|
+
info.sender_name = RCAP.xpath_text(info_xml_element, SENDER_NAME_XPATH, info.xmlns)
|
|
255
|
+
info.headline = RCAP.xpath_text(info_xml_element, HEADLINE_XPATH, info.xmlns)
|
|
256
|
+
info.description = RCAP.xpath_text(info_xml_element, DESCRIPTION_XPATH, info.xmlns)
|
|
257
|
+
info.instruction = RCAP.xpath_text(info_xml_element, INSTRUCTION_XPATH, info.xmlns)
|
|
258
|
+
info.web = RCAP.xpath_text(info_xml_element, WEB_XPATH, info.xmlns)
|
|
259
|
+
info.contact = RCAP.xpath_text(info_xml_element, CONTACT_XPATH, info.xmlns)
|
|
260
|
+
|
|
261
|
+
RCAP.xpath_match(info_xml_element, info.event_code_class::XPATH, info.xmlns).each do |element|
|
|
262
|
+
info.event_codes << info.event_code_class.from_xml_element(element)
|
|
264
263
|
end
|
|
265
264
|
|
|
266
|
-
RCAP.xpath_match(
|
|
267
|
-
info.parameters << info.parameter_class.from_xml_element(
|
|
265
|
+
RCAP.xpath_match(info_xml_element, info.parameter_class::XPATH, info.xmlns).each do |element|
|
|
266
|
+
info.parameters << info.parameter_class.from_xml_element(element)
|
|
268
267
|
end
|
|
269
268
|
|
|
270
|
-
RCAP.xpath_match(
|
|
271
|
-
|
|
269
|
+
RCAP.xpath_match(info_xml_element, info.resource_class::XPATH, info.xmlns).each do |element|
|
|
270
|
+
info.resources << info.resource_class.from_xml_element(element)
|
|
272
271
|
end
|
|
273
272
|
|
|
274
|
-
RCAP.xpath_match(
|
|
275
|
-
info.areas << info.area_class.from_xml_element(
|
|
273
|
+
RCAP.xpath_match(info_xml_element, info.area_class::XPATH, info.xmlns).each do |element|
|
|
274
|
+
info.areas << info.area_class.from_xml_element(element)
|
|
276
275
|
end
|
|
277
276
|
end
|
|
278
277
|
end
|
|
279
278
|
|
|
280
279
|
# @return [String]
|
|
281
280
|
def inspect
|
|
282
|
-
info_inspect = "Language: #{ @language }\n"
|
|
283
|
-
"Categories: #{ @categories.to_s_for_cap }\n"
|
|
284
|
-
"Event: #{ @event }\n"
|
|
285
|
-
"Urgency: #{ @urgency }\n"
|
|
286
|
-
"Severity: #{ @severity }\n"
|
|
287
|
-
"Certainty: #{ @certainty }\n"
|
|
288
|
-
"Audience: #{ @audience }\n"
|
|
289
|
-
"Event Codes: #{ @event_codes.inspect }\n"
|
|
290
|
-
"Effective: #{ @effective }\n"
|
|
291
|
-
"Onset: #{ @onset }\n"
|
|
292
|
-
"Expires: #{ @expires }\n"
|
|
293
|
-
"Sender Name: #{ @sender_name }\n"
|
|
294
|
-
"Headline: #{ @headline }\n"
|
|
295
|
-
"Description:\n"+
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
"
|
|
299
|
-
"
|
|
300
|
-
|
|
301
|
-
@
|
|
302
|
-
|
|
303
|
-
@resources.map{ |resource| " " + resource.inspect }.join( "\n" )+"\n"+
|
|
304
|
-
"Area:\n"+
|
|
305
|
-
@areas.map{ |area| " #{ area }" }.join( "\n" )+"\n"
|
|
306
|
-
RCAP.format_lines_for_inspect( 'INFO', info_inspect )
|
|
281
|
+
info_inspect = "Language: #{ @language }\n"\
|
|
282
|
+
"Categories: #{ @categories.to_s_for_cap }\n"\
|
|
283
|
+
"Event: #{ @event }\n"\
|
|
284
|
+
"Urgency: #{ @urgency }\n"\
|
|
285
|
+
"Severity: #{ @severity }\n"\
|
|
286
|
+
"Certainty: #{ @certainty }\n"\
|
|
287
|
+
"Audience: #{ @audience }\n"\
|
|
288
|
+
"Event Codes: #{ @event_codes.inspect }\n"\
|
|
289
|
+
"Effective: #{ @effective }\n"\
|
|
290
|
+
"Onset: #{ @onset }\n"\
|
|
291
|
+
"Expires: #{ @expires }\n"\
|
|
292
|
+
"Sender Name: #{ @sender_name }\n"\
|
|
293
|
+
"Headline: #{ @headline }\n"\
|
|
294
|
+
"Description:\n" + @description.to_s.lines.map { |line| ' ' + line }.join("\n") + "\n"\
|
|
295
|
+
"Instruction: #{ @instruction }\n"\
|
|
296
|
+
"Web: #{ @web }\n"\
|
|
297
|
+
"Contact: #{ @contact }\n"\
|
|
298
|
+
"Parameters:\n" + @parameters.map { |parameter| ' ' + parameter.inspect }.join("\n") + "\n"\
|
|
299
|
+
"Resources:\n" + @resources.map { |resource| ' ' + resource.inspect }.join("\n") + "\n"\
|
|
300
|
+
"Area:\n" + @areas.map { |area| " #{ area }" }.join("\n") + "\n"
|
|
301
|
+
RCAP.format_lines_for_inspect('INFO', info_inspect)
|
|
307
302
|
end
|
|
308
303
|
|
|
309
304
|
# Returns a string representation of the event of the form
|
|
@@ -337,78 +332,78 @@ module RCAP
|
|
|
337
332
|
|
|
338
333
|
# @return [Hash]
|
|
339
334
|
def to_yaml_data
|
|
340
|
-
parameter_to_hash = lambda{ |hash, parameter| hash.merge(
|
|
341
|
-
|
|
342
|
-
RCAP.attribute_values_to_hash(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
335
|
+
parameter_to_hash = lambda { |hash, parameter| hash.merge(parameter.name => parameter.value) }
|
|
336
|
+
|
|
337
|
+
RCAP.attribute_values_to_hash([LANGUAGE_YAML, @language],
|
|
338
|
+
[CATEGORIES_YAML, @categories],
|
|
339
|
+
[EVENT_YAML, @event],
|
|
340
|
+
[URGENCY_YAML, @urgency],
|
|
341
|
+
[SEVERITY_YAML, @severity],
|
|
342
|
+
[CERTAINTY_YAML, @certainty],
|
|
343
|
+
[AUDIENCE_YAML, @audience],
|
|
344
|
+
[EFFECTIVE_YAML, @effective],
|
|
345
|
+
[ONSET_YAML, @onset],
|
|
346
|
+
[EXPIRES_YAML, @expires],
|
|
347
|
+
[SENDER_NAME_YAML, @sender_name],
|
|
348
|
+
[HEADLINE_YAML, @headline],
|
|
349
|
+
[DESCRIPTION_YAML, @description],
|
|
350
|
+
[INSTRUCTION_YAML, @instruction],
|
|
351
|
+
[WEB_YAML, @web],
|
|
352
|
+
[CONTACT_YAML, @contact],
|
|
353
|
+
[EVENT_CODES_YAML, @event_codes.inject({}, ¶meter_to_hash)],
|
|
354
|
+
[PARAMETERS_YAML, @parameters.inject({}, ¶meter_to_hash)],
|
|
355
|
+
[RESOURCES_YAML, @resources.map(&:to_yaml_data)],
|
|
356
|
+
[AREAS_YAML, @areas.map(&:to_yaml_data)])
|
|
362
357
|
end
|
|
363
358
|
|
|
364
359
|
# @return [String]
|
|
365
|
-
def to_yaml(
|
|
366
|
-
|
|
360
|
+
def to_yaml(options = {})
|
|
361
|
+
to_yaml_data.to_yaml(options)
|
|
367
362
|
end
|
|
368
363
|
|
|
369
364
|
# @param [Hash] info_yaml_data
|
|
370
365
|
# @return [Info]
|
|
371
|
-
def self.from_yaml_data(
|
|
372
|
-
|
|
373
|
-
info.language = info_yaml_data [
|
|
374
|
-
Array(
|
|
366
|
+
def self.from_yaml_data(info_yaml_data)
|
|
367
|
+
new do |info|
|
|
368
|
+
info.language = info_yaml_data [LANGUAGE_YAML]
|
|
369
|
+
Array(info_yaml_data [CATEGORIES_YAML]).each do |category|
|
|
375
370
|
info.categories << category
|
|
376
371
|
end
|
|
377
|
-
info.event = RCAP.strip_if_given(
|
|
378
|
-
info.urgency = RCAP.strip_if_given(
|
|
379
|
-
info.severity = RCAP.strip_if_given(
|
|
380
|
-
info.certainty = RCAP.strip_if_given(
|
|
381
|
-
info.audience = RCAP.strip_if_given(
|
|
382
|
-
info.effective = RCAP.parse_datetime(
|
|
383
|
-
info.onset = RCAP.parse_datetime(
|
|
384
|
-
info.expires = RCAP.parse_datetime(
|
|
385
|
-
info.sender_name = RCAP.strip_if_given(
|
|
386
|
-
info.headline = RCAP.strip_if_given(
|
|
387
|
-
info.description = RCAP.strip_if_given(
|
|
388
|
-
info.instruction = RCAP.strip_if_given(
|
|
389
|
-
info.web = RCAP.strip_if_given(
|
|
390
|
-
info.contact = RCAP.strip_if_given(
|
|
391
|
-
|
|
392
|
-
Array(
|
|
372
|
+
info.event = RCAP.strip_if_given(info_yaml_data [EVENT_YAML])
|
|
373
|
+
info.urgency = RCAP.strip_if_given(info_yaml_data [URGENCY_YAML])
|
|
374
|
+
info.severity = RCAP.strip_if_given(info_yaml_data [SEVERITY_YAML])
|
|
375
|
+
info.certainty = RCAP.strip_if_given(info_yaml_data [CERTAINTY_YAML])
|
|
376
|
+
info.audience = RCAP.strip_if_given(info_yaml_data [AUDIENCE_YAML])
|
|
377
|
+
info.effective = RCAP.parse_datetime(info_yaml_data[EFFECTIVE_YAML])
|
|
378
|
+
info.onset = RCAP.parse_datetime(info_yaml_data[ONSET_YAML])
|
|
379
|
+
info.expires = RCAP.parse_datetime(info_yaml_data[EXPIRES_YAML])
|
|
380
|
+
info.sender_name = RCAP.strip_if_given(info_yaml_data [SENDER_NAME_YAML])
|
|
381
|
+
info.headline = RCAP.strip_if_given(info_yaml_data [HEADLINE_YAML])
|
|
382
|
+
info.description = RCAP.strip_if_given(info_yaml_data [DESCRIPTION_YAML])
|
|
383
|
+
info.instruction = RCAP.strip_if_given(info_yaml_data [INSTRUCTION_YAML])
|
|
384
|
+
info.web = RCAP.strip_if_given(info_yaml_data [WEB_YAML])
|
|
385
|
+
info.contact = RCAP.strip_if_given(info_yaml_data [CONTACT_YAML])
|
|
386
|
+
|
|
387
|
+
Array(info_yaml_data [EVENT_CODES_YAML]).each do |name, value|
|
|
393
388
|
info.add_event_code do |event_code|
|
|
394
|
-
event_code.name = RCAP.strip_if_given(
|
|
395
|
-
event_code.value = RCAP.strip_if_given(
|
|
389
|
+
event_code.name = RCAP.strip_if_given(name)
|
|
390
|
+
event_code.value = RCAP.strip_if_given(value)
|
|
396
391
|
end
|
|
397
392
|
end
|
|
398
393
|
|
|
399
|
-
Array(
|
|
394
|
+
Array(info_yaml_data [PARAMETERS_YAML]).each do |name, value|
|
|
400
395
|
info.add_parameter do |parameter|
|
|
401
|
-
parameter.name = RCAP.strip_if_given(
|
|
402
|
-
parameter.value = RCAP.strip_if_given(
|
|
396
|
+
parameter.name = RCAP.strip_if_given(name)
|
|
397
|
+
parameter.value = RCAP.strip_if_given(value)
|
|
403
398
|
end
|
|
404
399
|
end
|
|
405
400
|
|
|
406
|
-
Array(
|
|
407
|
-
info.resources << info.resource_class.from_yaml_data(
|
|
401
|
+
Array(info_yaml_data [RESOURCES_YAML]).each do |resource_yaml_data|
|
|
402
|
+
info.resources << info.resource_class.from_yaml_data(resource_yaml_data)
|
|
408
403
|
end
|
|
409
404
|
|
|
410
|
-
Array(
|
|
411
|
-
info.areas << info.area_class.from_yaml_data(
|
|
405
|
+
Array(info_yaml_data [AREAS_YAML]).each do |area_yaml_data|
|
|
406
|
+
info.areas << info.area_class.from_yaml_data(area_yaml_data)
|
|
412
407
|
end
|
|
413
408
|
end
|
|
414
409
|
end
|
|
@@ -436,65 +431,65 @@ module RCAP
|
|
|
436
431
|
|
|
437
432
|
# @return [Hash]
|
|
438
433
|
def to_h
|
|
439
|
-
RCAP.attribute_values_to_hash(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
434
|
+
RCAP.attribute_values_to_hash([LANGUAGE_KEY, @language],
|
|
435
|
+
[CATEGORIES_KEY, @categories],
|
|
436
|
+
[EVENT_KEY, @event],
|
|
437
|
+
[URGENCY_KEY, @urgency],
|
|
438
|
+
[SEVERITY_KEY, @severity],
|
|
439
|
+
[CERTAINTY_KEY, @certainty],
|
|
440
|
+
[AUDIENCE_KEY, @audience],
|
|
441
|
+
[EFFECTIVE_KEY, RCAP.to_s_for_cap(@effective)],
|
|
442
|
+
[ONSET_KEY, RCAP.to_s_for_cap(@onset)],
|
|
443
|
+
[EXPIRES_KEY, RCAP.to_s_for_cap(@expires)],
|
|
444
|
+
[SENDER_NAME_KEY, @sender_name],
|
|
445
|
+
[HEADLINE_KEY, @headline],
|
|
446
|
+
[DESCRIPTION_KEY, @description],
|
|
447
|
+
[INSTRUCTION_KEY, @instruction],
|
|
448
|
+
[WEB_KEY, @web],
|
|
449
|
+
[CONTACT_KEY, @contact],
|
|
450
|
+
[RESOURCES_KEY, @resources.map { |resource| resource.to_h }],
|
|
451
|
+
[EVENT_CODES_KEY, @event_codes.map { |event_code| event_code.to_h }],
|
|
452
|
+
[PARAMETERS_KEY, @parameters.map { |parameter| parameter.to_h }],
|
|
453
|
+
[AREAS_KEY, @areas.map { |area| area.to_h }])
|
|
459
454
|
end
|
|
460
455
|
|
|
461
456
|
# @param [Hash] info_hash
|
|
462
457
|
# @return [Info]
|
|
463
|
-
def self.from_h(
|
|
464
|
-
|
|
465
|
-
info.language = info_hash[
|
|
466
|
-
Array(
|
|
467
|
-
info.categories << RCAP.strip_if_given(
|
|
458
|
+
def self.from_h(info_hash)
|
|
459
|
+
new do |info|
|
|
460
|
+
info.language = info_hash[LANGUAGE_KEY]
|
|
461
|
+
Array(info_hash[CATEGORIES_KEY]).each do |category|
|
|
462
|
+
info.categories << RCAP.strip_if_given(category)
|
|
468
463
|
end
|
|
469
|
-
info.event = RCAP.strip_if_given(
|
|
470
|
-
info.urgency = RCAP.strip_if_given(
|
|
471
|
-
info.severity = RCAP.strip_if_given(
|
|
472
|
-
info.certainty = RCAP.strip_if_given(
|
|
473
|
-
info.audience = RCAP.strip_if_given(
|
|
474
|
-
info.effective = RCAP.parse_datetime(
|
|
475
|
-
info.onset = RCAP.parse_datetime(
|
|
476
|
-
info.expires = RCAP.parse_datetime(
|
|
477
|
-
info.sender_name = RCAP.strip_if_given(
|
|
478
|
-
info.headline = RCAP.strip_if_given(
|
|
479
|
-
info.description = RCAP.strip_if_given(
|
|
480
|
-
info.instruction = RCAP.strip_if_given(
|
|
481
|
-
info.web = RCAP.strip_if_given(
|
|
482
|
-
info.contact = RCAP.strip_if_given(
|
|
483
|
-
|
|
484
|
-
Array(
|
|
485
|
-
info.resources << info.resource_class.from_h(
|
|
464
|
+
info.event = RCAP.strip_if_given(info_hash[EVENT_KEY])
|
|
465
|
+
info.urgency = RCAP.strip_if_given(info_hash[URGENCY_KEY])
|
|
466
|
+
info.severity = RCAP.strip_if_given(info_hash[SEVERITY_KEY])
|
|
467
|
+
info.certainty = RCAP.strip_if_given(info_hash[CERTAINTY_KEY])
|
|
468
|
+
info.audience = RCAP.strip_if_given(info_hash[AUDIENCE_KEY])
|
|
469
|
+
info.effective = RCAP.parse_datetime(info_hash[EFFECTIVE_KEY])
|
|
470
|
+
info.onset = RCAP.parse_datetime(info_hash[ONSET_KEY])
|
|
471
|
+
info.expires = RCAP.parse_datetime(info_hash[EXPIRES_KEY])
|
|
472
|
+
info.sender_name = RCAP.strip_if_given(info_hash[SENDER_NAME_KEY])
|
|
473
|
+
info.headline = RCAP.strip_if_given(info_hash[HEADLINE_KEY])
|
|
474
|
+
info.description = RCAP.strip_if_given(info_hash[DESCRIPTION_KEY])
|
|
475
|
+
info.instruction = RCAP.strip_if_given(info_hash[INSTRUCTION_KEY])
|
|
476
|
+
info.web = RCAP.strip_if_given(info_hash[WEB_KEY])
|
|
477
|
+
info.contact = RCAP.strip_if_given(info_hash[CONTACT_KEY])
|
|
478
|
+
|
|
479
|
+
Array(info_hash[RESOURCES_KEY]).each do |resource_hash|
|
|
480
|
+
info.resources << info.resource_class.from_h(resource_hash)
|
|
486
481
|
end
|
|
487
482
|
|
|
488
|
-
Array(
|
|
489
|
-
info.event_codes << info.event_code_class.from_h(
|
|
483
|
+
Array(info_hash[EVENT_CODES_KEY]).each do |event_code_hash|
|
|
484
|
+
info.event_codes << info.event_code_class.from_h(event_code_hash)
|
|
490
485
|
end
|
|
491
486
|
|
|
492
|
-
Array(
|
|
493
|
-
info.parameters << info.parameter_class.from_h(
|
|
487
|
+
Array(info_hash[PARAMETERS_KEY]).each do |parameter_hash|
|
|
488
|
+
info.parameters << info.parameter_class.from_h(parameter_hash)
|
|
494
489
|
end
|
|
495
490
|
|
|
496
|
-
Array(
|
|
497
|
-
|
|
491
|
+
Array(info_hash[AREAS_KEY]).each do |area_hash|
|
|
492
|
+
info.areas << info.area_class.from_h(area_hash)
|
|
498
493
|
end
|
|
499
494
|
end
|
|
500
495
|
end
|