rcap 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/{CHANGELOG.rdoc → CHANGELOG.md} +26 -20
  2. data/README.md +259 -0
  3. data/Rakefile +8 -7
  4. data/lib/extensions/array.rb +7 -1
  5. data/lib/extensions/date_time.rb +5 -1
  6. data/lib/extensions/string.rb +14 -1
  7. data/lib/extensions/time.rb +5 -1
  8. data/lib/rcap.rb +1 -1
  9. data/lib/rcap/alert.rb +24 -10
  10. data/lib/rcap/cap_1_0/alert.rb +232 -166
  11. data/lib/rcap/cap_1_0/area.rb +100 -67
  12. data/lib/rcap/cap_1_0/circle.rb +47 -22
  13. data/lib/rcap/cap_1_0/event_code.rb +3 -2
  14. data/lib/rcap/cap_1_0/geocode.rb +3 -2
  15. data/lib/rcap/cap_1_0/info.rb +265 -202
  16. data/lib/rcap/cap_1_0/parameter.rb +43 -20
  17. data/lib/rcap/cap_1_0/point.rb +23 -9
  18. data/lib/rcap/cap_1_0/polygon.rb +37 -19
  19. data/lib/rcap/cap_1_0/resource.rb +77 -55
  20. data/lib/rcap/cap_1_1/alert.rb +222 -156
  21. data/lib/rcap/cap_1_1/area.rb +100 -67
  22. data/lib/rcap/cap_1_1/circle.rb +49 -22
  23. data/lib/rcap/cap_1_1/event_code.rb +3 -2
  24. data/lib/rcap/cap_1_1/geocode.rb +3 -2
  25. data/lib/rcap/cap_1_1/info.rb +281 -217
  26. data/lib/rcap/cap_1_1/parameter.rb +35 -16
  27. data/lib/rcap/cap_1_1/point.rb +23 -9
  28. data/lib/rcap/cap_1_1/polygon.rb +38 -20
  29. data/lib/rcap/cap_1_1/resource.rb +106 -65
  30. data/lib/rcap/cap_1_2/alert.rb +224 -158
  31. data/lib/rcap/cap_1_2/area.rb +100 -67
  32. data/lib/rcap/cap_1_2/circle.rb +49 -24
  33. data/lib/rcap/cap_1_2/event_code.rb +3 -2
  34. data/lib/rcap/cap_1_2/geocode.rb +3 -2
  35. data/lib/rcap/cap_1_2/info.rb +285 -219
  36. data/lib/rcap/cap_1_2/parameter.rb +39 -19
  37. data/lib/rcap/cap_1_2/point.rb +23 -9
  38. data/lib/rcap/cap_1_2/polygon.rb +37 -20
  39. data/lib/rcap/cap_1_2/resource.rb +107 -67
  40. data/lib/rcap/config.rb +4 -0
  41. data/lib/rcap/utilities.rb +55 -2
  42. data/lib/rcap/validations.rb +2 -2
  43. data/lib/rcap/version.rb +1 -1
  44. data/rcap.gemspec +2 -2
  45. data/spec/cap_1_0/parameter_spec.rb +5 -1
  46. data/spec/cap_1_1/resource_spec.rb +6 -0
  47. data/spec/cap_1_2/alert_spec.rb +8 -0
  48. data/spec/cap_1_2/resource_spec.rb +8 -2
  49. metadata +11 -10
  50. data/README.rdoc +0 -247
  51. data/lib/config.rb +0 -2
@@ -14,82 +14,58 @@ module RCAP
14
14
  XMLNS = "urn:oasis:names:tc:emergency:cap:1.2"
15
15
  CAP_VERSION = "1.2"
16
16
 
