rcap 0.4 → 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +104 -85
  5. data/Rakefile +35 -0
  6. data/lib/rcap.rb +21 -14
  7. data/lib/rcap/alert.rb +26 -325
  8. data/lib/rcap/cap_1_1/alert.rb +363 -0
  9. data/lib/rcap/cap_1_1/area.rb +180 -0
  10. data/lib/rcap/cap_1_1/circle.rb +81 -0
  11. data/lib/rcap/cap_1_1/event_code.rb +22 -0
  12. data/lib/rcap/cap_1_1/geocode.rb +22 -0
  13. data/lib/rcap/cap_1_1/info.rb +470 -0
  14. data/lib/rcap/cap_1_1/parameter.rb +68 -0
  15. data/lib/rcap/cap_1_1/point.rb +55 -0
  16. data/lib/rcap/cap_1_1/polygon.rb +89 -0
  17. data/lib/rcap/cap_1_1/resource.rb +145 -0
  18. data/lib/rcap/cap_1_2/alert.rb +363 -0
  19. data/lib/rcap/cap_1_2/area.rb +180 -0
  20. data/lib/rcap/cap_1_2/circle.rb +81 -0
  21. data/lib/rcap/cap_1_2/event_code.rb +22 -0
  22. data/lib/rcap/cap_1_2/geocode.rb +22 -0
  23. data/lib/rcap/cap_1_2/info.rb +472 -0
  24. data/lib/rcap/cap_1_2/parameter.rb +68 -0
  25. data/lib/rcap/cap_1_2/point.rb +55 -0
  26. data/lib/rcap/cap_1_2/polygon.rb +90 -0
  27. data/lib/rcap/cap_1_2/resource.rb +147 -0
  28. data/lib/rcap/utilities.rb +14 -9
  29. data/lib/rcap/validations.rb +39 -7
  30. data/lib/rcap/version.rb +3 -0
  31. data/rcap.gemspec +30 -0
  32. data/spec/alert_spec.rb +109 -172
  33. data/spec/cap_1_1/alert_spec.rb +222 -0
  34. data/spec/cap_1_1/area_spec.rb +247 -0
  35. data/spec/cap_1_1/circle_spec.rb +88 -0
  36. data/spec/{geocode_spec.rb → cap_1_1/geocode_spec.rb} +8 -8
  37. data/spec/{info_spec.rb → cap_1_1/info_spec.rb} +143 -75
  38. data/spec/{point_spec.rb → cap_1_1/point_spec.rb} +8 -8
  39. data/spec/cap_1_1/polygon_spec.rb +97 -0
  40. data/spec/{resource_spec.rb → cap_1_1/resource_spec.rb} +24 -24
  41. data/spec/cap_1_2/alert_spec.rb +233 -0
  42. data/spec/cap_1_2/area_spec.rb +248 -0
  43. data/spec/cap_1_2/circle_spec.rb +95 -0
  44. data/spec/cap_1_2/geocode_spec.rb +38 -0
  45. data/spec/cap_1_2/info_spec.rb +338 -0
  46. data/spec/cap_1_2/point_spec.rb +46 -0
  47. data/spec/cap_1_2/polygon_spec.rb +102 -0
  48. data/spec/cap_1_2/resource_spec.rb +161 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/validations_spec.rb +80 -7
  51. metadata +122 -37
  52. data/lib/rcap/area.rb +0 -156
  53. data/lib/rcap/circle.rb +0 -78
  54. data/lib/rcap/event_code.rb +0 -20
  55. data/lib/rcap/geocode.rb +0 -20
  56. data/lib/rcap/info.rb +0 -437
  57. data/lib/rcap/parameter.rb +0 -66
  58. data/lib/rcap/point.rb +0 -53
  59. data/lib/rcap/polygon.rb +0 -77
  60. data/lib/rcap/resource.rb +0 -143
  61. data/spec/area_spec.rb +0 -179
  62. data/spec/circle_spec.rb +0 -88
  63. data/spec/polygon_spec.rb +0 -68
