rcap 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -1
- data/README.rdoc +2 -2
- data/lib/config.rb +2 -0
- data/lib/rcap.rb +1 -3
- data/lib/rcap/cap_1_0/alert.rb +33 -33
- data/lib/rcap/cap_1_0/area.rb +11 -11
- data/lib/rcap/cap_1_0/circle.rb +9 -7
- data/lib/rcap/cap_1_0/info.rb +20 -22
- data/lib/rcap/cap_1_0/point.rb +1 -1
- data/lib/rcap/cap_1_0/resource.rb +4 -4
- data/lib/rcap/cap_1_1/alert.rb +60 -60
- data/lib/rcap/cap_1_1/area.rb +6 -6
- data/lib/rcap/cap_1_1/circle.rb +4 -4
- data/lib/rcap/cap_1_1/info.rb +63 -63
- data/lib/rcap/cap_1_1/parameter.rb +1 -1
- data/lib/rcap/cap_1_1/point.rb +1 -1
- data/lib/rcap/cap_1_1/resource.rb +6 -7
- data/lib/rcap/cap_1_2/alert.rb +60 -60
- data/lib/rcap/cap_1_2/area.rb +5 -5
- data/lib/rcap/cap_1_2/circle.rb +5 -3
- data/lib/rcap/cap_1_2/info.rb +61 -63
- data/lib/rcap/cap_1_2/parameter.rb +1 -1
- data/lib/rcap/utilities.rb +6 -6
- data/lib/rcap/version.rb +1 -1
- data/spec/cap_1_0/alert_spec.rb +1 -1
- data/spec/cap_1_1/alert_spec.rb +1 -1
- data/spec/cap_1_2/alert_spec.rb +1 -1
- metadata +3 -2
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
The Common Alerting Protocol is a lightweight standard to facilitate the distribution of alerting data. RCAP is an implementation of the CAP document protocol in Ruby. It allows for the creation of RCAP messages from Ruby applications and the parsing of external messages.
|
6
6
|
|
7
|
-
RCAP currently supports CAP 1.1 and 1.2.
|
7
|
+
RCAP currently supports CAP 1.0, 1.1 and 1.2.
|
8
8
|
|
9
9
|
== Version
|
10
10
|
|
11
|
-
1.
|
11
|
+
1.1.1
|
12
12
|
|
13
13
|
== Dependencies
|
14
14
|
|
data/lib/config.rb
ADDED
data/lib/rcap.rb
CHANGED
data/lib/rcap/cap_1_0/alert.rb
CHANGED
@@ -109,7 +109,7 @@ module RCAP
|
|
109
109
|
validates_collection_of( :infos )
|
110
110
|
|
111
111
|
def initialize( attributes = {})
|
112
|
-
@identifier = attributes[ :identifier ]
|
112
|
+
@identifier = attributes[ :identifier ] || RCAP.generate_identifier
|
113
113
|
@sender = attributes[ :sender ]
|
114
114
|
@sent = attributes[ :sent ]
|
115
115
|
@status = attributes[ :status ]
|
@@ -189,24 +189,24 @@ module RCAP
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def inspect # :nodoc:
|
192
|
-
alert_inspect = "CAP Version: #{ CAP_VERSION }
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
192
|
+
alert_inspect = [ "CAP Version: #{ CAP_VERSION }",
|
193
|
+
"Identifier: #{ self.identifier }",
|
194
|
+
"Sender: #{ self.sender }",
|
195
|
+
"Sent: #{ self.sent }",
|
196
|
+
"Status: #{ self.status }",
|
197
|
+
"Message Type: #{ self.msg_type }",
|
198
|
+
"Password: #{ self.password }",
|
199
|
+
"Source: #{ self.source }",
|
200
|
+
"Scope: #{ self.scope }",
|
201
|
+
"Restriction: #{ self.restriction }",
|
202
|
+
"Addresses: #{ self.addresses.to_s_for_cap }",
|
203
|
+
"Codes:",
|
204
|
+
self.codes.map{ |code| " " + code }.join("\n")+"",
|
205
|
+
"Note: #{ self.note }",
|
206
|
+
"References: #{ self.references.join( ' ' )}",
|
207
|
+
"Incidents: #{ self.incidents.join( ' ')}",
|
208
|
+
"Information:",
|
209
|
+
self.infos.map{ |info| " " + info.to_s }.join( "\n" )].join("\n")
|
210
210
|
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
211
211
|
end
|
212
212
|
|
@@ -219,20 +219,20 @@ module RCAP
|
|
219
219
|
|
220
220
|
def self.from_xml_element( alert_xml_element ) # :nodoc:
|
221
221
|
self.new( :identifier => RCAP.xpath_text( alert_xml_element, IDENTIFIER_XPATH, Alert::XMLNS ),
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
222
|
+
:sender => RCAP.xpath_text( alert_xml_element, SENDER_XPATH, Alert::XMLNS ),
|
223
|
+
:sent => (( sent = RCAP.xpath_first( alert_xml_element, SENT_XPATH, Alert::XMLNS )) ? DateTime.parse( sent.text ) : nil ),
|
224
|
+
:status => RCAP.xpath_text( alert_xml_element, STATUS_XPATH, Alert::XMLNS ),
|
225
|
+
:msg_type => RCAP.xpath_text( alert_xml_element, MSG_TYPE_XPATH, Alert::XMLNS ),
|
226
|
+
:password => RCAP.xpath_text( alert_xml_element, PASSWORD_XPATH, Alert::XMLNS ),
|
227
|
+
:source => RCAP.xpath_text( alert_xml_element, SOURCE_XPATH, Alert::XMLNS ),
|
228
|
+
:scope => RCAP.xpath_text( alert_xml_element, SCOPE_XPATH, Alert::XMLNS ),
|
229
|
+
:restriction => RCAP.xpath_text( alert_xml_element, RESTRICTION_XPATH, Alert::XMLNS ),
|
230
|
+
:addresses => (( address = RCAP.xpath_text( alert_xml_element, ADDRESSES_XPATH, Alert::XMLNS )) ? address.unpack_cap_list : nil ),
|
231
|
+
:codes => RCAP.xpath_match( alert_xml_element, CODE_XPATH, Alert::XMLNS ).map{ |element| element.text },
|
232
|
+
:note => RCAP.xpath_text( alert_xml_element, NOTE_XPATH, Alert::XMLNS ),
|
233
|
+
:references => (( references = RCAP.xpath_text( alert_xml_element, REFERENCES_XPATH, Alert::XMLNS )) ? references.split( ' ' ) : nil ),
|
234
|
+
:incidents => (( incidents = RCAP.xpath_text( alert_xml_element, INCIDENTS_XPATH, Alert::XMLNS )) ? incidents.split( ' ' ) : nil ),
|
235
|
+
:infos => RCAP.xpath_match( alert_xml_element, Info::XPATH, Alert::XMLNS ).map{ |element| Info.from_xml_element( element )})
|
236
236
|
end
|
237
237
|
|
238
238
|
def self.from_xml_document( xml_document ) # :nodoc:
|
data/lib/rcap/cap_1_0/area.rb
CHANGED
@@ -111,11 +111,11 @@ module RCAP
|
|
111
111
|
|
112
112
|
def self.from_xml_element( area_xml_element ) # :nodoc:
|
113
113
|
self.new( :area_desc => RCAP.xpath_text( area_xml_element, AREA_DESC_XPATH, Alert::XMLNS ),
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
:altitude => (( alt = RCAP.xpath_text( area_xml_element, ALTITUDE_XPATH, Alert::XMLNS )) ? alt.to_f : nil ),
|
115
|
+
:ceiling => (( ceil = RCAP.xpath_text( area_xml_element, CEILING_XPATH, Alert::XMLNS )) ? ceil.to_f : nil ),
|
116
|
+
:circles => RCAP.xpath_match( area_xml_element, Circle::XPATH, Alert::XMLNS ).map{ |circle_element| Circle.from_xml_element( circle_element )},
|
117
|
+
:geocodes => RCAP.xpath_match( area_xml_element, Geocode::XPATH, Alert::XMLNS ).map{ |geocode_element| Geocode.from_xml_element( geocode_element )},
|
118
|
+
:polygons => RCAP.xpath_match( area_xml_element, Polygon::XPATH, Alert::XMLNS ).map{ |polygon_element| Polygon.from_xml_element( polygon_element )})
|
119
119
|
end
|
120
120
|
|
121
121
|
AREA_DESC_YAML = 'Area Description' # :nodoc:
|
@@ -130,12 +130,12 @@ module RCAP
|
|
130
130
|
def circles_yaml.to_yaml_style; :inline; end
|
131
131
|
|
132
132
|
RCAP.attribute_values_to_hash(
|
133
|
-
[ AREA_DESC_YAML,
|
134
|
-
[ ALTITUDE_YAML,
|
135
|
-
[ CEILING_YAML,
|
136
|
-
[ CIRCLES_YAML,
|
137
|
-
[ GEOCODES_YAML,
|
138
|
-
[ POLYGONS_YAML,
|
133
|
+
[ AREA_DESC_YAML, self.area_desc ],
|
134
|
+
[ ALTITUDE_YAML, self.altitude ],
|
135
|
+
[ CEILING_YAML, self.ceiling ],
|
136
|
+
[ CIRCLES_YAML, circles_yaml ],
|
137
|
+
[ GEOCODES_YAML, self.geocodes.inject({}){|h,geocode| h.merge( geocode.name => geocode.value )}],
|
138
|
+
[ POLYGONS_YAML, self.polygons ]
|
139
139
|
).to_yaml( options )
|
140
140
|
end
|
141
141
|
|
data/lib/rcap/cap_1_0/circle.rb
CHANGED
@@ -50,8 +50,8 @@ module RCAP
|
|
50
50
|
def self.from_xml_element( circle_xml_element ) # :nodoc:
|
51
51
|
lattitude, longitude, radius = self.parse_circle_string( circle_xml_element.text )
|
52
52
|
circle = self.new( :lattitude => lattitude,
|
53
|
-
|
54
|
-
|
53
|
+
:longitude => longitude,
|
54
|
+
:radius => radius )
|
55
55
|
end
|
56
56
|
|
57
57
|
# Two circles are equivalent if their lattitude, longitude and radius are equal.
|
@@ -64,17 +64,19 @@ module RCAP
|
|
64
64
|
self.new( :lattitude => lattitude, :longitude => longitude, :radius => radius )
|
65
65
|
end
|
66
66
|
|
67
|
-
RADIUS_KEY = 'radius'
|
67
|
+
RADIUS_KEY = 'radius' # :nodoc:
|
68
68
|
LATTITUDE_KEY = 'lattitude' # :nodoc:
|
69
69
|
LONGITUDE_KEY = 'longitude' # :nodoc:
|
70
70
|
def to_h # :nodoc:
|
71
|
-
RCAP.attribute_values_to_hash( [ RADIUS_KEY,
|
72
|
-
|
73
|
-
|
71
|
+
RCAP.attribute_values_to_hash( [ RADIUS_KEY, self.radius ],
|
72
|
+
[ LATTITUDE_KEY, self.lattitude ],
|
73
|
+
[ LONGITUDE_KEY, self.longitude ])
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.from_h( circle_hash ) # :nodoc:
|
77
|
-
self.new( :radius
|
77
|
+
self.new( :radius => circle_hash[ RADIUS_KEY ],
|
78
|
+
:lattitude => circle_hash[ LATTITUDE_KEY ],
|
79
|
+
:longitude => circle_hash[ LONGITUDE_KEY ])
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
data/lib/rcap/cap_1_0/info.rb
CHANGED
@@ -315,28 +315,26 @@ module RCAP
|
|
315
315
|
|
316
316
|
parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}
|
317
317
|
|
318
|
-
RCAP.attribute_values_to_hash(
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
[ AREAS_YAML, self.areas ]
|
339
|
-
).to_yaml( options )
|
318
|
+
RCAP.attribute_values_to_hash( [ LANGUAGE_YAML, self.language ],
|
319
|
+
[ CATEGORIES_YAML, categories_yaml ],
|
320
|
+
[ EVENT_YAML, self.event ],
|
321
|
+
[ URGENCY_YAML, self.urgency ],
|
322
|
+
[ SEVERITY_YAML, self.severity ],
|
323
|
+
[ CERTAINTY_YAML, self.certainty ],
|
324
|
+
[ AUDIENCE_YAML, self.audience ],
|
325
|
+
[ EFFECTIVE_YAML, self.effective ],
|
326
|
+
[ ONSET_YAML, self.onset ],
|
327
|
+
[ EXPIRES_YAML, self.expires ],
|
328
|
+
[ SENDER_NAME_YAML, self.sender_name ],
|
329
|
+
[ HEADLINE_YAML, self.headline ],
|
330
|
+
[ DESCRIPTION_YAML, self.description ],
|
331
|
+
[ INSTRUCTION_YAML, self.instruction ],
|
332
|
+
[ WEB_YAML, self.web ],
|
333
|
+
[ CONTACT_YAML, self.contact ],
|
334
|
+
[ EVENT_CODES_YAML, self.event_codes.inject({}, ¶meter_to_hash )],
|
335
|
+
[ PARAMETERS_YAML, self.parameters.inject({}, ¶meter_to_hash )],
|
336
|
+
[ RESOURCES_YAML, self.resources ],
|
337
|
+
[ AREAS_YAML, self.areas ]).to_yaml( options )
|
340
338
|
end
|
341
339
|
|
342
340
|
def self.from_yaml_data( info_yaml_data ) # :nodoc:
|
data/lib/rcap/cap_1_0/point.rb
CHANGED
@@ -72,10 +72,10 @@ module RCAP
|
|
72
72
|
|
73
73
|
def self.from_xml_element( resource_xml_element ) # :nodoc:
|
74
74
|
resource = self.new( :resource_desc => RCAP.xpath_text( resource_xml_element, RESOURCE_DESC_XPATH, Alert::XMLNS ),
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
:uri => RCAP.xpath_text( resource_xml_element, URI_XPATH, Alert::XMLNS ),
|
76
|
+
:mime_type => RCAP.xpath_text( resource_xml_element, MIME_TYPE_XPATH, Alert::XMLNS ),
|
77
|
+
:size => RCAP.xpath_text( resource_xml_element, SIZE_XPATH, Alert::XMLNS ),
|
78
|
+
:digest => RCAP.xpath_text( resource_xml_element, DIGEST_XPATH, Alert::XMLNS ))
|
79
79
|
end
|
80
80
|
|
81
81
|
RESOURCE_DESC_YAML = "Resource Description" # :nodoc:
|
data/lib/rcap/cap_1_1/alert.rb
CHANGED
@@ -107,7 +107,7 @@ module RCAP
|
|
107
107
|
validates_collection_of( :infos )
|
108
108
|
|
109
109
|
def initialize( attributes = {})
|
110
|
-
@identifier = attributes[ :identifier ]
|
110
|
+
@identifier = attributes[ :identifier ] || RCAP.generate_identifier
|
111
111
|
@sender = attributes[ :sender ]
|
112
112
|
@sent = attributes[ :sent ]
|
113
113
|
@status = attributes[ :status ]
|
@@ -185,23 +185,23 @@ module RCAP
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def inspect # :nodoc:
|
188
|
-
alert_inspect = "CAP Version: #{ CAP_VERSION }
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
188
|
+
alert_inspect = [ "CAP Version: #{ CAP_VERSION }",
|
189
|
+
"Identifier: #{ self.identifier }",
|
190
|
+
"Sender: #{ self.sender }",
|
191
|
+
"Sent: #{ self.sent }",
|
192
|
+
"Status: #{ self.status }",
|
193
|
+
"Message Type: #{ self.msg_type }",
|
194
|
+
"Source: #{ self.source }",
|
195
|
+
"Scope: #{ self.scope }",
|
196
|
+
"Restriction: #{ self.restriction }",
|
197
|
+
"Addresses: #{ self.addresses.to_s_for_cap }",
|
198
|
+
"Codes:",
|
199
|
+
self.codes.map{ |code| " " + code }.join("\n")+"",
|
200
|
+
"Note: #{ self.note }",
|
201
|
+
"References: #{ self.references.join( ' ' )}",
|
202
|
+
"Incidents: #{ self.incidents.join( ' ')}",
|
203
|
+
"Information:",
|
204
|
+
self.infos.map{ |info| " " + info.to_s }.join( "\n" )].join( "\n" )
|
205
205
|
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
206
206
|
end
|
207
207
|
|
@@ -214,19 +214,19 @@ module RCAP
|
|
214
214
|
|
215
215
|
def self.from_xml_element( alert_xml_element ) # :nodoc:
|
216
216
|
self.new( :identifier => RCAP.xpath_text( alert_xml_element, IDENTIFIER_XPATH, Alert::XMLNS ),
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
217
|
+
:sender => RCAP.xpath_text( alert_xml_element, SENDER_XPATH, Alert::XMLNS ),
|
218
|
+
:sent => (( sent = RCAP.xpath_first( alert_xml_element, SENT_XPATH, Alert::XMLNS )) ? DateTime.parse( sent.text ) : nil ),
|
219
|
+
:status => RCAP.xpath_text( alert_xml_element, STATUS_XPATH, Alert::XMLNS ),
|
220
|
+
:msg_type => RCAP.xpath_text( alert_xml_element, MSG_TYPE_XPATH, Alert::XMLNS ),
|
221
|
+
:source => RCAP.xpath_text( alert_xml_element, SOURCE_XPATH, Alert::XMLNS ),
|
222
|
+
:scope => RCAP.xpath_text( alert_xml_element, SCOPE_XPATH, Alert::XMLNS ),
|
223
|
+
:restriction => RCAP.xpath_text( alert_xml_element, RESTRICTION_XPATH, Alert::XMLNS ),
|
224
|
+
:addresses => (( address = RCAP.xpath_text( alert_xml_element, ADDRESSES_XPATH, Alert::XMLNS )) ? address.unpack_cap_list : nil ),
|
225
|
+
:codes => RCAP.xpath_match( alert_xml_element, CODE_XPATH, Alert::XMLNS ).map{ |element| element.text },
|
226
|
+
:note => RCAP.xpath_text( alert_xml_element, NOTE_XPATH, Alert::XMLNS ),
|
227
|
+
:references => (( references = RCAP.xpath_text( alert_xml_element, REFERENCES_XPATH, Alert::XMLNS )) ? references.split( ' ' ) : nil ),
|
228
|
+
:incidents => (( incidents = RCAP.xpath_text( alert_xml_element, INCIDENTS_XPATH, Alert::XMLNS )) ? incidents.split( ' ' ) : nil ),
|
229
|
+
:infos => RCAP.xpath_match( alert_xml_element, Info::XPATH, Alert::XMLNS ).map{ |element| Info.from_xml_element( element )})
|
230
230
|
end
|
231
231
|
|
232
232
|
def self.from_xml_document( xml_document ) # :nodoc:
|
@@ -238,21 +238,21 @@ module RCAP
|
|
238
238
|
self.from_xml_document( REXML::Document.new( xml ))
|
239
239
|
end
|
240
240
|
|
241
|
-
CAP_VERSION_YAML = "CAP Version"
|
242
|
-
IDENTIFIER_YAML = "Identifier"
|
243
|
-
SENDER_YAML = "Sender"
|
244
|
-
SENT_YAML = "Sent"
|
245
|
-
STATUS_YAML = "Status"
|
246
|
-
MSG_TYPE_YAML = "Message Type"
|
247
|
-
SOURCE_YAML = "Source"
|
248
|
-
SCOPE_YAML = "Scope"
|
249
|
-
RESTRICTION_YAML = "Restriction"
|
250
|
-
ADDRESSES_YAML = "Addresses"
|
251
|
-
CODES_YAML = "Codes"
|
252
|
-
NOTE_YAML = "Note"
|
253
|
-
REFERENCES_YAML = "References"
|
254
|
-
INCIDENTS_YAML = "Incidents"
|
255
|
-
INFOS_YAML = "Information"
|
241
|
+
CAP_VERSION_YAML = "CAP Version" # :nodoc:
|
242
|
+
IDENTIFIER_YAML = "Identifier" # :nodoc:
|
243
|
+
SENDER_YAML = "Sender" # :nodoc:
|
244
|
+
SENT_YAML = "Sent" # :nodoc:
|
245
|
+
STATUS_YAML = "Status" # :nodoc:
|
246
|
+
MSG_TYPE_YAML = "Message Type" # :nodoc:
|
247
|
+
SOURCE_YAML = "Source" # :nodoc:
|
248
|
+
SCOPE_YAML = "Scope" # :nodoc:
|
249
|
+
RESTRICTION_YAML = "Restriction" # :nodoc:
|
250
|
+
ADDRESSES_YAML = "Addresses" # :nodoc:
|
251
|
+
CODES_YAML = "Codes" # :nodoc:
|
252
|
+
NOTE_YAML = "Note" # :nodoc:
|
253
|
+
REFERENCES_YAML = "References" # :nodoc:
|
254
|
+
INCIDENTS_YAML = "Incidents" # :nodoc:
|
255
|
+
INFOS_YAML = "Information" # :nodoc:
|
256
256
|
|
257
257
|
# Returns a string containing the YAML representation of the alert.
|
258
258
|
def to_yaml( options = {} )
|
@@ -318,20 +318,20 @@ module RCAP
|
|
318
318
|
# Returns a Hash representation of an Alert object
|
319
319
|
def to_h
|
320
320
|
RCAP.attribute_values_to_hash( [ CAP_VERSION_KEY, CAP_VERSION ],
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
321
|
+
[ IDENTIFIER_KEY, self.identifier ],
|
322
|
+
[ SENDER_KEY, self.sender ],
|
323
|
+
[ SENT_KEY, RCAP.to_s_for_cap( self.sent )],
|
324
|
+
[ STATUS_KEY, self.status ],
|
325
|
+
[ MSG_TYPE_KEY, self.msg_type ],
|
326
|
+
[ SOURCE_KEY, self.source ],
|
327
|
+
[ SCOPE_KEY, self.scope ],
|
328
|
+
[ RESTRICTION_KEY, self.restriction ],
|
329
|
+
[ ADDRESSES_KEY, self.addresses ],
|
330
|
+
[ CODES_KEY, self.codes ],
|
331
|
+
[ NOTE_KEY, self.note ],
|
332
|
+
[ REFERENCES_KEY, self.references ],
|
333
|
+
[ INCIDENTS_KEY, self.incidents ],
|
334
|
+
[ INFOS_KEY, self.infos.map{ |info| info.to_h }])
|
335
335
|
end
|
336
336
|
|
337
337
|
# Initialises an Alert object from a Hash produced by Alert#to_h
|
data/lib/rcap/cap_1_1/area.rb
CHANGED
@@ -130,12 +130,12 @@ module RCAP
|
|
130
130
|
def circles_yaml.to_yaml_style; :inline; end
|
131
131
|
|
132
132
|
RCAP.attribute_values_to_hash(
|
133
|
-
[ AREA_DESC_YAML,
|
134
|
-
[ ALTITUDE_YAML,
|
135
|
-
[ CEILING_YAML,
|
136
|
-
[ CIRCLES_YAML,
|
137
|
-
[ GEOCODES_YAML,
|
138
|
-
[ POLYGONS_YAML,
|
133
|
+
[ AREA_DESC_YAML, self.area_desc ],
|
134
|
+
[ ALTITUDE_YAML, self.altitude ],
|
135
|
+
[ CEILING_YAML, self.ceiling ],
|
136
|
+
[ CIRCLES_YAML, circles_yaml ],
|
137
|
+
[ GEOCODES_YAML, self.geocodes.inject({}){|h,geocode| h.merge( geocode.name => geocode.value )}],
|
138
|
+
[ POLYGONS_YAML, self.polygons ]
|
139
139
|
).to_yaml( options )
|
140
140
|
end
|
141
141
|
|
data/lib/rcap/cap_1_1/circle.rb
CHANGED
@@ -50,8 +50,8 @@ module RCAP
|
|
50
50
|
def self.from_xml_element( circle_xml_element ) # :nodoc:
|
51
51
|
lattitude, longitude, radius = self.parse_circle_string( circle_xml_element.text )
|
52
52
|
circle = self.new( :lattitude => lattitude,
|
53
|
-
|
54
|
-
|
53
|
+
:longitude => longitude,
|
54
|
+
:radius => radius )
|
55
55
|
end
|
56
56
|
|
57
57
|
# Two circles are equivalent if their lattitude, longitude and radius are equal.
|
@@ -69,8 +69,8 @@ module RCAP
|
|
69
69
|
LONGITUDE_KEY = 'longitude' # :nodoc:
|
70
70
|
def to_h # :nodoc:
|
71
71
|
RCAP.attribute_values_to_hash( [ RADIUS_KEY, self.radius ],
|
72
|
-
|
73
|
-
|
72
|
+
[ LATTITUDE_KEY, self.lattitude ],
|
73
|
+
[ LONGITUDE_KEY, self.longitude ])
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.from_h( circle_hash ) # :nodoc:
|
data/lib/rcap/cap_1_1/info.rb
CHANGED
@@ -344,28 +344,27 @@ module RCAP
|
|
344
344
|
parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}
|
345
345
|
|
346
346
|
RCAP.attribute_values_to_hash(
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
).to_yaml( options )
|
347
|
+
[ LANGUAGE_YAML, self.language ],
|
348
|
+
[ CATEGORIES_YAML, categories_yaml ],
|
349
|
+
[ EVENT_YAML, self.event ],
|
350
|
+
[ RESPONSE_TYPES_YAML, response_types_yaml ],
|
351
|
+
[ URGENCY_YAML, self.urgency ],
|
352
|
+
[ SEVERITY_YAML, self.severity ],
|
353
|
+
[ CERTAINTY_YAML, self.certainty ],
|
354
|
+
[ AUDIENCE_YAML, self.audience ],
|
355
|
+
[ EFFECTIVE_YAML, self.effective ],
|
356
|
+
[ ONSET_YAML, self.onset ],
|
357
|
+
[ EXPIRES_YAML, self.expires ],
|
358
|
+
[ SENDER_NAME_YAML, self.sender_name ],
|
359
|
+
[ HEADLINE_YAML, self.headline ],
|
360
|
+
[ DESCRIPTION_YAML, self.description ],
|
361
|
+
[ INSTRUCTION_YAML, self.instruction ],
|
362
|
+
[ WEB_YAML, self.web ],
|
363
|
+
[ CONTACT_YAML, self.contact ],
|
364
|
+
[ EVENT_CODES_YAML, self.event_codes.inject({}, ¶meter_to_hash )],
|
365
|
+
[ PARAMETERS_YAML, self.parameters.inject({}, ¶meter_to_hash )],
|
366
|
+
[ RESOURCES_YAML, self.resources ],
|
367
|
+
[ AREAS_YAML, self.areas ]).to_yaml( options )
|
369
368
|
end
|
370
369
|
|
371
370
|
def self.from_yaml_data( info_yaml_data ) # :nodoc:
|
@@ -417,51 +416,52 @@ module RCAP
|
|
417
416
|
AREAS_KEY = 'areas' # :nodoc:
|
418
417
|
|
419
418
|
def to_h # :nodoc:
|
420
|
-
RCAP.attribute_values_to_hash(
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
419
|
+
RCAP.attribute_values_to_hash(
|
420
|
+
[ LANGUAGE_KEY, self.language ],
|
421
|
+
[ CATEGORIES_KEY, self.categories ],
|
422
|
+
[ EVENT_KEY, self.event ],
|
423
|
+
[ RESPONSE_TYPES_KEY, self.response_types ],
|
424
|
+
[ URGENCY_KEY, self.urgency ],
|
425
|
+
[ SEVERITY_KEY, self.severity ],
|
426
|
+
[ CERTAINTY_KEY, self.certainty ],
|
427
|
+
[ AUDIENCE_KEY, self.audience ],
|
428
|
+
[ EFFECTIVE_KEY, RCAP.to_s_for_cap( self.effective )],
|
429
|
+
[ ONSET_KEY, RCAP.to_s_for_cap( self.onset )],
|
430
|
+
[ EXPIRES_KEY, RCAP.to_s_for_cap( self.expires )],
|
431
|
+
[ SENDER_NAME_KEY, self.sender_name ],
|
432
|
+
[ HEADLINE_KEY, self.headline ],
|
433
|
+
[ DESCRIPTION_KEY, self.description ],
|
434
|
+
[ INSTRUCTION_KEY, self.instruction ],
|
435
|
+
[ WEB_KEY, self.web ],
|
436
|
+
[ CONTACT_KEY, self.contact ],
|
437
|
+
[ RESOURCES_KEY, self.resources.map{ |resource| resource.to_h } ],
|
438
|
+
[ EVENT_CODES_KEY, self.event_codes.map{ |event_code| event_code.to_h } ],
|
439
|
+
[ PARAMETERS_KEY, self.parameters.map{ |parameter| parameter.to_h } ],
|
440
|
+
[ AREAS_KEY, self.areas.map{ |area| area.to_h }])
|
441
441
|
end
|
442
442
|
|
443
443
|
def self.from_h( info_hash ) # :nodoc:
|
444
444
|
self.new( :language => info_hash[ LANGUAGE_KEY ],
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
445
|
+
:categories => info_hash[ CATEGORIES_KEY ],
|
446
|
+
:event => info_hash[ EVENT_KEY ],
|
447
|
+
:response_types => info_hash[ RESPONSE_TYPES_KEY ],
|
448
|
+
:urgency => info_hash[ URGENCY_KEY ],
|
449
|
+
:severity => info_hash[ SEVERITY_KEY ],
|
450
|
+
:certainty => info_hash[ CERTAINTY_KEY ],
|
451
|
+
:audience => info_hash[ AUDIENCE_KEY ],
|
452
|
+
:effective => RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ]),
|
453
|
+
:onset => RCAP.parse_datetime( info_hash[ ONSET_KEY ]),
|
454
|
+
:expires => RCAP.parse_datetime( info_hash[ EXPIRES_KEY ]),
|
455
|
+
:sender_name => info_hash[ SENDER_NAME_KEY ],
|
456
|
+
:headline => info_hash[ HEADLINE_KEY ],
|
457
|
+
:description => info_hash[ DESCRIPTION_KEY ],
|
458
|
+
:instruction => info_hash[ INSTRUCTION_KEY ],
|
459
|
+
:web => info_hash[ WEB_KEY ],
|
460
|
+
:contact => info_hash[ CONTACT_KEY ],
|
461
|
+
:resources => Array( info_hash[ RESOURCES_KEY ]).map{ |resource_hash| Resource.from_h( resource_hash ) },
|
462
|
+
:event_codes => Array( info_hash[ EVENT_CODES_KEY ]).map{ |event_code_hash| EventCode.from_h( event_code_hash )},
|
463
|
+
:parameters => Array( info_hash[ PARAMETERS_KEY ]).map{ |parameter_hash| Parameter.from_h( parameter_hash )},
|
464
|
+
:areas => Array( info_hash[ AREAS_KEY ]).map{ |area_hash| Area.from_h( area_hash )})
|
465
465
|
end
|
466
466
|
end
|
467
467
|
end
|
@@ -46,7 +46,7 @@ module RCAP
|
|
46
46
|
|
47
47
|
def self.from_xml_element( parameter_xml_element ) # :nodoc:
|
48
48
|
Parameter.new( :name => RCAP.xpath_text( parameter_xml_element, self::NAME_XPATH, Alert::XMLNS ),
|
49
|
-
|
49
|
+
:value => RCAP.xpath_text( parameter_xml_element, self::VALUE_XPATH, Alert::XMLNS ))
|
50
50
|
end
|
51
51
|
|
52
52
|
# Two parameters are equivalent if they have the same name and value.
|
data/lib/rcap/cap_1_1/point.rb
CHANGED
@@ -78,11 +78,11 @@ module RCAP
|
|
78
78
|
|
79
79
|
def self.from_xml_element( resource_xml_element ) # :nodoc:
|
80
80
|
resource = self.new( :resource_desc => RCAP.xpath_text( resource_xml_element, RESOURCE_DESC_XPATH, Alert::XMLNS ),
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
:uri => RCAP.xpath_text( resource_xml_element, URI_XPATH, Alert::XMLNS ),
|
82
|
+
:mime_type => RCAP.xpath_text( resource_xml_element, MIME_TYPE_XPATH, Alert::XMLNS ),
|
83
|
+
:deref_uri => RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH, Alert::XMLNS ),
|
84
|
+
:size => RCAP.xpath_text( resource_xml_element, SIZE_XPATH, Alert::XMLNS ),
|
85
|
+
:digest => RCAP.xpath_text( resource_xml_element, DIGEST_XPATH, Alert::XMLNS ))
|
86
86
|
end
|
87
87
|
|
88
88
|
RESOURCE_DESC_YAML = "Resource Description" # :nodoc:
|
@@ -99,8 +99,7 @@ module RCAP
|
|
99
99
|
[ MIME_TYPE_YAML, self.mime_type ],
|
100
100
|
[ DEREF_URI_YAML, self.deref_uri ],
|
101
101
|
[ SIZE_YAML, self.size ],
|
102
|
-
[ DIGEST_YAML, self.digest ]
|
103
|
-
).to_yaml( options )
|
102
|
+
[ DIGEST_YAML, self.digest ]).to_yaml( options )
|
104
103
|
end
|
105
104
|
|
106
105
|
def self.from_yaml_data( resource_yaml_data ) # :nodoc:
|
data/lib/rcap/cap_1_2/alert.rb
CHANGED
@@ -107,7 +107,7 @@ module RCAP
|
|
107
107
|
validates_collection_of( :infos )
|
108
108
|
|
109
109
|
def initialize( attributes = {})
|
110
|
-
@identifier = attributes[ :identifier ]
|
110
|
+
@identifier = attributes[ :identifier ] || RCAP.generate_identifier
|
111
111
|
@sender = attributes[ :sender ]
|
112
112
|
@sent = attributes[ :sent ]
|
113
113
|
@status = attributes[ :status ]
|
@@ -185,23 +185,23 @@ module RCAP
|
|
185
185
|
end
|
186
186
|
|
187
187
|
def inspect # :nodoc:
|
188
|
-
alert_inspect = "CAP Version: #{ CAP_VERSION }
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
188
|
+
alert_inspect = [ "CAP Version: #{ CAP_VERSION }",
|
189
|
+
"Identifier: #{ self.identifier }",
|
190
|
+
"Sender: #{ self.sender }",
|
191
|
+
"Sent: #{ self.sent }",
|
192
|
+
"Status: #{ self.status }",
|
193
|
+
"Message Type: #{ self.msg_type }",
|
194
|
+
"Source: #{ self.source }",
|
195
|
+
"Scope: #{ self.scope }",
|
196
|
+
"Restriction: #{ self.restriction }",
|
197
|
+
"Addresses: #{ self.addresses.to_s_for_cap }",
|
198
|
+
"Codes:",
|
199
|
+
self.codes.map{ |code| " #{ code }" }.join("\n"),
|
200
|
+
"Note: #{ self.note }",
|
201
|
+
"References: #{ self.references.join( ' ' )}",
|
202
|
+
"Incidents: #{ self.incidents.join( ' ')}",
|
203
|
+
"Information:",
|
204
|
+
self.infos.map{ |info| " " + info.to_s }.join( "\n" )].join( "\n" )
|
205
205
|
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
206
206
|
end
|
207
207
|
|
@@ -214,19 +214,19 @@ module RCAP
|
|
214
214
|
|
215
215
|
def self.from_xml_element( alert_xml_element ) # :nodoc:
|
216
216
|
self.new( :identifier => RCAP.xpath_text( alert_xml_element, IDENTIFIER_XPATH, Alert::XMLNS ),
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
217
|
+
:sender => RCAP.xpath_text( alert_xml_element, SENDER_XPATH, Alert::XMLNS ),
|
218
|
+
:sent => (( sent = RCAP.xpath_first( alert_xml_element, SENT_XPATH, Alert::XMLNS )) ? DateTime.parse( sent.text ) : nil ),
|
219
|
+
:status => RCAP.xpath_text( alert_xml_element, STATUS_XPATH, Alert::XMLNS ),
|
220
|
+
:msg_type => RCAP.xpath_text( alert_xml_element, MSG_TYPE_XPATH, Alert::XMLNS ),
|
221
|
+
:source => RCAP.xpath_text( alert_xml_element, SOURCE_XPATH, Alert::XMLNS ),
|
222
|
+
:scope => RCAP.xpath_text( alert_xml_element, SCOPE_XPATH, Alert::XMLNS ),
|
223
|
+
:restriction => RCAP.xpath_text( alert_xml_element, RESTRICTION_XPATH, Alert::XMLNS ),
|
224
|
+
:addresses => (( address = RCAP.xpath_text( alert_xml_element, ADDRESSES_XPATH, Alert::XMLNS )) ? address.unpack_cap_list : nil ),
|
225
|
+
:codes => RCAP.xpath_match( alert_xml_element, CODE_XPATH, Alert::XMLNS ).map{ |element| element.text },
|
226
|
+
:note => RCAP.xpath_text( alert_xml_element, NOTE_XPATH, Alert::XMLNS ),
|
227
|
+
:references => (( references = RCAP.xpath_text( alert_xml_element, REFERENCES_XPATH, Alert::XMLNS )) ? references.split( ' ' ) : nil ),
|
228
|
+
:incidents => (( incidents = RCAP.xpath_text( alert_xml_element, INCIDENTS_XPATH, Alert::XMLNS )) ? incidents.split( ' ' ) : nil ),
|
229
|
+
:infos => RCAP.xpath_match( alert_xml_element, Info::XPATH, Alert::XMLNS ).map{ |element| Info.from_xml_element( element )})
|
230
230
|
end
|
231
231
|
|
232
232
|
def self.from_xml_document( xml_document ) # :nodoc:
|
@@ -257,21 +257,21 @@ module RCAP
|
|
257
257
|
# Returns a string containing the YAML representation of the alert.
|
258
258
|
def to_yaml( options = {} )
|
259
259
|
RCAP.attribute_values_to_hash(
|
260
|
-
[ CAP_VERSION_YAML,
|
261
|
-
[ IDENTIFIER_YAML,
|
262
|
-
[ SENDER_YAML,
|
263
|
-
[ SENT_YAML,
|
264
|
-
[ STATUS_YAML,
|
265
|
-
[ MSG_TYPE_YAML,
|
266
|
-
[ SOURCE_YAML,
|
267
|
-
[ SCOPE_YAML,
|
268
|
-
[ RESTRICTION_YAML,
|
269
|
-
[ ADDRESSES_YAML,
|
270
|
-
[ CODES_YAML,
|
271
|
-
[ NOTE_YAML,
|
272
|
-
[ REFERENCES_YAML,
|
273
|
-
[ INCIDENTS_YAML,
|
274
|
-
[ INFOS_YAML,
|
260
|
+
[ CAP_VERSION_YAML, CAP_VERSION ],
|
261
|
+
[ IDENTIFIER_YAML, self.identifier ],
|
262
|
+
[ SENDER_YAML, self.sender ],
|
263
|
+
[ SENT_YAML, self.sent ],
|
264
|
+
[ STATUS_YAML, self.status ],
|
265
|
+
[ MSG_TYPE_YAML, self.msg_type ],
|
266
|
+
[ SOURCE_YAML, self.source ],
|
267
|
+
[ SCOPE_YAML, self.scope ],
|
268
|
+
[ RESTRICTION_YAML, self.restriction ],
|
269
|
+
[ ADDRESSES_YAML, self.addresses ],
|
270
|
+
[ CODES_YAML, self.codes ],
|
271
|
+
[ NOTE_YAML, self.note ],
|
272
|
+
[ REFERENCES_YAML, self.references ],
|
273
|
+
[ INCIDENTS_YAML, self.incidents ],
|
274
|
+
[ INFOS_YAML, self.infos ]
|
275
275
|
).to_yaml( options )
|
276
276
|
end
|
277
277
|
|
@@ -318,20 +318,20 @@ module RCAP
|
|
318
318
|
# Returns a Hash representation of an Alert object
|
319
319
|
def to_h
|
320
320
|
RCAP.attribute_values_to_hash( [ CAP_VERSION_KEY, CAP_VERSION ],
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
321
|
+
[ IDENTIFIER_KEY, self.identifier ],
|
322
|
+
[ SENDER_KEY, self.sender ],
|
323
|
+
[ SENT_KEY, RCAP.to_s_for_cap( self.sent )],
|
324
|
+
[ STATUS_KEY, self.status ],
|
325
|
+
[ MSG_TYPE_KEY, self.msg_type ],
|
326
|
+
[ SOURCE_KEY, self.source ],
|
327
|
+
[ SCOPE_KEY, self.scope ],
|
328
|
+
[ RESTRICTION_KEY, self.restriction ],
|
329
|
+
[ ADDRESSES_KEY, self.addresses ],
|
330
|
+
[ CODES_KEY, self.codes ],
|
331
|
+
[ NOTE_KEY, self.note ],
|
332
|
+
[ REFERENCES_KEY, self.references ],
|
333
|
+
[ INCIDENTS_KEY, self.incidents ],
|
334
|
+
[ INFOS_KEY, self.infos.map{ |info| info.to_h }])
|
335
335
|
end
|
336
336
|
|
337
337
|
# Initialises an Alert object from a Hash produced by Alert#to_h
|
data/lib/rcap/cap_1_2/area.rb
CHANGED
@@ -111,11 +111,11 @@ module RCAP
|
|
111
111
|
|
112
112
|
def self.from_xml_element( area_xml_element ) # :nodoc:
|
113
113
|
self.new( :area_desc => RCAP.xpath_text( area_xml_element, AREA_DESC_XPATH, Alert::XMLNS ),
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
:altitude => (( alt = RCAP.xpath_text( area_xml_element, ALTITUDE_XPATH, Alert::XMLNS )) ? alt.to_f : nil ),
|
115
|
+
:ceiling => (( ceil = RCAP.xpath_text( area_xml_element, CEILING_XPATH, Alert::XMLNS )) ? ceil.to_f : nil ),
|
116
|
+
:circles => RCAP.xpath_match( area_xml_element, Circle::XPATH, Alert::XMLNS ).map{ |circle_element| Circle.from_xml_element( circle_element )},
|
117
|
+
:geocodes => RCAP.xpath_match( area_xml_element, Geocode::XPATH, Alert::XMLNS ).map{ |geocode_element| Geocode.from_xml_element( geocode_element )},
|
118
|
+
:polygons => RCAP.xpath_match( area_xml_element, Polygon::XPATH, Alert::XMLNS ).map{ |polygon_element| Polygon.from_xml_element( polygon_element )})
|
119
119
|
end
|
120
120
|
|
121
121
|
AREA_DESC_YAML = 'Area Description' # :nodoc:
|
data/lib/rcap/cap_1_2/circle.rb
CHANGED
@@ -69,12 +69,14 @@ module RCAP
|
|
69
69
|
LONGITUDE_KEY = 'longitude' # :nodoc:
|
70
70
|
def to_h # :nodoc:
|
71
71
|
RCAP.attribute_values_to_hash( [ RADIUS_KEY, self.radius ],
|
72
|
-
|
73
|
-
|
72
|
+
[ LATTITUDE_KEY, self.lattitude ],
|
73
|
+
[ LONGITUDE_KEY, self.longitude ])
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.from_h( circle_hash ) # :nodoc:
|
77
|
-
self.new( :radius => circle_hash[ RADIUS_KEY ],
|
77
|
+
self.new( :radius => circle_hash[ RADIUS_KEY ],
|
78
|
+
:lattitude => circle_hash[ LATTITUDE_KEY ],
|
79
|
+
:longitude => circle_hash[ LONGITUDE_KEY ])
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
data/lib/rcap/cap_1_2/info.rb
CHANGED
@@ -345,29 +345,27 @@ module RCAP
|
|
345
345
|
|
346
346
|
parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}
|
347
347
|
|
348
|
-
RCAP.attribute_values_to_hash(
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
[ AREAS_YAML, self.areas ]
|
370
|
-
).to_yaml( options )
|
348
|
+
RCAP.attribute_values_to_hash( [ LANGUAGE_YAML, self.language ],
|
349
|
+
[ CATEGORIES_YAML, categories_yaml ],
|
350
|
+
[ EVENT_YAML, self.event ],
|
351
|
+
[ RESPONSE_TYPES_YAML, response_types_yaml ],
|
352
|
+
[ URGENCY_YAML, self.urgency ],
|
353
|
+
[ SEVERITY_YAML, self.severity ],
|
354
|
+
[ CERTAINTY_YAML, self.certainty ],
|
355
|
+
[ AUDIENCE_YAML, self.audience ],
|
356
|
+
[ EFFECTIVE_YAML, self.effective ],
|
357
|
+
[ ONSET_YAML, self.onset ],
|
358
|
+
[ EXPIRES_YAML, self.expires ],
|
359
|
+
[ SENDER_NAME_YAML, self.sender_name ],
|
360
|
+
[ HEADLINE_YAML, self.headline ],
|
361
|
+
[ DESCRIPTION_YAML, self.description ],
|
362
|
+
[ INSTRUCTION_YAML, self.instruction ],
|
363
|
+
[ WEB_YAML, self.web ],
|
364
|
+
[ CONTACT_YAML, self.contact ],
|
365
|
+
[ EVENT_CODES_YAML, self.event_codes.inject({}, ¶meter_to_hash )],
|
366
|
+
[ PARAMETERS_YAML, self.parameters.inject({}, ¶meter_to_hash )],
|
367
|
+
[ RESOURCES_YAML, self.resources ],
|
368
|
+
[ AREAS_YAML, self.areas ]).to_yaml( options )
|
371
369
|
end
|
372
370
|
|
373
371
|
def self.from_yaml_data( info_yaml_data ) # :nodoc:
|
@@ -420,50 +418,50 @@ module RCAP
|
|
420
418
|
|
421
419
|
def to_h # :nodoc:
|
422
420
|
RCAP.attribute_values_to_hash( [ LANGUAGE_KEY, self.language ],
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
421
|
+
[ CATEGORIES_KEY, self.categories ],
|
422
|
+
[ EVENT_KEY, self.event ],
|
423
|
+
[ RESPONSE_TYPES_KEY, self.response_types ],
|
424
|
+
[ URGENCY_KEY, self.urgency ],
|
425
|
+
[ SEVERITY_KEY, self.severity ],
|
426
|
+
[ CERTAINTY_KEY, self.certainty ],
|
427
|
+
[ AUDIENCE_KEY, self.audience ],
|
428
|
+
[ EFFECTIVE_KEY, RCAP.to_s_for_cap( self.effective )],
|
429
|
+
[ ONSET_KEY, RCAP.to_s_for_cap( self.onset )],
|
430
|
+
[ EXPIRES_KEY, RCAP.to_s_for_cap( self.expires )],
|
431
|
+
[ SENDER_NAME_KEY, self.sender_name ],
|
432
|
+
[ HEADLINE_KEY, self.headline ],
|
433
|
+
[ DESCRIPTION_KEY, self.description ],
|
434
|
+
[ INSTRUCTION_KEY, self.instruction ],
|
435
|
+
[ WEB_KEY, self.web ],
|
436
|
+
[ CONTACT_KEY, self.contact ],
|
437
|
+
[ RESOURCES_KEY, self.resources.map{ |resource| resource.to_h } ],
|
438
|
+
[ EVENT_CODES_KEY, self.event_codes.map{ |event_code| event_code.to_h } ],
|
439
|
+
[ PARAMETERS_KEY, self.parameters.map{ |parameter| parameter.to_h } ],
|
440
|
+
[ AREAS_KEY, self.areas.map{ |area| area.to_h }])
|
443
441
|
end
|
444
442
|
|
445
443
|
def self.from_h( info_hash ) # :nodoc:
|
446
444
|
self.new( :language => info_hash[ LANGUAGE_KEY ],
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
445
|
+
:categories => info_hash[ CATEGORIES_KEY ],
|
446
|
+
:event => info_hash[ EVENT_KEY ],
|
447
|
+
:response_types => info_hash[ RESPONSE_TYPES_KEY ],
|
448
|
+
:urgency => info_hash[ URGENCY_KEY ],
|
449
|
+
:severity => info_hash[ SEVERITY_KEY ],
|
450
|
+
:certainty => info_hash[ CERTAINTY_KEY ],
|
451
|
+
:audience => info_hash[ AUDIENCE_KEY ],
|
452
|
+
:effective => RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ]),
|
453
|
+
:onset => RCAP.parse_datetime( info_hash[ ONSET_KEY ]),
|
454
|
+
:expires => RCAP.parse_datetime( info_hash[ EXPIRES_KEY ]),
|
455
|
+
:sender_name => info_hash[ SENDER_NAME_KEY ],
|
456
|
+
:headline => info_hash[ HEADLINE_KEY ],
|
457
|
+
:description => info_hash[ DESCRIPTION_KEY ],
|
458
|
+
:instruction => info_hash[ INSTRUCTION_KEY ],
|
459
|
+
:web => info_hash[ WEB_KEY ],
|
460
|
+
:contact => info_hash[ CONTACT_KEY ],
|
461
|
+
:resources => Array( info_hash[ RESOURCES_KEY ]).map{ |resource_hash| Resource.from_h( resource_hash ) },
|
462
|
+
:event_codes => Array( info_hash[ EVENT_CODES_KEY ]).map{ |event_code_hash| EventCode.from_h( event_code_hash )},
|
463
|
+
:parameters => Array( info_hash[ PARAMETERS_KEY ]).map{ |parameter_hash| Parameter.from_h( parameter_hash )},
|
464
|
+
:areas => Array( info_hash[ AREAS_KEY ]).map{ |area_hash| Area.from_h( area_hash )})
|
467
465
|
end
|
468
466
|
end
|
469
467
|
end
|
@@ -46,7 +46,7 @@ module RCAP
|
|
46
46
|
|
47
47
|
def self.from_xml_element( parameter_xml_element ) # :nodoc:
|
48
48
|
Parameter.new( :name => RCAP.xpath_text( parameter_xml_element, NAME_XPATH, Alert::XMLNS ),
|
49
|
-
|
49
|
+
:value => RCAP.xpath_text( parameter_xml_element, VALUE_XPATH, Alert::XMLNS ))
|
50
50
|
end
|
51
51
|
|
52
52
|
# Two parameters are equivalent if they have the same name and value.
|
data/lib/rcap/utilities.rb
CHANGED
@@ -61,12 +61,12 @@ module RCAP # :nodoc:
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.format_lines_for_inspect( header, inspect_string )
|
64
|
-
max_line_length = inspect_string.lines.
|
65
|
-
"\n." + '-' * max_line_length + ".\n"+
|
66
|
-
'|' + header.ljust( max_line_length ) + "|\n"+
|
67
|
-
'|' + '-' * max_line_length + "|\n"+
|
68
|
-
inspect_string.lines.map{ |line| '|' + line.chomp.ljust( max_line_length ) +'|'}.join( "\n" ) + "\n" +
|
69
|
-
"'" + '-' * max_line_length + "'\n"
|
64
|
+
max_line_length = inspect_string.lines.map{ |line| line.chomp.length }.max
|
65
|
+
"\n." + '-' * (max_line_length + 2) + ".\n"+
|
66
|
+
'| ' + header.ljust( max_line_length ) + " |\n"+
|
67
|
+
'|' + '-' * ( max_line_length + 2 ) + "|\n"+
|
68
|
+
inspect_string.lines.map{ |line| '| ' + line.chomp.ljust( max_line_length ) +' |'}.join( "\n" ) + "\n" +
|
69
|
+
"'" + '-' * ( max_line_length + 2 ) + "'\n"
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.attribute_values_to_hash( *attribute_values )
|
data/lib/rcap/version.rb
CHANGED
data/spec/cap_1_0/alert_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe( RCAP::CAP_1_0::Alert ) do
|
|
6
6
|
@alert = RCAP::CAP_1_0::Alert.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it( 'should
|
9
|
+
it( 'should have a identifier' ){ @alert.identifier.should_not( be_nil )}
|
10
10
|
it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
|
11
11
|
it( 'should not have a sent time' ){ @alert.sent.should( be_nil )}
|
12
12
|
it( 'should not have a status' ){ @alert.status.should( be_nil )}
|
data/spec/cap_1_1/alert_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe( RCAP::CAP_1_1::Alert ) do
|
|
6
6
|
@alert = RCAP::CAP_1_1::Alert.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it( 'should
|
9
|
+
it( 'should have a identifier' ){ @alert.identifier.should_not( be_nil )}
|
10
10
|
it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
|
11
11
|
it( 'should not have a sent time' ){ @alert.sent.should( be_nil )}
|
12
12
|
it( 'should not have a status' ){ @alert.status.should( be_nil )}
|
data/spec/cap_1_2/alert_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe( RCAP::CAP_1_2::Alert ) do
|
|
6
6
|
@alert = RCAP::CAP_1_2::Alert.new
|
7
7
|
end
|
8
8
|
|
9
|
-
it( 'should
|
9
|
+
it( 'should have a identifier' ){ @alert.identifier.should_not( be_nil )}
|
10
10
|
it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
|
11
11
|
it( 'should not have a sent time' ){ @alert.sent.should( be_nil )}
|
12
12
|
it( 'should not have a status' ){ @alert.status.should( be_nil )}
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rcap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Farrel Lifson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assistance
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- Gemfile
|
84
84
|
- README.rdoc
|
85
85
|
- Rakefile
|
86
|
+
- lib/config.rb
|
86
87
|
- lib/rcap.rb
|
87
88
|
- lib/rcap/alert.rb
|
88
89
|
- lib/rcap/cap_1_0/alert.rb
|