17
- STATUS_ACTUAL = "Actual" # :nodoc:
18
- STATUS_EXERCISE = "Exercise" # :nodoc:
19
- STATUS_SYSTEM = "System" # :nodoc:
20
- STATUS_TEST = "Test" # :nodoc:
21
- STATUS_DRAFT = "Draft" # :nodoc:
17
+ STATUS_ACTUAL = "Actual"
18
+ STATUS_EXERCISE = "Exercise"
19
+ STATUS_SYSTEM = "System"
20
+ STATUS_TEST = "Test"
21
+ STATUS_DRAFT = "Draft"
22
22
  # Valid values for status
23
23
  VALID_STATUSES = [ STATUS_ACTUAL, STATUS_EXERCISE, STATUS_SYSTEM, STATUS_TEST, STATUS_DRAFT ]
24
24
 
25
- MSG_TYPE_ALERT = "Alert" # :nodoc:
26
- MSG_TYPE_UPDATE = "Update" # :nodoc:
27
- MSG_TYPE_CANCEL = "Cancel" # :nodoc:
28
- MSG_TYPE_ACK = "Ack" # :nodoc:
29
- MSG_TYPE_ERROR = "Error" # :nodoc:
25
+ MSG_TYPE_ALERT = "Alert"
26
+ MSG_TYPE_UPDATE = "Update"
27
+ MSG_TYPE_CANCEL = "Cancel"
28
+ MSG_TYPE_ACK = "Ack"
29
+ MSG_TYPE_ERROR = "Error"
30
30
  # Valid values for msg_type
31
31
  VALID_MSG_TYPES = [ MSG_TYPE_ALERT, MSG_TYPE_UPDATE, MSG_TYPE_CANCEL, MSG_TYPE_ACK, MSG_TYPE_ERROR ]
32
32
 
33
- SCOPE_PUBLIC = "Public" # :nodoc:
34
- SCOPE_RESTRICTED = "Restricted" # :nodoc:
35
- SCOPE_PRIVATE = "Private" # :nodoc:
33
+ SCOPE_PUBLIC = "Public"
34
+ SCOPE_RESTRICTED = "Restricted"
35
+ SCOPE_PRIVATE = "Private"
36
36
  # Valid values for scope
37
37
  VALID_SCOPES = [ SCOPE_PUBLIC, SCOPE_PRIVATE, SCOPE_RESTRICTED ]
38
38
 
39
- XML_ELEMENT_NAME = 'alert' # :nodoc:
40
- IDENTIFIER_ELEMENT_NAME = 'identifier' # :nodoc:
41
- SENDER_ELEMENT_NAME = 'sender' # :nodoc:
42
- SENT_ELEMENT_NAME = 'sent' # :nodoc:
43
- STATUS_ELEMENT_NAME = 'status' # :nodoc:
44
- MSG_TYPE_ELEMENT_NAME = 'msgType' # :nodoc:
45
- SOURCE_ELEMENT_NAME = 'source' # :nodoc:
46
- SCOPE_ELEMENT_NAME = 'scope' # :nodoc:
47
- RESTRICTION_ELEMENT_NAME = 'restriction' # :nodoc:
48
- ADDRESSES_ELEMENT_NAME = 'addresses' # :nodoc:
49
- CODE_ELEMENT_NAME = 'code' # :nodoc:
50
- NOTE_ELEMENT_NAME = 'note' # :nodoc:
51
- REFERENCES_ELEMENT_NAME = 'references' # :nodoc:
52
- INCIDENTS_ELEMENT_NAME = 'incidents' # :nodoc:
53
-
54
- XPATH = 'cap:alert' # :nodoc:
55
- IDENTIFIER_XPATH = "cap:#{ IDENTIFIER_ELEMENT_NAME }" # :nodoc:
56
- SENDER_XPATH = "cap:#{ SENDER_ELEMENT_NAME }" # :nodoc:
57
- SENT_XPATH = "cap:#{ SENT_ELEMENT_NAME }" # :nodoc:
58
- STATUS_XPATH = "cap:#{ STATUS_ELEMENT_NAME }" # :nodoc:
59
- MSG_TYPE_XPATH = "cap:#{ MSG_TYPE_ELEMENT_NAME }" # :nodoc:
60
- SOURCE_XPATH = "cap:#{ SOURCE_ELEMENT_NAME }" # :nodoc:
61
- SCOPE_XPATH = "cap:#{ SCOPE_ELEMENT_NAME }" # :nodoc:
62
- RESTRICTION_XPATH = "cap:#{ RESTRICTION_ELEMENT_NAME }" # :nodoc:
63
- ADDRESSES_XPATH = "cap:#{ ADDRESSES_ELEMENT_NAME }" # :nodoc:
64
- CODE_XPATH = "cap:#{ CODE_ELEMENT_NAME }" # :nodoc:
65
- NOTE_XPATH = "cap:#{ NOTE_ELEMENT_NAME }" # :nodoc:
66
- REFERENCES_XPATH = "cap:#{ REFERENCES_ELEMENT_NAME }" # :nodoc:
67
- INCIDENTS_XPATH = "cap:#{ INCIDENTS_ELEMENT_NAME }" # :nodoc:
68
-
69
- # If not set a UUID will be set by default
39
+ # @return [String] If not set a UUID will be set by default
70
40
  attr_accessor( :identifier)