@@ -1,20 +0,0 @@
1
- module RCAP
2
- class EventCode < Parameter
3
-
4
- XML_ELEMENT_NAME = 'eventCode' # :nodoc:
5
-
6
- XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
7
-
8
- def to_xml_element # :nodoc:
9
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
10
- xml_element.add_element( NAME_ELEMENT_NAME ).add_text( self.name )
11
- xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( self.value )
12
- xml_element
13
- end
14
-
15
- def self.from_xml_element( event_code_xml_element ) # :nodoc:
16
- EventCode.new( :name => RCAP.xpath_text( event_code_xml_element, NAME_XPATH ),
17
- :value => RCAP.xpath_text( event_code_xml_element, VALUE_XPATH ))
18
- end
19
- end
20
- end
data/lib/rcap/geocode.rb DELETED
@@ -1,20 +0,0 @@
1
- module RCAP
2
- class Geocode < Parameter
3
-
4
- XML_ELEMENT_NAME = 'geocode' # :nodoc:
5
-
6
- XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
7
-
8
- def to_xml_element # :nodoc:
9
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
10
- xml_element.add_element( NAME_ELEMENT_NAME ).add_text( @name )
11
- xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( @value )
12
- xml_element
13
- end
14
-
15
- def self.from_xml_element( geocode_xml_element ) # :nodoc:
16
- self.new( :name => RCAP.xpath_text( geocode_xml_element, NAME_XPATH ),
17
- :value => RCAP.xpath_text( geocode_xml_element, VALUE_XPATH ))
18
- end
19
- end
20
- end
data/lib/rcap/info.rb DELETED
@@ -1,437 +0,0 @@
1
- module RCAP
2
- # In Info object is valid if
3
- # * it has an event
4
- # * it has an urgency with a valid value
5
- # * it has a severity with a valid value
6
- # * it has a certainty with a valid value
7
- # * all categories are valid and categories has at minimum 1 entry
8
- # * all Resource objects in the resources collection are valid
9
- # * all Area objects in the areas collection are valid
10
- #
11
- class Info
12
- include Validation
13
-
14
- CATEGORY_GEO = "Geo" # :nodoc:
15
- CATEGORY_MET = "Met" # :nodoc:
16
- CATEGORY_SAFETY = "Safety" # :nodoc:
17
- CATEGORY_SECURITY = "Security" # :nodoc:
18
- CATEGORY_RESCUE = "Rescue" # :nodoc:
19
- CATEGORY_FIRE = "Fire" # :nodoc:
20
- CATEGORY_HEALTH = "Health" # :nodoc:
21
- CATEGORY_ENV = "Env" # :nodoc:
22
- CATEGORY_TRANSPORT = "Transport" # :nodoc:
23
- CATEGORY_INFRA = "Infra" # :nodoc:
24
- CATEGORY_CBRNE = "CBRNE" # :nodoc:
25
- CATEGORY_OTHER = "Other" # :nodoc:
26
- # Valid values for categories
27
- VALID_CATEGORIES = [ CATEGORY_GEO, CATEGORY_MET, CATEGORY_SAFETY,
28
- CATEGORY_SECURITY, CATEGORY_RESCUE, CATEGORY_FIRE, CATEGORY_HEALTH,
29
- CATEGORY_ENV, CATEGORY_TRANSPORT, CATEGORY_INFRA, CATEGORY_CBRNE,
30
- CATEGORY_OTHER ]
31
-
32
- RESPONSE_TYPE_SHELTER = "Shelter" # :nodoc:
33
- RESPONSE_TYPE_EVACUATE = "Evacuate" # :nodoc:
34
- RESPONSE_TYPE_PREPARE = "Prepare" # :nodoc:
35
- RESPONSE_TYPE_EXECUTE = "Execute" # :nodoc:
36
- RESPONSE_TYPE_MONITOR = "Monitor" # :nodoc:
37
- RESPONSE_TYPE_ASSESS = "Assess" # :nodoc:
38
- RESPONSE_TYPE_NONE = "None" # :nodoc:
39
- # Valid values for response_type
40
- VALID_RESPONSE_TYPES = [ RESPONSE_TYPE_SHELTER, RESPONSE_TYPE_EVACUATE,
41
- RESPONSE_TYPE_PREPARE, RESPONSE_TYPE_EXECUTE, RESPONSE_TYPE_MONITOR,
42
- RESPONSE_TYPE_ASSESS, RESPONSE_TYPE_NONE ]
43
-
44
- URGENCY_IMMEDIATE = "Immediate" # :nodoc:
45
- URGENCY_EXPECTED = "Expected" # :nodoc:
46
- URGENCY_FUTURE = "Future" # :nodoc:
47
- URGENCY_PAST = "Past" # :nodoc:
48
- URGENCY_UNKNOWN = "Unknown" # :nodoc:
49
- # Valid values for urgency
50
- VALID_URGENCIES = [ URGENCY_IMMEDIATE, URGENCY_EXPECTED, URGENCY_FUTURE,
51
- URGENCY_PAST, URGENCY_UNKNOWN ]
52
-
53
- SEVERITY_EXTREME = "Extreme" # :nodoc:
54
- SEVERITY_SEVERE = "Severe" # :nodoc:
55
- SEVERITY_MODERATE = "Moderate" # :nodoc:
56
- SEVERITY_MINOR = "Minor" # :nodoc:
57
- SEVERITY_UNKNOWN = "Unknown" # :nodoc:
58
- # Valid values for severity
59
- VALID_SEVERITIES = [ SEVERITY_EXTREME, SEVERITY_SEVERE, SEVERITY_MODERATE,
60
- SEVERITY_MINOR, SEVERITY_UNKNOWN ]
61
-
62
- CERTAINTY_OBSERVED = "Observed" # :nodoc:
63
- CERTAINTY_LIKELY = "Likely" # :nodoc:
64
- CERTAINTY_POSSIBLE = "Possible" # :nodoc:
65
- CERTAINTY_UNLIKELY = "Unlikely" # :nodoc:
66
- CERTAINTY_UNKNOWN = "Unknown" # :nodoc:
67
- # Valid valies for certainty
68
- VALID_CERTAINTIES = [ CERTAINTY_OBSERVED, CERTAINTY_LIKELY,
69
- CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN ]
70
-
71
- XML_ELEMENT_NAME = 'info' # :nodoc:
72
- LANGUAGE_ELEMENT_NAME = 'language' # :nodoc:
73
- CATEGORY_ELEMENT_NAME = 'category' # :nodoc:
74
- EVENT_ELEMENT_NAME = 'event' # :nodoc:
75
- RESPONSE_TYPE_ELEMENT_NAME = 'responseType' # :nodoc:
76
- URGENCY_ELEMENT_NAME = 'urgency' # :nodoc:
77
- SEVERITY_ELEMENT_NAME = 'severity' # :nodoc:
78
- CERTAINTY_ELEMENT_NAME = 'certainty' # :nodoc:
79
- AUDIENCE_ELEMENT_NAME = 'audience' # :nodoc:
80
- EVENT_CODE_ELEMENT_NAME = 'eventCode' # :nodoc:
81
- EFFECTIVE_ELEMENT_NAME = 'effective' # :nodoc:
82
- ONSET_ELEMENT_NAME = 'onset' # :nodoc:
83
- EXPIRES_ELEMENT_NAME = 'expires' # :nodoc:
84
- SENDER_NAME_ELEMENT_NAME = 'sernderName' # :nodoc:
85
- HEADLINE_ELEMENT_NAME = 'headline' # :nodoc:
86
- DESCRIPTION_ELEMENT_NAME = 'description' # :nodoc:
87
- INSTRUCTION_ELEMENT_NAME = 'instruction' # :nodoc:
88
- WEB_ELEMENT_NAME = 'web' # :nodoc:
89
- CONTACT_ELEMENT_NAME = 'contact' # :nodoc:
90
-
91
- XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
92
- LANGUAGE_XPATH = "cap:#{ LANGUAGE_ELEMENT_NAME }" # :nodoc:
93
- EVENT_XPATH = "cap:#{ EVENT_ELEMENT_NAME }" # :nodoc:
94
- URGENCY_XPATH = "cap:#{ URGENCY_ELEMENT_NAME }" # :nodoc:
95
- RESPONSE_TYPE_XPATH = "cap:#{ RESPONSE_TYPE_ELEMENT_NAME }" # :nodoc:
96
- CATEGORY_XPATH = "cap:#{ CATEGORY_ELEMENT_NAME }" # :nodoc:
97
- SEVERITY_XPATH = "cap:#{ SEVERITY_ELEMENT_NAME }" # :nodoc:
98
- CERTAINTY_XPATH = "cap:#{ CERTAINTY_ELEMENT_NAME }" # :nodoc:
99
- AUDIENCE_XPATH = "cap:#{ AUDIENCE_ELEMENT_NAME }" # :nodoc:
100
- EVENT_CODE_XPATH = "cap:#{ EVENT_CODE_ELEMENT_NAME }" # :nodoc:
101
- EFFECTIVE_XPATH = "cap:#{ EFFECTIVE_ELEMENT_NAME }" # :nodoc:
102
- ONSET_XPATH = "cap:#{ ONSET_ELEMENT_NAME }" # :nodoc:
103
- EXPIRES_XPATH = "cap:#{ EXPIRES_ELEMENT_NAME }" # :nodoc:
104
- SENDER_NAME_XPATH = "cap:#{ SENDER_NAME_ELEMENT_NAME }" # :nodoc:
105
- HEADLINE_XPATH = "cap:#{ HEADLINE_ELEMENT_NAME }" # :nodoc:
106
- DESCRIPTION_XPATH = "cap:#{ DESCRIPTION_ELEMENT_NAME }" # :nodoc:
107
- INSTRUCTION_XPATH = "cap:#{ INSTRUCTION_ELEMENT_NAME }" # :nodoc:
108
- WEB_XPATH = "cap:#{ WEB_ELEMENT_NAME }" # :nodoc:
109
- CONTACT_XPATH = "cap:#{ CONTACT_ELEMENT_NAME }" # :nodoc:
110
-
111
- DEFAULT_LANGUAGE = 'en-US'
112
-
113
- validates_presence_of( :event, :urgency, :severity, :certainty )
114
- validates_length_of( :categories, :minimum => 1 )
115
- validates_inclusion_of( :certainty, :allow_nil => true, :in => VALID_CERTAINTIES, :message => "can only be assigned the following values: #{ VALID_CERTAINTIES.join(', ') }")
116
- validates_inclusion_of( :severity, :allow_nil => true, :in => VALID_SEVERITIES, :message => "can only be assigned the following values: #{ VALID_SEVERITIES.join(', ') }" )
117
- validates_inclusion_of( :urgency, :allow_nil => true, :in => VALID_URGENCIES, :message => "can only be assigned the following values: #{ VALID_URGENCIES.join(', ') }" )
118
- validates_inclusion_of_members_of( :response_types, :in => VALID_RESPONSE_TYPES, :allow_blank => true )
119
- validates_inclusion_of_members_of( :categories, :in => VALID_CATEGORIES, :allow_blank => true )
120
- validates_collection_of( :resources, :areas )
121
-
122
- attr_accessor( :event )
123
- # Value can only be one of VALID_URGENCIES
124
- attr_accessor( :urgency )
125
- # Value can only be one of VALID_SEVERITIES
126
- attr_accessor( :severity )
127
- # Value can only be one of VALID_CERTAINTIES
128
- attr_accessor( :certainty )
129
- attr_accessor( :language )
130
- attr_accessor( :audience )
131
- # Effective start time of information
132
- attr_accessor( :effective )
133
- # Expected start of event
134
- attr_accessor( :onset )
135
- # Effective expiry time of information
136
- attr_accessor( :expires )
137
- attr_accessor( :sender_name )
138
- attr_accessor( :headline )
139
- attr_accessor( :description )
140
- attr_accessor( :instruction )
141
- attr_accessor( :web )
142
- attr_accessor( :contact )
143
-
144
- # Collection of textual categories; elements can be one of VALID_CATEGORIES
145
- attr_reader( :categories )
146
- # Collection of textual response types
147
- attr_reader( :response_types )
148
- # Collectoin of EventCode objects
149
- attr_reader( :event_codes )
150
- # Collection of Parameter objects
151
- attr_reader( :parameters )
152
- # Collection of Resource objects
153
- attr_reader( :resources )
154
- # Collection of Area objects
155
- attr_reader( :areas )
156
-
157
- def initialize( attributes = {} )
158
- @language = attributes[ :language ] || DEFAULT_LANGUAGE
159
- @categories = Array( attributes[ :categories ])
160
- @event = attributes [ :event ]
161
- @response_types = Array( attributes[ :response_types ])
162
- @urgency = attributes[ :urgency ]
163
- @severity = attributes[ :severity ]
164
- @certainty = attributes[ :certainty ]
165
- @effective = attributes[ :effective ]
166
- @onset = attributes[ :onset ]
167
- @expires = attributes[ :expires ]
168
- @event_codes = Array( attributes[ :event_codes ])
169
- @sender_name = attributes[ :sender_name ]
170
- @headline = attributes[ :headline ]
171
- @description = attributes[ :description ]
172
- @instruction = attributes[ :instruction ]
173
- @web = attributes[ :web ]
174
- @contact = attributes[ :contact ]
175
- @parameters = Array( attributes[ :parameters ])
176
- @resources = Array( attributes[ :resources ])
177
- @areas = Array( attributes[ :areas ])
178
- end
179
-
180
- def to_xml_element # :nodoc:
181
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
182
- xml_element.add_element( LANGUAGE_ELEMENT_NAME ).add_text( self.language ) if self.language
183
- @categories.each do |category|
184
- xml_element.add_element( CATEGORY_ELEMENT_NAME ).add_text( category )
185
- end
186
- xml_element.add_element( EVENT_ELEMENT_NAME ).add_text( self.event )
187
- @response_types.each do |response_type|
188
- xml_element.add_element( RESPONSE_TYPE_ELEMENT_NAME ).add_text( response_type )
189
- end
190
- xml_element.add_element( URGENCY_ELEMENT_NAME ).add_text( self.urgency )
191
- xml_element.add_element( SEVERITY_ELEMENT_NAME ).add_text( self.severity )
192
- xml_element.add_element( CERTAINTY_ELEMENT_NAME ).add_text( self.certainty )
193
- xml_element.add_element( AUDIENCE_ELEMENT_NAME ).add_text( self.audience ) if self.audience
194
- @event_codes.each do |event_code|
195
- xml_element.add_element( event_code.to_xml_element )
196
- end
197
- xml_element.add_element( EFFECTIVE_ELEMENT_NAME ).add_text( self.effective.to_s_for_cap ) if self.effective
198
- xml_element.add_element( ONSET_ELEMENT_NAME ).add_text( self.onset.to_s_for_cap ) if self.onset
199
- xml_element.add_element( EXPIRES_ELEMENT_NAME ).add_text( self.expires.to_s_for_cap ) if self.expires
200
- xml_element.add_element( SENDER_NAME_ELEMENT_NAME ).add_text( self.sender_name ) if self.sender_name
201
- xml_element.add_element( HEADLINE_ELEMENT_NAME ).add_text( self.headline ) if self.headline
202
- xml_element.add_element( DESCRIPTION_ELEMENT_NAME ).add_text( self.description ) if self.description
203
- xml_element.add_element( INSTRUCTION_ELEMENT_NAME ).add_text( self.instruction ) if self.instruction
204
- xml_element.add_element( WEB_ELEMENT_NAME ).add_text( self.web ) if self.web
205
- xml_element.add_element( CONTACT_ELEMENT_NAME ).add_text( self.contact ) if self.contact
206
- @parameters.each do |parameter|
207
- xml_element.add_element( parameter.to_xml_element )
208
- end
209
- @resources.each do |resource|
210
- xml_element.add_element( resource.to_xml_element )
211
- end
212
- @areas.each do |area|
213
- xml_element.add_element( area.to_xml_element )
214
- end
215
- xml_element
216
- end
217
-
218
- def to_xml # :nodoc:
219
- self.to_xml_element.to_s
220
- end
221
-
222
- def inspect # :nodoc:
223
- info_inspect = <<EOF
224
- Language: #{ self.language }
225
- Categories: #{ self.categories.to_s_for_cap }
226
- Event: #{ self.event }
227
- Response Types: #{ self.response_types.to_s_for_cap }
228
- Urgency: #{ self.urgency }
229
- Severity: #{ self.severity }
230
- Certainty: #{ self.certainty }
231
- Audience: #{ self.audience }
232
- Event Codes: #{ self.event_codes.inspect }
233
- Effective: #{ self.effective }
234
- Onset: #{ self.onset }
235
- Expires: #{ self.expires }
236
- Sender Name: #{ self.sender_name }
237
- Headline: #{ self.headline }
238
- Description:
239
- #{ self.description.to_s.lines.map{ |line| " " + line }.join }
240
- Instruction: #{ self.instruction }
241
- Web: #{ self.web }
242
- Contact: #{ self.contact }
243
- Parameters:
244
- #{ self.parameters.map{ |parameter| parameter.inspect }.join( "\n" )}
245
- Resources:
246
- #{ self.resources.map{ |resource| " " + resource.inspect }.join( "\n" )}
247
- Area:
248
- #{ self.areas.map{ |area| " #{ area }" }.join( "\n" )}
249
- EOF
250
- RCAP.format_lines_for_inspect( 'INFO', info_inspect )
251
- end
252
-
253
- # Returns a string representation of the event of the form
254
- # event(urgency/severity/certainty)
255
- def to_s
256
- "#{ self.event }(#{ self.urgency }/#{ self.severity }/#{ self.certainty })"
257
- end
258
-
259
- def self.from_xml_element( info_xml_element ) # :nodoc:
260
- self.new(
261
- :language => RCAP.xpath_text( info_xml_element, LANGUAGE_XPATH ) || DEFAULT_LANGUAGE,
262
- :categories => RCAP.xpath_match( info_xml_element, CATEGORY_XPATH ).map{ |element| element.text },
263
- :event => RCAP.xpath_text( info_xml_element, EVENT_XPATH ),
264
- :response_types => RCAP.xpath_match( info_xml_element, RESPONSE_TYPE_XPATH ).map{ |element| element.text },
265
- :urgency => RCAP.xpath_text( info_xml_element, URGENCY_XPATH ),
266
- :severity => RCAP.xpath_text( info_xml_element, SEVERITY_XPATH ),
267
- :certainty => RCAP.xpath_text( info_xml_element, CERTAINTY_XPATH ),
268
- :audience => RCAP.xpath_text( info_xml_element, AUDIENCE_XPATH ),
269
- :effective => (( effective = RCAP.xpath_first( info_xml_element, EFFECTIVE_XPATH )) ? DateTime.parse( effective.text ) : nil ),
270
- :onset => (( onset = RCAP.xpath_first( info_xml_element, ONSET_XPATH )) ? DateTime.parse( onset.text ) : nil ),
271
- :expires => (( expires = RCAP.xpath_first( info_xml_element, EXPIRES_XPATH )) ? DateTime.parse( expires.text ) : nil ),
272
- :sender_name => RCAP.xpath_text( info_xml_element, SENDER_NAME_XPATH ),
273
- :headline => RCAP.xpath_text( info_xml_element, HEADLINE_XPATH ),
274
- :description => RCAP.xpath_text( info_xml_element, DESCRIPTION_XPATH ),
275
- :instruction => RCAP.xpath_text( info_xml_element, INSTRUCTION_XPATH ),
276
- :web => RCAP.xpath_text( info_xml_element, WEB_XPATH ),
277
- :contact => RCAP.xpath_text( info_xml_element, CONTACT_XPATH ),
278
- :event_codes => RCAP.xpath_match( info_xml_element, RCAP::EventCode::XPATH ).map{ |element| RCAP::EventCode.from_xml_element( element )},
279
- :parameters => RCAP.xpath_match( info_xml_element, RCAP::Parameter::XPATH ).map{ |element| RCAP::Parameter.from_xml_element( element )},
280
- :resources => RCAP.xpath_match( info_xml_element, RCAP::Resource::XPATH ).map{ |element| RCAP::Resource.from_xml_element( element )},
281
- :areas => RCAP.xpath_match( info_xml_element, RCAP::Area::XPATH ).map{ |element| RCAP::Area.from_xml_element( element )}
282
- )
283
- end
284
-
285
- LANGUAGE_YAML = 'Language' # :nodoc:
286
- CATEGORIES_YAML = 'Categories' # :nodoc:
287
- EVENT_YAML = 'Event' # :nodoc:
288
- RESPONSE_TYPES_YAML = 'Response Types' # :nodoc:
289
- URGENCY_YAML = 'Urgency' # :nodoc:
290
- SEVERITY_YAML = 'Severity' # :nodoc:
291
- CERTAINTY_YAML = 'Certainty' # :nodoc:
292
- AUDIENCE_YAML = 'Audience' # :nodoc:
293
- EFFECTIVE_YAML = 'Effective' # :nodoc:
294
- ONSET_YAML = 'Onset' # :nodoc:
295
- EXPIRES_YAML = 'Expires' # :nodoc:
296
- SENDER_NAME_YAML = 'Sender Name' # :nodoc:
297
- HEADLINE_YAML = 'Headline' # :nodoc:
298
- DESCRIPTION_YAML = 'Description' # :nodoc:
299
- INSTRUCTION_YAML = 'Instruction' # :nodoc:
300
- WEB_YAML = 'Web' # :nodoc:
301
- CONTACT_YAML = 'Contact' # :nodoc:
302
- EVENT_CODES_YAML = 'Event Codes' # :nodoc:
303
- PARAMETERS_YAML = 'Parameters' # :nodoc:
304
- RESOURCES_YAML = 'Resources' # :nodoc:
305
- AREAS_YAML = 'Areas' # :nodoc:
306
-
307
- def to_yaml( options = {} ) # :nodoc:
308
- response_types_yaml = self.response_types
309
- def response_types_yaml.to_yaml_style; :inline; end
310
-
311
- categories_yaml = self.categories
312
- def categories_yaml.to_yaml_style; :inline; end
313
-
314
- parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}
315
-
316
- RCAP.attribute_values_to_hash(
317
- [ LANGUAGE_YAML, self.language ],
318
- [ CATEGORIES_YAML, categories_yaml ],
319
- [ EVENT_YAML, self.event ],
320
- [ RESPONSE_TYPES_YAML, response_types_yaml ],
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 ]
338
- ).to_yaml( options )
339
- end
340
-
341
- def self.from_yaml_data( info_yaml_data ) # :nodoc:
342
- self.new(
343
- :language => info_yaml_data [ LANGUAGE_YAML ],
344
- :categories => info_yaml_data [ CATEGORIES_YAML ],
345
- :event => info_yaml_data [ EVENT_YAML ],
346
- :response_types => info_yaml_data [ RESPONSE_TYPES_YAML ],
347
- :urgency => info_yaml_data [ URGENCY_YAML ],
348
- :severity => info_yaml_data [ SEVERITY_YAML ],
349
- :certainty => info_yaml_data [ CERTAINTY_YAML ],
350
- :audience => info_yaml_data [ AUDIENCE_YAML ],
351
- :effective => ( effective = info_yaml_data[ EFFECTIVE_YAML ]).blank? ? nil : DateTime.parse( effective.to_s ),
352
- :onset => ( onset = info_yaml_data[ ONSET_YAML ]).blank? ? nil : DateTime.parse( onset.to_s ),
353
- :expires => ( expires = info_yaml_data[ EXPIRES_YAML ]).blank? ? nil : DateTime.parse( expires.to_s ),
354
- :sender_name => info_yaml_data [ SENDER_NAME_YAML ],
355
- :headline => info_yaml_data [ HEADLINE_YAML ],
356
- :description => info_yaml_data [ DESCRIPTION_YAML ],
357
- :instruction => info_yaml_data [ INSTRUCTION_YAML ],
358
- :web => info_yaml_data [ WEB_YAML ],
359
- :contact => info_yaml_data [ CONTACT_YAML ],
360
- :event_codes => Array( info_yaml_data [ EVENT_CODES_YAML ]).map{ |name,value| RCAP::EventCode.new( :name => name, :value => value )},
361
- :parameters => Array( info_yaml_data [ PARAMETERS_YAML ]).map{ |parameter_yaml_data| RCAP::Parameter.new( :name => name, :value => value )},
362
- :resources => Array( info_yaml_data [ RESOURCES_YAML ]).map{ |resource_yaml_data| RCAP::Resource.from_yaml_data( resource_yaml_data )},
363
- :areas => Array( info_yaml_data [ AREAS_YAML ]).map{ |area_yaml_data| RCAP::Area.from_yaml_data( area_yaml_data )}
364
- )
365
- end
366
-
367
- LANGUAGE_KEY = 'language' # :nodoc:
368
- CATEGORIES_KEY = 'categories' # :nodoc:
369
- EVENT_KEY = 'event' # :nodoc:
370
- RESPONSE_TYPES_KEY = 'response_types' # :nodoc:
371
- URGENCY_KEY = 'urgency' # :nodoc:
372
- SEVERITY_KEY = 'severity' # :nodoc:
373
- CERTAINTY_KEY = 'certainty' # :nodoc:
374
- AUDIENCE_KEY = 'audience' # :nodoc:
375
- EFFECTIVE_KEY = 'effective' # :nodoc:
376
- ONSET_KEY = 'onset' # :nodoc:
377
- EXPIRES_KEY = 'expires' # :nodoc:
378
- SENDER_NAME_KEY = 'sender_name' # :nodoc:
379
- HEADLINE_KEY = 'headline' # :nodoc:
380
- DESCRIPTION_KEY = 'description' # :nodoc:
381
- INSTRUCTION_KEY = 'instruction' # :nodoc:
382
- WEB_KEY = 'web' # :nodoc:
383
- CONTACT_KEY = 'contact' # :nodoc:
384
- RESOURCES_KEY = 'resources' # :nodoc:
385
- EVENT_CODES_KEY = 'event_codes' # :nodoc:
386
- PARAMETERS_KEY = 'parameters' # :nodoc:
387
- AREAS_KEY = 'areas' # :nodoc:
388
-
389
- def to_h # :nodoc:
390
- RCAP.attribute_values_to_hash( [ LANGUAGE_KEY, self.language ],
391
- [ CATEGORIES_KEY, self.categories ],
392
- [ EVENT_KEY, self.event ],
393
- [ RESPONSE_TYPES_KEY, self.response_types ],
394
- [ URGENCY_KEY, self.urgency ],
395
- [ SEVERITY_KEY, self.severity ],
396
- [ CERTAINTY_KEY, self.certainty ],
397
- [ AUDIENCE_KEY, self.audience ],
398
- [ EFFECTIVE_KEY, RCAP.to_s_for_cap( self.effective )],
399
- [ ONSET_KEY, RCAP.to_s_for_cap( self.onset )],
400
- [ EXPIRES_KEY, RCAP.to_s_for_cap( self.expires )],
401
- [ SENDER_NAME_KEY, self.sender_name ],
402
- [ HEADLINE_KEY, self.headline ],
403
- [ DESCRIPTION_KEY, self.description ],
404
- [ INSTRUCTION_KEY, self.instruction ],
405
- [ WEB_KEY, self.web ],
406
- [ CONTACT_KEY, self.contact ],
407
- [ RESOURCES_KEY, self.resources.map{ |resource| resource.to_h } ],
408
- [ EVENT_CODES_KEY, self.event_codes.map{ |event_code| event_code.to_h } ],
409
- [ PARAMETERS_KEY, self.parameters.map{ |parameter| parameter.to_h } ],
410
- [ AREAS_KEY, self.areas.map{ |area| area.to_h }])
411
- end
412
-
413
- def self.from_h( info_hash ) # :nodoc:
414
- self.new( :language => info_hash[ LANGUAGE_KEY ],
415
- :categories => info_hash[ CATEGORIES_KEY ],
416
- :event => info_hash[ EVENT_KEY ],
417
- :response_types => info_hash[ RESPONSE_TYPES_KEY ],
418
- :urgency => info_hash[ URGENCY_KEY ],
419
- :severity => info_hash[ SEVERITY_KEY ],
420
- :certainty => info_hash[ CERTAINTY_KEY ],
421
- :audience => info_hash[ AUDIENCE_KEY ],
422
- :effective => RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ]),
423
- :onset => RCAP.parse_datetime( info_hash[ ONSET_KEY ]),
424
- :expires => RCAP.parse_datetime( info_hash[ EXPIRES_KEY ]),
425
- :sender_name => info_hash[ SENDER_NAME_KEY ],
426
- :headline => info_hash[ HEADLINE_KEY ],
427
- :description => info_hash[ DESCRIPTION_KEY ],
428
- :instruction => info_hash[ INSTRUCTION_KEY ],
429
- :web => info_hash[ WEB_KEY ],
430
- :contact => info_hash[ CONTACT_KEY ],
431
- :resources => Array( info_hash[ RESOURCES_KEY ]).map{ |resource_hash| RCAP::Resource.from_h( resource_hash ) },
432
- :event_codes => Array( info_hash[ EVENT_CODES_KEY ]).map{ |event_code_hash| RCAP::EventCode.from_h( event_code_hash )},
433
- :parameters => Array( info_hash[ PARAMETERS_KEY ]).map{ |parameter_hash| RCAP::Parameter.from_h( parameter_hash )},
434
- :areas => Array( info_hash[ AREAS_KEY ]).map{ |area_hash| RCAP::Area.from_h( area_hash )})
435
- end
436
- end
437
- end