rcap 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,10 @@
1
1
  = Change Log
2
2
 
3
- == 1.1 - 20 June 2011
3
+ == 1.1.1 - 25 June 2011
4
+
5
+ * Documentation and code cleanup
6
+
7
+ == 1.1.0 - 20 June 2011
4
8
 
5
9
  * Added CAP 1.0 Support
6
10
 
@@ -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.0.0
11
+ 1.1.1
12
12
 
13
13
  == Dependencies
14
14
 
@@ -0,0 +1,2 @@
1
+ XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new( 2 )
2
+ XML_PRETTY_PRINTER.compact = true
@@ -39,6 +39,4 @@ require 'rcap/cap_1_2/circle'
39
39
  require 'rcap/cap_1_2/polygon'
40
40
  require 'rcap/cap_1_2/geocode'
41
41
  require 'rcap/cap_1_2/area'
42
-
43
- XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new( 2 )
44
- XML_PRETTY_PRINTER.compact = true
42
+ require 'config'
@@ -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 }\n"+
193
- "Identifier: #{ self.identifier }\n"+
194
- "Sender: #{ self.sender }\n"+
195
- "Sent: #{ self.sent }\n"+
196
- "Status: #{ self.status }\n"+
197
- "Message Type: #{ self.msg_type }\n"+
198
- "Password: #{ self.password }\n"+
199
- "Source: #{ self.source }\n"+
200
- "Scope: #{ self.scope }\n"+
201
- "Restriction: #{ self.restriction }\n"+
202
- "Addresses: #{ self.addresses.to_s_for_cap }\n"+
203
- "Codes:\n"+
204
- self.codes.map{ |code| " " + code }.join("\n")+"\n"+
205
- "Note: #{ self.note }\n"+
206
- "References: #{ self.references.join( ' ' )}\n"+
207
- "Incidents: #{ self.incidents.join( ' ')}\n"+
208
- "Information:\n"+
209
- self.infos.map{ |info| " " + info.to_s }.join( "\n" )
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
- :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 )})
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:
@@ -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
- :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 )})
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, 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 ]
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
 
@@ -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
- :longitude => longitude,
54
- :radius => radius )
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' # :nodoc:
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, self.radius ],
72
- [ LATTITUDE_KEY, self.lattitude ],
73
- [ LONGITUDE_KEY, self.longitude ])
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 => circle_hash[ RADIUS_KEY ], :lattitude => circle_hash[ LATTITUDE_KEY ], :longitude => circle_hash[ LONGITUDE_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
@@ -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
- [ LANGUAGE_YAML, self.language ],
320
- [ CATEGORIES_YAML, categories_yaml ],
321
- [ EVENT_YAML, self.event ],
322
- [ URGENCY_YAML, self.urgency ],
323
- [ SEVERITY_YAML, self.severity ],
324
- [ CERTAINTY_YAML, self.certainty ],
325
- [ AUDIENCE_YAML, self.audience ],
326
- [ EFFECTIVE_YAML, self.effective ],
327
- [ ONSET_YAML, self.onset ],
328
- [ EXPIRES_YAML, self.expires ],
329
- [ SENDER_NAME_YAML, self.sender_name ],
330
- [ HEADLINE_YAML, self.headline ],
331
- [ DESCRIPTION_YAML, self.description ],
332
- [ INSTRUCTION_YAML, self.instruction ],
333
- [ WEB_YAML, self.web ],
334
- [ CONTACT_YAML, self.contact ],
335
- [ EVENT_CODES_YAML, self.event_codes.inject({}, &parameter_to_hash )],
336
- [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_to_hash )],
337
- [ RESOURCES_YAML, self.resources ],
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({}, &parameter_to_hash )],
335
+ [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_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:
@@ -9,7 +9,7 @@ module RCAP
9
9
  MAX_LONGITUDE = 180
10
10
  MIN_LONGITUDE = -180
11
11
  MAX_LATTITUDE = 90
12
- MIN_LATTITUDE= -90
12
+ MIN_LATTITUDE = -90
13
13
 
14
14
  attr_accessor( :lattitude )
15
15
  attr_accessor( :longitude )
@@ -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
- :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 ))
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:
@@ -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 }\n"+
189
- "Identifier: #{ self.identifier }\n"+
190
- "Sender: #{ self.sender }\n"+
191
- "Sent: #{ self.sent }\n"+
192
- "Status: #{ self.status }\n"+
193
- "Message Type: #{ self.msg_type }\n"+
194
- "Source: #{ self.source }\n"+
195
- "Scope: #{ self.scope }\n"+
196
- "Restriction: #{ self.restriction }\n"+
197
- "Addresses: #{ self.addresses.to_s_for_cap }\n"+
198
- "Codes:\n"+
199
- self.codes.map{ |code| " " + code }.join("\n")+"\n"+
200
- "Note: #{ self.note }\n"+
201
- "References: #{ self.references.join( ' ' )}\n"+
202
- "Incidents: #{ self.incidents.join( ' ')}\n"+
203
- "Information:\n"+
204
- self.infos.map{ |info| " " + info.to_s }.join( "\n" )
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
- :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 )})
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" # :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:
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
- [ 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 }])
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
@@ -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, 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 ]
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
 