41
+ # @return [String]
71
42
  attr_accessor( :sender )
72
- # Sent Time - If not set will value will be time of creation.
43
+ # @return [DateTime] If not set will value will be time of creation.
73
44
  attr_accessor( :sent )
74
- # Value can only be one of VALID_STATUSES
45
+ # @return [String] Can only be one of {VALID_STATUSES}
75
46
  attr_accessor( :status )
76
- # Value can only be one of VALID_MSG_TYPES
47
+ # @return [String] Can only be one of {VALID_MSG_TYPES}
77
48
  attr_accessor( :msg_type )
78
- # Value can only be one of VALID_SCOPES
49
+ # @return [String]
50
+ attr_accessor( :password )
51
+ # @return [String] Can only be one of {VALID_SCOPES}
79
52
  attr_accessor( :scope )
53
+ # @return [String]
80
54
  attr_accessor( :source )
81
- # Depends on scope being SCOPE_RESTRICTED.
55
+ # @return [String ] Depends on scope being {SCOPE_RESTRICTED}
82
56
  attr_accessor( :restriction )
57
+ # @return [String]
83
58
  attr_accessor( :note )
84
59
 
85
- # Collection of address strings. Depends on scope being SCOPE_PRIVATE.
60
+ # @return [Array<String>] Collection of address strings. Depends on scope being {SCOPE_PRIVATE}
86
61
  attr_reader( :addresses )
62
+ # @return [Array<String>]
87
63
  attr_reader( :codes )
88
- # Collection of reference strings - see Alert#to_reference
64
+ # @return [Array<String>] See {#to_reference}
89
65
  attr_reader( :references)
90
- # Collection of incident strings
66
+ # @return [Array<String>] Collection of incident strings
91
67
  attr_reader( :incidents )
92
- # Collection of Info objects
68
+ # @return [Array<Info>] Collection of {Info} objects
93
69
  attr_reader( :infos )
94
70
 
95
71
  validates_presence_of( :identifier, :sender, :sent, :status, :msg_type, :scope )
@@ -106,6 +82,28 @@ module RCAP
106
82
 
107
83
  validates_collection_of( :infos )
108
84
 
85
+ # @example
86
+ # Alert.new( sender: 'disaster_management@cape_town.municipal.za',
87
+ # sent: Date.today,
88
+ # status: Alert::STATUS_ACTUAL,
89
+ # msg_type: Alert::MSG_TYPE_ALERT,
90
+ # scope: Alert::SCOPE_PUBLIC )
91
+ #
92
+ # @param [Hash] attributes
93
+ # @option attributes [String] :identifier Unique identifier - autogenerated if not given
94
+ # @option attributes [String] :sender
95
+ # @option attributes [DateTime] :sent
96
+ # @option attributes [String] :status A member of {VALID_STATUSES}
97
+ # @option attributes [String] :msg_type A member of {VALID_MSG_TYPES}
98
+ # @option attributes [String] :password
99
+ # @option attributes [String] :scope A member of {VALID_SCOPES}
100
+ # @option attributes [String] :source
101
+ # @option attributes [String] :restriction
102
+ # @option attributes [Array<String>] :addresses
103
+ # @option attributes [Array<String>] :codes
104
+ # @option attributes [Array<String>] :references see {#to_reference}
105
+ # @option attributes [Array<String>] :incidents
106
+ # @option attributes [Array<Info>] :infos
109
107
  def initialize( attributes = {})
110
108
  @identifier = attributes[ :identifier ] || RCAP.generate_identifier
111
109
  @sender = attributes[ :sender ]
@@ -122,45 +120,65 @@ module RCAP
122
120
  @infos = Array( attributes[ :infos ])
123
121
  end
124
122
 
125
- # Creates a new Info object and adds it to the infos array. The
126
- # info_attributes are passed as a parameter to Info.new.
127
- def add_info( info_attributes = {})
123
+ # Creates a new {Info} object and adds it to the {#infos array}.
124
+ #
125
+ # @see Info#initialize
126
+ # @param [Hash] info_attributes Info attributes - see {Info#initialize}
127
+ # @return [Info]
128
+ def add_info( info_attributes = {})
128
129
  info = Info.new( info_attributes )
129
- self.infos << info
130
+ @infos << info
130
131
  info
131
132
  end
132
133
 
133
- def to_xml_element #:nodoc:
134
+ XML_ELEMENT_NAME = 'alert'
135
+ IDENTIFIER_ELEMENT_NAME = 'identifier'
136
+ SENDER_ELEMENT_NAME = 'sender'
137
+ SENT_ELEMENT_NAME = 'sent'
138
+ STATUS_ELEMENT_NAME = 'status'
139
+ MSG_TYPE_ELEMENT_NAME = 'msgType'
140
+ SOURCE_ELEMENT_NAME = 'source'
141
+ SCOPE_ELEMENT_NAME = 'scope'
142
+ RESTRICTION_ELEMENT_NAME = 'restriction'
143
+ ADDRESSES_ELEMENT_NAME = 'addresses'
144
+ CODE_ELEMENT_NAME = 'code'
145
+ NOTE_ELEMENT_NAME = 'note'
146
+ REFERENCES_ELEMENT_NAME = 'references'
147
+ INCIDENTS_ELEMENT_NAME = 'incidents'
148
+
149
+ # @return [REXML::Element]
150
+ def to_xml_element
134
151
  xml_element = REXML::Element.new( XML_ELEMENT_NAME )
135
152
  xml_element.add_namespace( XMLNS )