@@ -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
- :longitude => longitude,
54
- :radius => radius )
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
- [ LATTITUDE_KEY, self.lattitude ],
73
- [ LONGITUDE_KEY, self.longitude ])
72
+ [ LATTITUDE_KEY, self.lattitude ],
73
+ [ LONGITUDE_KEY, self.longitude ])
74
74
  end
75
75
 
76
76
  def self.from_h( circle_hash ) # :nodoc:
@@ -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
- [ 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({}, &parameter_to_hash )],
365
- [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_to_hash )],
366
- [ RESOURCES_YAML, self.resources ],
367
- [ AREAS_YAML, self.areas ]
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({}, &parameter_to_hash )],
365
+ [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_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( [ 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 }])
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
- :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 )})
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
- :value => RCAP.xpath_text( parameter_xml_element, self::VALUE_XPATH, Alert::XMLNS ))
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.
@@ -9,7 +9,7 @@ module RCAP
9
9
  MAX_LONGITUDE = 180
10
10
  MIN_LONGITUDE = -180
11
11
  MAX_LATTITUDE = 90
12
- MIN_LATTITUDE= -90
12
+ MIN_LATTITUDE = -90
13
13
 
14
14
  attr_accessor( :lattitude )
15
15
  attr_accessor( :longitude )