136
- xml_element.add_element( IDENTIFIER_ELEMENT_NAME ).add_text( self.identifier ) if self.identifier
137
- xml_element.add_element( SENDER_ELEMENT_NAME ).add_text( self.sender ) if self.sender
138
- xml_element.add_element( SENT_ELEMENT_NAME ).add_text( self.sent.to_s_for_cap ) if self.sent
139
- xml_element.add_element( STATUS_ELEMENT_NAME ).add_text( self.status ) if self.status
140
- xml_element.add_element( MSG_TYPE_ELEMENT_NAME ).add_text( self.msg_type ) if self.msg_type
141
- xml_element.add_element( SOURCE_ELEMENT_NAME ).add_text( self.source ) if self.source
142
- xml_element.add_element( SCOPE_ELEMENT_NAME ).add_text( self.scope ) if self.scope
143
- xml_element.add_element( RESTRICTION_ELEMENT_NAME ).add_text( self.restriction ) if self.restriction
144
- unless self.addresses.empty?
145
- xml_element.add_element( ADDRESSES_ELEMENT_NAME ).add_text( self.addresses.to_s_for_cap )
153
+ xml_element.add_element( IDENTIFIER_ELEMENT_NAME ).add_text( @identifier ) if @identifier
154
+ xml_element.add_element( SENDER_ELEMENT_NAME ).add_text( @sender ) if @sender
155
+ xml_element.add_element( SENT_ELEMENT_NAME ).add_text( @sent.to_s_for_cap ) if @sent
156
+ xml_element.add_element( STATUS_ELEMENT_NAME ).add_text( @status ) if @status
157
+ xml_element.add_element( MSG_TYPE_ELEMENT_NAME ).add_text( @msg_type ) if @msg_type
158
+ xml_element.add_element( SOURCE_ELEMENT_NAME ).add_text( @source ) if @source
159
+ xml_element.add_element( SCOPE_ELEMENT_NAME ).add_text( @scope ) if @scope
160
+ xml_element.add_element( RESTRICTION_ELEMENT_NAME ).add_text( @restriction ) if @restriction
161
+ if @addresses.any?
162
+ xml_element.add_element( ADDRESSES_ELEMENT_NAME ).add_text( @addresses.to_s_for_cap )
146
163
  end
147
- self.codes.each do |code|
164
+ @codes.each do |code|
148
165
  xml_element.add_element( CODE_ELEMENT_NAME ).add_text( code )
149
166
  end
150
- xml_element.add_element( NOTE_ELEMENT_NAME ).add_text( self.note ) if self.note
151
- unless self.references.empty?
152
- xml_element.add_element( REFERENCES_ELEMENT_NAME ).add_text( self.references.join( ' ' ))
167
+ xml_element.add_element( NOTE_ELEMENT_NAME ).add_text( @note ) if @note
168
+ if @references.any?
169
+ xml_element.add_element( REFERENCES_ELEMENT_NAME ).add_text( @references.join( ' ' ))
153
170
  end
154
- unless self.incidents.empty?
155
- xml_element.add_element( INCIDENTS_ELEMENT_NAME ).add_text( self.incidents.join( ' ' ))
171
+ if @incidents.any?
172
+ xml_element.add_element( INCIDENTS_ELEMENT_NAME ).add_text( @incidents.join( ' ' ))
156
173
  end
157
- self.infos.each do |info|
174
+ @infos.each do |info|
158
175
  xml_element.add_element( info.to_xml_element )
159
176
  end
160
177
  xml_element
161
178
  end
162
179
 
163
- def to_xml_document #:nodoc:
180
+ # @return [REXML::Document]
181
+ def to_xml_document
164
182
  xml_document = REXML::Document.new
165
183
  xml_document.add( REXML::XMLDecl.new )
166
184
  xml_document.add( self.to_xml_element )
@@ -168,10 +186,13 @@ module RCAP
168
186
  end
169
187
 
170
188
  # Returns a string containing the XML representation of the alert.
189
+ #
190
+ # @param [true,false] pretty_print Pretty print output
191
+ # @return [String]
171
192
  def to_xml( pretty_print = false )
172
193
  if pretty_print
173
194
  xml_document = ""
174
- XML_PRETTY_PRINTER.write( self.to_xml_document, xml_document )
195
+ RCAP::XML_PRETTY_PRINTER.write( self.to_xml_document, xml_document )
175
196
  xml_document
176
197
  else
177
198
  self.to_xml_document.to_s
@@ -180,39 +201,61 @@ module RCAP
180
201
 
181
202
  # Returns a string representation of the alert suitable for usage as a reference in a CAP message of the form
182
203
  # sender,identifier,sent
204
+ #
205
+ # @return [String]
183
206
  def to_reference
184
- "#{ self.sender },#{ self.identifier },#{ self.sent }"
207
+ "#{ @sender },#{ @identifier },#{ @sent }"
185
208
  end