@@ -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
- :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 ))
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:
@@ -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 }\n"+
189
- "Identifier: #{ self.identifier }\n"+
190
- "Sender: #{ self.sender }\n"+
191
- "Sent: #{ self.sent }\n"+
192
- "Status: #{ self.status }\n"+
193
- "Message Type: #{ self.msg_type }\n"+
194
- "Source: #{ self.source }\n"+
195
- "Scope: #{ self.scope }\n"+
196
- "Restriction: #{ self.restriction }\n"+
197
- "Addresses: #{ self.addresses.to_s_for_cap }\n"+
198
- "Codes:\n"+
199
- " #{ self.codes.map{ |code| " #{ code }" }.join("\n")}\n"+
200
- "Note: #{ self.note }\n"+
201
- "References: #{ self.references.join( ' ' )}\n"+
202
- "Incidents: #{ self.incidents.join( ' ')}\n"+
203
- "Information:\n"+
204
- " #{ self.infos.map{ |info| " " + info.to_s }.join( "\n" )}\n"
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
- :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 )})
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, 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 ]
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
- [ 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 }])
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
@@ -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
- :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 )})
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:
@@ -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
- [ LATTITUDE_KEY, self.lattitude ],
73
- [ LONGITUDE_KEY, self.longitude ])
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 ], :lattitude => circle_hash[ LATTITUDE_KEY ], :longitude => circle_hash[ LONGITUDE_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
@@ -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
- [ LANGUAGE_YAML, self.language ],
350
- [ CATEGORIES_YAML, categories_yaml ],
351
- [ EVENT_YAML, self.event ],
352
- [ RESPONSE_TYPES_YAML, response_types_yaml ],
353
- [ URGENCY_YAML, self.urgency ],
354
- [ SEVERITY_YAML, self.severity ],
355
- [ CERTAINTY_YAML, self.certainty ],
356
- [ AUDIENCE_YAML, self.audience ],
357
- [ EFFECTIVE_YAML, self.effective ],
358
- [ ONSET_YAML, self.onset ],
359
- [ EXPIRES_YAML, self.expires ],
360
- [ SENDER_NAME_YAML, self.sender_name ],
361
- [ HEADLINE_YAML, self.headline ],
362
- [ DESCRIPTION_YAML, self.description ],
363
- [ INSTRUCTION_YAML, self.instruction ],
364
- [ WEB_YAML, self.web ],
365
- [ CONTACT_YAML, self.contact ],
366
- [ EVENT_CODES_YAML, self.event_codes.inject({}, &parameter_to_hash )],
367
- [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_to_hash )],
368
- [ RESOURCES_YAML, self.resources ],
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({}, &parameter_to_hash )],
366
+ [ PARAMETERS_YAML, self.parameters.inject({}, &parameter_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
- [ CATEGORIES_KEY, self.categories ],
424
- [ EVENT_KEY, self.event ],
425
- [ RESPONSE_TYPES_KEY, self.response_types ],
426
- [ URGENCY_KEY, self.urgency ],
427
- [ SEVERITY_KEY, self.severity ],
428
- [ CERTAINTY_KEY, self.certainty ],
429
- [ AUDIENCE_KEY, self.audience ],
430
- [ EFFECTIVE_KEY, RCAP.to_s_for_cap( self.effective )],
431
- [ ONSET_KEY, RCAP.to_s_for_cap( self.onset )],
432
- [ EXPIRES_KEY, RCAP.to_s_for_cap( self.expires )],
433
- [ SENDER_NAME_KEY, self.sender_name ],
434
- [ HEADLINE_KEY, self.headline ],
435
- [ DESCRIPTION_KEY, self.description ],
436
- [ INSTRUCTION_KEY, self.instruction ],
437
- [ WEB_KEY, self.web ],
438
- [ CONTACT_KEY, self.contact ],
439
- [ RESOURCES_KEY, self.resources.map{ |resource| resource.to_h } ],
440
- [ EVENT_CODES_KEY, self.event_codes.map{ |event_code| event_code.to_h } ],
441
- [ PARAMETERS_KEY, self.parameters.map{ |parameter| parameter.to_h } ],
442
- [ AREAS_KEY, self.areas.map{ |area| area.to_h }])
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
- :categories => info_hash[ CATEGORIES_KEY ],
448
- :event => info_hash[ EVENT_KEY ],
449
- :response_types => info_hash[ RESPONSE_TYPES_KEY ],
450
- :urgency => info_hash[ URGENCY_KEY ],
451
- :severity => info_hash[ SEVERITY_KEY ],
452
- :certainty => info_hash[ CERTAINTY_KEY ],
453
- :audience => info_hash[ AUDIENCE_KEY ],
454
- :effective => RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ]),
455
- :onset => RCAP.parse_datetime( info_hash[ ONSET_KEY ]),
456
- :expires => RCAP.parse_datetime( info_hash[ EXPIRES_KEY ]),
457
- :sender_name => info_hash[ SENDER_NAME_KEY ],
458
- :headline => info_hash[ HEADLINE_KEY ],
459
- :description => info_hash[ DESCRIPTION_KEY ],
460
- :instruction => info_hash[ INSTRUCTION_KEY ],
461
- :web => info_hash[ WEB_KEY ],
462
- :contact => info_hash[ CONTACT_KEY ],
463
- :resources => Array( info_hash[ RESOURCES_KEY ]).map{ |resource_hash| Resource.from_h( resource_hash ) },
464
- :event_codes => Array( info_hash[ EVENT_CODES_KEY ]).map{ |event_code_hash| EventCode.from_h( event_code_hash )},
465
- :parameters => Array( info_hash[ PARAMETERS_KEY ]).map{ |parameter_hash| Parameter.from_h( parameter_hash )},
466
- :areas => Array( info_hash[ AREAS_KEY ]).map{ |area_hash| Area.from_h( area_hash )})
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
- :value => RCAP.xpath_text( parameter_xml_element, VALUE_XPATH, Alert::XMLNS ))
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.
@@ -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.inject( 0 ){ |max_length, line| line.chomp.length > max_length ? line.chomp.length : max_length }
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 )
@@ -1,3 +1,3 @@
1
1
  module RCAP
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -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 not have a identifier' ){ @alert.identifier.should( be_nil )}
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 )}
@@ -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 not have a identifier' ){ @alert.identifier.should( be_nil )}
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 )}
@@ -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 not have a identifier' ){ @alert.identifier.should( be_nil )}
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.0
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-23 00:00:00 Z
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