186
209
 
187
- def inspect # :nodoc:
210
+ # @return [String]
211
+ def inspect
188
212
  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 }",
213
+ "Identifier: #{ @identifier }",
214
+ "Sender: #{ @sender }",
215
+ "Sent: #{ @sent }",
216
+ "Status: #{ @status }",
217
+ "Message Type: #{ @msg_type }",
218
+ "Source: #{ @source }",
219
+ "Scope: #{ @scope }",
220
+ "Restriction: #{ @restriction }",
221
+ "Addresses: #{ @addresses.to_s_for_cap }",
198
222
  "Codes:",
199
- self.codes.map{ |code| " #{ code }" }.join("\n"),
200
- "Note: #{ self.note }",
201
- "References: #{ self.references.join( ' ' )}",
202
- "Incidents: #{ self.incidents.join( ' ')}",
223
+ @codes.map{ |code| " " + code }.join("\n")+"",
224
+ "Note: #{ @note }",
225
+ "References: #{ @references.join( ' ' )}",
226
+ "Incidents: #{ @incidents.join( ' ')}",
203
227
  "Information:",
204
- self.infos.map{ |info| " " + info.to_s }.join( "\n" )].join( "\n" )
228
+ @infos.map{ |info| " " + info.to_s }.join( "\n" )].join( "\n" )
205
229
  RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
206
230
  end
207
231
 
208
232
  # Returns a string representation of the alert of the form
209
233
  # sender/identifier/sent
210
- # See Alert#to_reference for another string representation suitable as a CAP reference.
234
+ # See {#to_reference} for another string representation suitable as a CAP reference.
235
+ #
236
+ # @return [String]
211
237
  def to_s
212
- "#{ self.sender }/#{ self.identifier }/#{ self.sent }"
238
+ "#{ @sender }/#{ @identifier }/#{ @sent }"
213
239
  end
214
240
 
215
- def self.from_xml_element( alert_xml_element ) # :nodoc:
241
+ XPATH = 'cap:alert'
242
+ IDENTIFIER_XPATH = "cap:#{ IDENTIFIER_ELEMENT_NAME }"
243
+ SENDER_XPATH = "cap:#{ SENDER_ELEMENT_NAME }"
244
+ SENT_XPATH = "cap:#{ SENT_ELEMENT_NAME }"
245
+ STATUS_XPATH = "cap:#{ STATUS_ELEMENT_NAME }"
246
+ MSG_TYPE_XPATH = "cap:#{ MSG_TYPE_ELEMENT_NAME }"
247
+ SOURCE_XPATH = "cap:#{ SOURCE_ELEMENT_NAME }"
248
+ SCOPE_XPATH = "cap:#{ SCOPE_ELEMENT_NAME }"
249
+ RESTRICTION_XPATH = "cap:#{ RESTRICTION_ELEMENT_NAME }"
250
+ ADDRESSES_XPATH = "cap:#{ ADDRESSES_ELEMENT_NAME }"
251
+ CODE_XPATH = "cap:#{ CODE_ELEMENT_NAME }"
252
+ NOTE_XPATH = "cap:#{ NOTE_ELEMENT_NAME }"
253
+ REFERENCES_XPATH = "cap:#{ REFERENCES_ELEMENT_NAME }"
254
+ INCIDENTS_XPATH = "cap:#{ INCIDENTS_ELEMENT_NAME }"
255
+
256
+ # @param [REXML::Element] alert_xml_element
257
+ # @return [Alert]
258
+ def self.from_xml_element( alert_xml_element )
216
259
  self.new( :identifier => RCAP.xpath_text( alert_xml_element, IDENTIFIER_XPATH, Alert::XMLNS ),
217
260
  :sender => RCAP.xpath_text( alert_xml_element, SENDER_XPATH, Alert::XMLNS ),
218
261
  :sent => (( sent = RCAP.xpath_first( alert_xml_element, SENT_XPATH, Alert::XMLNS )) ? DateTime.parse( sent.text ) : nil ),
@@ -229,58 +272,70 @@ module RCAP
229
272
  :infos => RCAP.xpath_match( alert_xml_element, Info::XPATH, Alert::XMLNS ).map{ |element| Info.from_xml_element( element )})
230
273
  end
231
274
 
232
- def self.from_xml_document( xml_document ) # :nodoc:
275
+ # @param [REXML::Document] xml_document
276
+ # @return [Alert]
277
+ def self.from_xml_document( xml_document )
233
278
  self.from_xml_element( xml_document.root )
234
279
  end
235
280
 
236
281
  # Initialise an Alert object from an XML string. Any object that is a subclass of IO (e.g. File) can be passed in.
282
+ #
283
+ # @param [String] xml
284
+ # @return [Alert]
237
285
  def self.from_xml( xml )
238
286
  self.from_xml_document( REXML::Document.new( xml ))
239
287
  end
240
288
 
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:
289
+ CAP_VERSION_YAML = "CAP Version"
290
+ IDENTIFIER_YAML = "Identifier"
291
+ SENDER_YAML = "Sender"
292
+ SENT_YAML = "Sent"
293
+ STATUS_YAML = "Status"
294
+ MSG_TYPE_YAML = "Message Type"
295
+ SOURCE_YAML = "Source"
296
+ SCOPE_YAML = "Scope"
297
+ RESTRICTION_YAML = "Restriction"
298
+ ADDRESSES_YAML = "Addresses"
299
+ CODES_YAML = "Codes"
300
+ NOTE_YAML = "Note"
301
+ REFERENCES_YAML = "References"
302
+ INCIDENTS_YAML = "Incidents"
303
+ INFOS_YAML = "Information"
256
304
 
257
305
  # Returns a string containing the YAML representation of the alert.
306
+ #
307
+ # @return [String]
258
308
  def to_yaml( options = {} )
259
309
  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 ]
310
+ [ CAP_VERSION_YAML, CAP_VERSION ],
311
+ [ IDENTIFIER_YAML, @identifier ],
312
+ [ SENDER_YAML, @sender ],
313
+ [ SENT_YAML, @sent ],
314
+ [ STATUS_YAML, @status ],
315
+ [ MSG_TYPE_YAML, @msg_type ],
316
+ [ SOURCE_YAML, @source ],
317
+ [ SCOPE_YAML, @scope ],
318
+ [ RESTRICTION_YAML, @restriction ],
319
+ [ ADDRESSES_YAML, @addresses ],
320
+ [ CODES_YAML, @codes ],
321
+ [ NOTE_YAML, @note ],
322
+ [ REFERENCES_YAML, @references ],
323
+ [ INCIDENTS_YAML, @incidents ],
324
+ [ INFOS_YAML, @infos ]
275
325
  ).to_yaml( options )
276
326
  end
277
327
 
278
328
  # Initialise an Alert object from a YAML string. Any object that is a subclass of IO (e.g. File) can be passed in.
329
+ #
330
+ # @param [String] yaml
331
+ # @return [Alert]
279
332
  def self.from_yaml( yaml )
280
333
  self.from_yaml_data( YAML.load( yaml ))
281
334
  end
282
335
 
283
- def self.from_yaml_data( alert_yaml_data ) # :nodoc:
336
+ # @param [Hash] yaml_data
337
+ # @return [Alert]
338
+ def self.from_yaml_data( alert_yaml_data )
284
339
  Alert.new(
285
340
  :identifier => alert_yaml_data[ IDENTIFIER_YAML ],
286
341
  :sender => alert_yaml_data[ SENDER_YAML ],
@@ -299,42 +354,47 @@ module RCAP
299
354
  )
300
355
  end
301
356
 
302
- CAP_VERSION_KEY = 'cap_version' # :nodoc:
303
- IDENTIFIER_KEY = 'identifier' # :nodoc:
304
- SENDER_KEY = 'sender' # :nodoc:
305
- SENT_KEY = 'sent' # :nodoc:
306
- STATUS_KEY = 'status' # :nodoc:
307
- MSG_TYPE_KEY = 'msg_type' # :nodoc:
308
- SOURCE_KEY = 'source' # :nodoc:
309
- SCOPE_KEY = 'scope' # :nodoc:
310
- RESTRICTION_KEY = 'restriction' # :nodoc:
311
- ADDRESSES_KEY = 'addresses' # :nodoc:
312
- CODES_KEY = 'codes' # :nodoc:
313
- NOTE_KEY = 'note' # :nodoc:
314
- REFERENCES_KEY = 'references' # :nodoc:
315
- INCIDENTS_KEY = 'incidents' # :nodoc:
316
- INFOS_KEY = 'infos' # :nodoc:
357
+ CAP_VERSION_KEY = 'cap_version'
358
+ IDENTIFIER_KEY = 'identifier'
359
+ SENDER_KEY = 'sender'
360
+ SENT_KEY = 'sent'
361
+ STATUS_KEY = 'status'
362
+ MSG_TYPE_KEY = 'msg_type'
363
+ SOURCE_KEY = 'source'
364
+ SCOPE_KEY = 'scope'
365
+ RESTRICTION_KEY = 'restriction'
366
+ ADDRESSES_KEY = 'addresses'
367
+ CODES_KEY = 'codes'
368
+ NOTE_KEY = 'note'
369
+ REFERENCES_KEY = 'references'
370
+ INCIDENTS_KEY = 'incidents'
371
+ INFOS_KEY = 'infos'
317
372
 
318
373
  # Returns a Hash representation of an Alert object
374
+ #
375
+ # @return [Hash]
319
376
  def to_h
320
377
  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 }])
378
+ [ IDENTIFIER_KEY, @identifier ],
379
+ [ SENDER_KEY, @sender ],
380
+ [ SENT_KEY, RCAP.to_s_for_cap( @sent )],
381
+ [ STATUS_KEY, @status ],
382
+ [ MSG_TYPE_KEY, @msg_type ],
383
+ [ SOURCE_KEY, @source ],
384
+ [ SCOPE_KEY, @scope ],
385
+ [ RESTRICTION_KEY, @restriction ],
386
+ [ ADDRESSES_KEY, @addresses ],
387
+ [ CODES_KEY, @codes ],
388
+ [ NOTE_KEY, @note ],
389
+ [ REFERENCES_KEY, @references ],
390
+ [ INCIDENTS_KEY, @incidents ],
391
+ [ INFOS_KEY, @infos.map{ |info| info.to_h }])
335
392
  end
336
393
 
337
394
  # Initialises an Alert object from a Hash produced by Alert#to_h
395
+ #
396
+ # @param [Hash] alert_hash
397
+ # @return [Alert]
338
398
  def self.from_h( alert_hash )
339
399
  self.new(
340
400
  :identifier => alert_hash[ IDENTIFIER_KEY ],
@@ -354,6 +414,9 @@ module RCAP
354
414
  end
355
415
 
356
416
  # Returns a JSON string representation of an Alert object
417
+ #
418
+ # @param [true,false] pretty_print
419
+ # @return [String]
357
420
  def to_json( pretty_print = false )
358
421
  if pretty_print
359
422
  JSON.pretty_generate( self.to_h )
@@ -362,7 +425,10 @@ module RCAP
362
425
  end
363
426
  end
364
427
 
365
- # Initiialises an Alert object from a JSON string produced by Alert#to_json
428
+ # Initialises an Alert object from a JSON string produced by Alert#to_json
429
+ #
430
+ # @param [String] json_string
431
+ # @return [Alert]
366
432
  def self.from_json( json_string )
367
433
  self.from_h( JSON.parse( json_string ))
368
434
  end