rcap 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +78 -151
- data/Rakefile +1 -1
- data/lib/rcap/alert.rb +2 -2
- data/lib/rcap/base/alert.rb +446 -0
- data/lib/rcap/base/area.rb +228 -0
- data/lib/rcap/base/circle.rb +121 -0
- data/lib/rcap/base/event_code.rb +6 -0
- data/lib/rcap/base/geocode.rb +6 -0
- data/lib/rcap/base/info.rb +498 -0
- data/lib/rcap/base/parameter.rb +88 -0
- data/lib/rcap/base/point.rb +87 -0
- data/lib/rcap/base/polygon.rb +120 -0
- data/lib/rcap/base/resource.rb +168 -0
- data/lib/rcap/cap_1_0/alert.rb +59 -342
- data/lib/rcap/cap_1_0/area.rb +13 -188
- data/lib/rcap/cap_1_0/circle.rb +2 -100
- data/lib/rcap/cap_1_0/event_code.rb +8 -3
- data/lib/rcap/cap_1_0/geocode.rb +8 -3
- data/lib/rcap/cap_1_0/info.rb +16 -468
- data/lib/rcap/cap_1_0/parameter.rb +9 -67
- data/lib/rcap/cap_1_0/point.rb +2 -61
- data/lib/rcap/cap_1_0/polygon.rb +5 -95
- data/lib/rcap/cap_1_0/resource.rb +4 -144
- data/lib/rcap/cap_1_1/alert.rb +7 -412
- data/lib/rcap/cap_1_1/area.rb +13 -188
- data/lib/rcap/cap_1_1/circle.rb +2 -100
- data/lib/rcap/cap_1_1/event_code.rb +8 -3
- data/lib/rcap/cap_1_1/geocode.rb +7 -3
- data/lib/rcap/cap_1_1/info.rb +127 -386
- data/lib/rcap/cap_1_1/parameter.rb +4 -76
- data/lib/rcap/cap_1_1/point.rb +2 -61
- data/lib/rcap/cap_1_1/polygon.rb +5 -95
- data/lib/rcap/cap_1_1/resource.rb +37 -143
- data/lib/rcap/cap_1_2/alert.rb +8 -413
- data/lib/rcap/cap_1_2/area.rb +13 -188
- data/lib/rcap/cap_1_2/circle.rb +2 -100
- data/lib/rcap/cap_1_2/event_code.rb +8 -3
- data/lib/rcap/cap_1_2/geocode.rb +8 -3
- data/lib/rcap/cap_1_2/info.rb +132 -419
- data/lib/rcap/cap_1_2/parameter.rb +4 -76
- data/lib/rcap/cap_1_2/point.rb +2 -61
- data/lib/rcap/cap_1_2/polygon.rb +5 -92
- data/lib/rcap/cap_1_2/resource.rb +31 -134
- data/lib/rcap/config.rb +3 -0
- data/lib/{extensions → rcap/extensions}/array.rb +1 -1
- data/lib/rcap/extensions/date.rb +11 -0
- data/lib/{extensions → rcap/extensions}/date_time.rb +2 -5
- data/lib/{extensions → rcap/extensions}/string.rb +1 -1
- data/lib/{extensions → rcap/extensions}/time.rb +2 -4
- data/lib/rcap/utilities.rb +11 -11
- data/lib/rcap/validations.rb +7 -2
- data/lib/rcap/version.rb +1 -1
- data/lib/rcap.rb +21 -4
- data/spec/alert_spec.rb +69 -37
- data/spec/cap_1_0/alert_spec.rb +46 -61
- data/spec/cap_1_0/area_spec.rb +77 -37
- data/spec/cap_1_0/circle_spec.rb +26 -6
- data/spec/cap_1_0/event_code_spec.rb +10 -3
- data/spec/cap_1_0/geocode_spec.rb +11 -4
- data/spec/cap_1_0/info_spec.rb +74 -77
- data/spec/cap_1_0/parameter_spec.rb +18 -5
- data/spec/cap_1_0/point_spec.rb +9 -2
- data/spec/cap_1_0/polygon_spec.rb +52 -9
- data/spec/cap_1_0/resource_spec.rb +28 -21
- data/spec/cap_1_1/alert_spec.rb +47 -60
- data/spec/cap_1_1/area_spec.rb +66 -43
- data/spec/cap_1_1/circle_spec.rb +29 -6
- data/spec/cap_1_1/event_code_spec.rb +11 -3
- data/spec/cap_1_1/geocode_spec.rb +11 -3
- data/spec/cap_1_1/info_spec.rb +262 -118
- data/spec/cap_1_1/parameter_spec.rb +12 -3
- data/spec/cap_1_1/point_spec.rb +8 -2
- data/spec/cap_1_1/polygon_spec.rb +57 -18
- data/spec/cap_1_1/resource_spec.rb +70 -20
- data/spec/cap_1_2/alert_spec.rb +97 -110
- data/spec/cap_1_2/area_spec.rb +59 -41
- data/spec/cap_1_2/circle_spec.rb +15 -8
- data/spec/cap_1_2/event_code_spec.rb +11 -3
- data/spec/cap_1_2/geocode_spec.rb +11 -3
- data/spec/cap_1_2/info_spec.rb +266 -119
- data/spec/cap_1_2/parameter_spec.rb +11 -3
- data/spec/cap_1_2/point_spec.rb +10 -3
- data/spec/cap_1_2/polygon_spec.rb +25 -10
- data/spec/cap_1_2/resource_spec.rb +33 -28
- data/spec/{utilities_spec.rb → extensions_spec.rb} +0 -0
- data/spec/validations_spec.rb +18 -2
- metadata +20 -46
data/lib/rcap/cap_1_0/alert.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module RCAP
|
2
2
|
module CAP_1_0
|
3
|
+
|
3
4
|
# An Alert object is valid if
|
4
5
|
# * it has an identifier
|
5
6
|
# * it has a sender
|
@@ -8,148 +9,28 @@ module RCAP
|
|
8
9
|
# * it has a valid messge type value
|
9
10
|
# * it has a valid scope value
|
10
11
|
# * all Info objects contained in infos are valid
|
11
|
-
class Alert
|
12
|
-
include Validation
|
12
|
+
class Alert < RCAP::Base::Alert
|
13
13
|
|
14
14
|
XMLNS = "http://www.incident.com/cap/1.0"
|
15
15
|
CAP_VERSION = "1.0"
|
16
16
|
|
17
|
-
STATUS_ACTUAL = "Actual"
|
18
|
-
STATUS_EXERCISE = "Exercise"
|
19
|
-
STATUS_SYSTEM = "System"
|
20
|
-
STATUS_TEST = "Test"
|
21
|
-
# Valid values for status
|
22
|
-
VALID_STATUSES = [ STATUS_ACTUAL, STATUS_EXERCISE, STATUS_SYSTEM, STATUS_TEST ]
|
23
|
-
|
24
|
-
MSG_TYPE_ALERT = "Alert"
|
25
|
-
MSG_TYPE_UPDATE = "Update"
|
26
|
-
MSG_TYPE_CANCEL = "Cancel"
|
27
|
-
MSG_TYPE_ACK = "Ack"
|
28
|
-
MSG_TYPE_ERROR = "Error"
|
29
|
-
# Valid values for msg_type
|
30
|
-
VALID_MSG_TYPES = [ MSG_TYPE_ALERT, MSG_TYPE_UPDATE, MSG_TYPE_CANCEL, MSG_TYPE_ACK, MSG_TYPE_ERROR ]
|
31
|
-
|
32
|
-
SCOPE_PUBLIC = "Public"
|
33
|
-
SCOPE_RESTRICTED = "Restricted"
|
34
|
-
SCOPE_PRIVATE = "Private"
|
35
|
-
# Valid values for scope
|
36
|
-
VALID_SCOPES = [ SCOPE_PUBLIC, SCOPE_PRIVATE, SCOPE_RESTRICTED ]
|
37
|
-
|
38
|
-
|
39
|
-
# @return [String] If not set a UUID will be set by default
|
40
|
-
attr_accessor( :identifier)
|
41
|
-
# @return [String]
|
42
|
-
attr_accessor( :sender )
|
43
|
-
# @return [DateTime] If not set will value will be time of creation.
|
44
|
-
attr_accessor( :sent )
|
45
|
-
# @return [String] Can only be one of {VALID_STATUSES}
|
46
|
-
attr_accessor( :status )
|
47
|
-
# @return [String] Can only be one of {VALID_MSG_TYPES}
|
48
|
-
attr_accessor( :msg_type )
|
49
17
|
# @return [String]
|
50
18
|
attr_accessor( :password )
|
51
|
-
# @return [String] Can only be one of {VALID_SCOPES}
|
52
|
-
attr_accessor( :scope )
|
53
|
-
# @return [String]
|
54
|
-
attr_accessor( :source )
|
55
|
-
# @return [String ] Depends on scope being {SCOPE_RESTRICTED}
|
56
|
-
attr_accessor( :restriction )
|
57
|
-
# @return [String]
|
58
|
-
attr_accessor( :note )
|
59
|
-
|
60
|
-
# @return [Array<String>] Collection of address strings. Depends on scope being {SCOPE_PRIVATE}
|
61
|
-
attr_reader( :addresses )
|
62
|
-
# @return [Array<String>]
|
63
|
-
attr_reader( :codes )
|
64
|
-
# @return [Array<String>] See {#to_reference}
|
65
|
-
attr_reader( :references)
|
66
|
-
# @return [Array<String>] Collection of incident strings
|
67
|
-
attr_reader( :incidents )
|
68
|
-
# @return [Array<Info>]
|
69
|
-
attr_reader( :infos )
|
70
|
-
|
71
|
-
validates_presence_of( :identifier, :sender, :sent, :status, :msg_type, :scope )
|
72
|
-
|
73
|
-
validates_inclusion_of( :status, :in => VALID_STATUSES )
|
74
|
-
validates_inclusion_of( :msg_type, :in => VALID_MSG_TYPES )
|
75
|
-
validates_inclusion_of( :scope, :in => VALID_SCOPES )
|
76
|
-
|
77
|
-
validates_format_of( :identifier, :with => ALLOWED_CHARACTERS )
|
78
|
-
validates_format_of( :sender , :with => ALLOWED_CHARACTERS )
|
79
|
-
|
80
|
-
validates_dependency_of( :addresses, :on => :scope, :with_value => SCOPE_PRIVATE )
|
81
|
-
validates_dependency_of( :restriction, :on => :scope, :with_value => SCOPE_RESTRICTED )
|
82
19
|
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
107
|
-
def initialize( attributes = {})
|
108
|
-
@identifier = attributes[ :identifier ] || RCAP.generate_identifier
|
109
|
-
@sender = attributes[ :sender ]
|
110
|
-
@sent = attributes[ :sent ]
|
111
|
-
@status = attributes[ :status ]
|
112
|
-
@msg_type = attributes[ :msg_type ]
|
113
|
-
@password = attributes[ :password ]
|
114
|
-
@scope = attributes[ :scope ]
|
115
|
-
@source = attributes[ :source ]
|
116
|
-
@restriction = attributes[ :restriction ]
|
117
|
-
@addresses = Array( attributes[ :addresses ])
|
118
|
-
@codes = Array( attributes[ :codes ])
|
119
|
-
@references = Array( attributes[ :references ])
|
120
|
-
@incidents = Array( attributes[ :incidents ])
|
121
|
-
@infos = Array( attributes[ :infos ])
|
20
|
+
# @return [String]
|
21
|
+
def xmlns
|
22
|
+
XMLNS
|
122
23
|
end
|
123
24
|
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
# @param [Hash] info_attributes Info attributes - see {Info#initialize}
|
128
|
-
# @return [Info]
|
129
|
-
def add_info( info_attributes = {})
|
130
|
-
info = Info.new( info_attributes )
|
131
|
-
@infos << info
|
132
|
-
info
|
25
|
+
# @return [Class]
|
26
|
+
def info_class
|
27
|
+
Info
|
133
28
|
end
|
134
29
|
|
135
|
-
|
136
|
-
IDENTIFIER_ELEMENT_NAME = 'identifier'
|
137
|
-
SENDER_ELEMENT_NAME = 'sender'
|
138
|
-
SENT_ELEMENT_NAME = 'sent'
|
139
|
-
STATUS_ELEMENT_NAME = 'status'
|
140
|
-
MSG_TYPE_ELEMENT_NAME = 'msgType'
|
141
|
-
PASSWORD_ELEMENT_NAME = 'password'
|
142
|
-
SOURCE_ELEMENT_NAME = 'source'
|
143
|
-
SCOPE_ELEMENT_NAME = 'scope'
|
144
|
-
RESTRICTION_ELEMENT_NAME = 'restriction'
|
145
|
-
ADDRESSES_ELEMENT_NAME = 'addresses'
|
146
|
-
CODE_ELEMENT_NAME = 'code'
|
147
|
-
NOTE_ELEMENT_NAME = 'note'
|
148
|
-
REFERENCES_ELEMENT_NAME = 'references'
|
149
|
-
INCIDENTS_ELEMENT_NAME = 'incidents'
|
30
|
+
PASSWORD_ELEMENT_NAME = 'password'
|
150
31
|
|
151
32
|
# @return [REXML::Element]
|
152
|
-
def to_xml_element
|
33
|
+
def to_xml_element
|
153
34
|
xml_element = REXML::Element.new( XML_ELEMENT_NAME )
|
154
35
|
xml_element.add_namespace( XMLNS )
|
155
36
|
xml_element.add_element( IDENTIFIER_ELEMENT_NAME ).add_text( @identifier ) if @identifier
|
@@ -180,38 +61,8 @@ module RCAP
|
|
180
61
|
xml_element
|
181
62
|
end
|
182
63
|
|
183
|
-
# @return [REXML::Document]
|
184
|
-
def to_xml_document
|
185
|
-
xml_document = REXML::Document.new
|
186
|
-
xml_document.add( REXML::XMLDecl.new )
|
187
|
-
xml_document.add( to_xml_element )
|
188
|
-
xml_document
|
189
|
-
end
|
190
|
-
|
191
|
-
# Returns a string containing the XML representation of the alert.
|
192
|
-
#
|
193
|
-
# @param [true,false] pretty_print Pretty print output
|
194
64
|
# @return [String]
|
195
|
-
def
|
196
|
-
if pretty_print
|
197
|
-
xml_document = ""
|
198
|
-
RCAP::XML_PRETTY_PRINTER.write( to_xml_document, xml_document )
|
199
|
-
xml_document
|
200
|
-
else
|
201
|
-
to_xml_document.to_s
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# Returns a string representation of the alert suitable for usage as a reference in a CAP message of the form
|
206
|
-
# sender,identifier,sent
|
207
|
-
#
|
208
|
-
# @return [String]
|
209
|
-
def to_reference
|
210
|
-
"#{ @sender },#{ @identifier },#{ @sent }"
|
211
|
-
end
|
212
|
-
|
213
|
-
# @return [String]
|
214
|
-
def inspect
|
65
|
+
def inspect
|
215
66
|
alert_inspect = [ "CAP Version: #{ CAP_VERSION }",
|
216
67
|
"Identifier: #{ @identifier }",
|
217
68
|
"Sender: #{ @sender }",
|
@@ -224,7 +75,7 @@ module RCAP
|
|
224
75
|
"Restriction: #{ @restriction }",
|
225
76
|
"Addresses: #{ @addresses.to_s_for_cap }",
|
226
77
|
"Codes:",
|
227
|
-
@codes.map{ |code| " " + code }.join("\n")
|
78
|
+
@codes.map{ |code| " " + code }.join("\n"),
|
228
79
|
"Note: #{ @note }",
|
229
80
|
"References: #{ @references.join( ' ' )}",
|
230
81
|
"Incidents: #{ @incidents.join( ' ')}",
|
@@ -233,173 +84,72 @@ module RCAP
|
|
233
84
|
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
234
85
|
end
|
235
86
|
|
236
|
-
# Returns a string representation of the alert of the form
|
237
|
-
# sender/identifier/sent
|
238
|
-
# See {#to_reference} for another string representation suitable as a CAP reference.
|
239
|
-
#
|
240
|
-
# @return [String]
|
241
|
-
def to_s
|
242
|
-
"#{ @sender }/#{ @identifier }/#{ @sent }"
|
243
|
-
end
|
244
87
|
|
245
|
-
|
246
|
-
IDENTIFIER_XPATH = "cap:#{ IDENTIFIER_ELEMENT_NAME }"
|
247
|
-
SENDER_XPATH = "cap:#{ SENDER_ELEMENT_NAME }"
|
248
|
-
SENT_XPATH = "cap:#{ SENT_ELEMENT_NAME }"
|
249
|
-
STATUS_XPATH = "cap:#{ STATUS_ELEMENT_NAME }"
|
250
|
-
MSG_TYPE_XPATH = "cap:#{ MSG_TYPE_ELEMENT_NAME }"
|
251
|
-
PASSWORD_XPATH = "cap:#{ PASSWORD_ELEMENT_NAME }"
|
252
|
-
SOURCE_XPATH = "cap:#{ SOURCE_ELEMENT_NAME }"
|
253
|
-
SCOPE_XPATH = "cap:#{ SCOPE_ELEMENT_NAME }"
|
254
|
-
RESTRICTION_XPATH = "cap:#{ RESTRICTION_ELEMENT_NAME }"
|
255
|
-
ADDRESSES_XPATH = "cap:#{ ADDRESSES_ELEMENT_NAME }"
|
256
|
-
CODE_XPATH = "cap:#{ CODE_ELEMENT_NAME }"
|
257
|
-
NOTE_XPATH = "cap:#{ NOTE_ELEMENT_NAME }"
|
258
|
-
REFERENCES_XPATH = "cap:#{ REFERENCES_ELEMENT_NAME }"
|
259
|
-
INCIDENTS_XPATH = "cap:#{ INCIDENTS_ELEMENT_NAME }"
|
88
|
+
PASSWORD_XPATH = "cap:#{ PASSWORD_ELEMENT_NAME }"
|
260
89
|
|
261
90
|
# @param [REXML::Element] alert_xml_element
|
262
91
|
# @return [RCAP::CAP_1_0::Alert]
|
263
|
-
def self.from_xml_element( alert_xml_element )
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
:status => RCAP.xpath_text( alert_xml_element, STATUS_XPATH, Alert::XMLNS ),
|
268
|
-
:msg_type => RCAP.xpath_text( alert_xml_element, MSG_TYPE_XPATH, Alert::XMLNS ),
|
269
|
-
:password => RCAP.xpath_text( alert_xml_element, PASSWORD_XPATH, Alert::XMLNS ),
|
270
|
-
:source => RCAP.xpath_text( alert_xml_element, SOURCE_XPATH, Alert::XMLNS ),
|
271
|
-
:scope => RCAP.xpath_text( alert_xml_element, SCOPE_XPATH, Alert::XMLNS ),
|
272
|
-
:restriction => RCAP.xpath_text( alert_xml_element, RESTRICTION_XPATH, Alert::XMLNS ),
|
273
|
-
:addresses => (( address = RCAP.xpath_text( alert_xml_element, ADDRESSES_XPATH, Alert::XMLNS )) ? address.unpack_cap_list : nil ),
|
274
|
-
:codes => RCAP.xpath_match( alert_xml_element, CODE_XPATH, Alert::XMLNS ).map{ |element| element.text },
|
275
|
-
:note => RCAP.xpath_text( alert_xml_element, NOTE_XPATH, Alert::XMLNS ),
|
276
|
-
:references => (( references = RCAP.xpath_text( alert_xml_element, REFERENCES_XPATH, Alert::XMLNS )) ? references.split( ' ' ) : nil ),
|
277
|
-
:incidents => (( incidents = RCAP.xpath_text( alert_xml_element, INCIDENTS_XPATH, Alert::XMLNS )) ? incidents.split( ' ' ) : nil ),
|
278
|
-
:infos => RCAP.xpath_match( alert_xml_element, Info::XPATH, Alert::XMLNS ).map{ |element| Info.from_xml_element( element )})
|
279
|
-
end
|
280
|
-
|
281
|
-
# @param [REXML::Document] xml_document
|
282
|
-
# @return [RCAP::CAP_1_0::Alert]
|
283
|
-
def self.from_xml_document( xml_document )
|
284
|
-
self.from_xml_element( xml_document.root )
|
92
|
+
def self.from_xml_element( alert_xml_element )
|
93
|
+
super.tap do |alert|
|
94
|
+
alert.password = RCAP.xpath_text( alert_xml_element, PASSWORD_XPATH, Alert::XMLNS )
|
95
|
+
end
|
285
96
|
end
|
286
97
|
|
287
|
-
# Initialise an Alert object from an XML string. Any object that is a subclass of IO (e.g. File) can be passed in.
|
288
|
-
#
|
289
|
-
# @param [String] xml
|
290
|
-
# @return [RCAP::CAP_1_0::Alert]
|
291
|
-
def self.from_xml( xml )
|
292
|
-
self.from_xml_document( REXML::Document.new( xml ))
|
293
|
-
end
|
294
98
|
|
295
|
-
|
296
|
-
IDENTIFIER_YAML = "Identifier"
|
297
|
-
SENDER_YAML = "Sender"
|
298
|
-
SENT_YAML = "Sent"
|
299
|
-
STATUS_YAML = "Status"
|
300
|
-
MSG_TYPE_YAML = "Message Type"
|
301
|
-
PASSWORD_YAML = "Password"
|
302
|
-
SOURCE_YAML = "Source"
|
303
|
-
SCOPE_YAML = "Scope"
|
304
|
-
RESTRICTION_YAML = "Restriction"
|
305
|
-
ADDRESSES_YAML = "Addresses"
|
306
|
-
CODES_YAML = "Codes"
|
307
|
-
NOTE_YAML = "Note"
|
308
|
-
REFERENCES_YAML = "References"
|
309
|
-
INCIDENTS_YAML = "Incidents"
|
310
|
-
INFOS_YAML = "Information"
|
99
|
+
PASSWORD_YAML = "Password"
|
311
100
|
|
312
101
|
# Returns a string containing the YAML representation of the alert.
|
313
102
|
#
|
314
103
|
# @return [String]
|
315
104
|
def to_yaml( options = {} )
|
316
|
-
RCAP.attribute_values_to_hash(
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
# Initialise an Alert object from a YAML string. Any object that is a subclass of IO (e.g. File) can be passed in.
|
337
|
-
#
|
338
|
-
# @param [String] yaml
|
339
|
-
# @return [RCAP::CAP_1_0::Alert]
|
340
|
-
def self.from_yaml( yaml )
|
341
|
-
self.from_yaml_data( YAML.load( yaml ))
|
342
|
-
end
|
343
|
-
|
344
|
-
# @param [Hash] yaml_data
|
105
|
+
RCAP.attribute_values_to_hash( [ CAP_VERSION_YAML, CAP_VERSION ],
|
106
|
+
[ IDENTIFIER_YAML, @identifier ],
|
107
|
+
[ SENDER_YAML, @sender ],
|
108
|
+
[ SENT_YAML, @sent ],
|
109
|
+
[ STATUS_YAML, @status ],
|
110
|
+
[ MSG_TYPE_YAML, @msg_type ],
|
111
|
+
[ PASSWORD_YAML, @password ],
|
112
|
+
[ SOURCE_YAML, @source ],
|
113
|
+
[ SCOPE_YAML, @scope ],
|
114
|
+
[ RESTRICTION_YAML, @restriction ],
|
115
|
+
[ ADDRESSES_YAML, @addresses ],
|
116
|
+
[ CODES_YAML, @codes ],
|
117
|
+
[ NOTE_YAML, @note ],
|
118
|
+
[ REFERENCES_YAML, @references ],
|
119
|
+
[ INCIDENTS_YAML, @incidents ],
|
120
|
+
[ INFOS_YAML, @infos ]).to_yaml( options )
|
121
|
+
end
|
122
|
+
|
123
|
+
# @param [Hash] alert_yaml_data
|
345
124
|
# @return [RCAP::CAP_1_0::Alert]
|
346
|
-
def self.from_yaml_data( alert_yaml_data )
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
:sent => ( sent = alert_yaml_data[ SENT_YAML ]).blank? ? nil : DateTime.parse( sent.to_s ),
|
351
|
-
:status => alert_yaml_data[ STATUS_YAML ],
|
352
|
-
:msg_type => alert_yaml_data[ MSG_TYPE_YAML ],
|
353
|
-
:password => alert_yaml_data[ PASSWORD_YAML ],
|
354
|
-
:source => alert_yaml_data[ SOURCE_YAML ],
|
355
|
-
:scope => alert_yaml_data[ SCOPE_YAML ],
|
356
|
-
:restriction => alert_yaml_data[ RESTRICTION_YAML ],
|
357
|
-
:addresses => alert_yaml_data[ ADDRESSES_YAML ],
|
358
|
-
:codes => alert_yaml_data[ CODES_YAML ],
|
359
|
-
:note => alert_yaml_data[ NOTE_YAML ],
|
360
|
-
:references => alert_yaml_data[ REFERENCES_YAML ],
|
361
|
-
:incidents => alert_yaml_data[ INCIDENTS_YAML ],
|
362
|
-
:infos => Array( alert_yaml_data[ INFOS_YAML ]).map{ |info_yaml_data| Info.from_yaml_data( info_yaml_data )}
|
363
|
-
)
|
125
|
+
def self.from_yaml_data( alert_yaml_data )
|
126
|
+
super.tap do |alert|
|
127
|
+
alert.password = alert_yaml_data[ PASSWORD_YAML ]
|
128
|
+
end
|
364
129
|
end
|
365
130
|
|
366
|
-
|
367
|
-
IDENTIFIER_KEY = 'identifier'
|
368
|
-
SENDER_KEY = 'sender'
|
369
|
-
SENT_KEY = 'sent'
|
370
|
-
STATUS_KEY = 'status'
|
371
|
-
MSG_TYPE_KEY = 'msg_type'
|
372
|
-
PASSWORD_KEY = 'password'
|
373
|
-
SOURCE_KEY = 'source'
|
374
|
-
SCOPE_KEY = 'scope'
|
375
|
-
RESTRICTION_KEY = 'restriction'
|
376
|
-
ADDRESSES_KEY = 'addresses'
|
377
|
-
CODES_KEY = 'codes'
|
378
|
-
NOTE_KEY = 'note'
|
379
|
-
REFERENCES_KEY = 'references'
|
380
|
-
INCIDENTS_KEY = 'incidents'
|
381
|
-
INFOS_KEY = 'infos'
|
131
|
+
PASSWORD_KEY = 'password'
|
382
132
|
|
383
133
|
# Returns a Hash representation of an Alert object
|
384
134
|
#
|
385
135
|
# @return [Hash]
|
386
136
|
def to_h
|
387
137
|
RCAP.attribute_values_to_hash( [ CAP_VERSION_KEY, CAP_VERSION ],
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
138
|
+
[ IDENTIFIER_KEY, @identifier ],
|
139
|
+
[ SENDER_KEY, @sender ],
|
140
|
+
[ SENT_KEY, RCAP.to_s_for_cap( @sent )],
|
141
|
+
[ STATUS_KEY, @status ],
|
142
|
+
[ MSG_TYPE_KEY, @msg_type ],
|
143
|
+
[ PASSWORD_KEY, @password ],
|
144
|
+
[ SOURCE_KEY, @source ],
|
145
|
+
[ SCOPE_KEY, @scope ],
|
146
|
+
[ RESTRICTION_KEY, @restriction ],
|
147
|
+
[ ADDRESSES_KEY, @addresses ],
|
148
|
+
[ CODES_KEY, @codes ],
|
149
|
+
[ NOTE_KEY, @note ],
|
150
|
+
[ REFERENCES_KEY, @references ],
|
151
|
+
[ INCIDENTS_KEY, @incidents ],
|
152
|
+
[ INFOS_KEY, @infos.map{ |info| info.to_h }])
|
403
153
|
end
|
404
154
|
|
405
155
|
# Initialises an Alert object from a Hash produced by Alert#to_h
|
@@ -407,43 +157,10 @@ module RCAP
|
|
407
157
|
# @param [Hash] alert_hash
|
408
158
|
# @return [RCAP::CAP_1_0::Alert]
|
409
159
|
def self.from_h( alert_hash )
|
410
|
-
|
411
|
-
|
412
|
-
:sender => alert_hash[ SENDER_KEY ],
|
413
|
-
:sent => RCAP.parse_datetime( alert_hash[ SENT_KEY ]),
|
414
|
-
:status => alert_hash[ STATUS_KEY ],
|
415
|
-
:msg_type => alert_hash[ MSG_TYPE_KEY ],
|
416
|
-
:password => alert_hash[ PASSWORD_KEY ],
|
417
|
-
:source => alert_hash[ SOURCE_KEY ],
|
418
|
-
:scope => alert_hash[ SCOPE_KEY ],
|
419
|
-
:restriction => alert_hash[ RESTRICTION_KEY ],
|
420
|
-
:addresses => alert_hash[ ADDRESSES_KEY ],
|
421
|
-
:codes => alert_hash[ CODES_KEY ],
|
422
|
-
:note => alert_hash[ NOTE_KEY ],
|
423
|
-
:references => alert_hash[ REFERENCES_KEY ],
|
424
|
-
:incidents => alert_hash[ INCIDENTS_KEY ],
|
425
|
-
:infos => Array( alert_hash[ INFOS_KEY ]).map{ |info_hash| Info.from_h( info_hash )})
|
426
|
-
end
|
427
|
-
|
428
|
-
# Returns a JSON string representation of an Alert object
|
429
|
-
#
|
430
|
-
# @param [true,false] pretty_print
|
431
|
-
# @return [String]
|
432
|
-
def to_json( pretty_print = false )
|
433
|
-
if pretty_print
|
434
|
-
JSON.pretty_generate( self.to_h )
|
435
|
-
else
|
436
|
-
self.to_h.to_json
|
160
|
+
super.tap do |alert|
|
161
|
+
alert.password = alert_hash[ PASSWORD_KEY ]
|
437
162
|
end
|
438
163
|
end
|
439
|
-
|
440
|
-
# Initialises an Alert object from a JSON string produced by Alert#to_json
|
441
|
-
#
|
442
|
-
# @param [String] json_string
|
443
|
-
# @return [RCAP::CAP_1_0::Alert]
|
444
|
-
def self.from_json( json_string )
|
445
|
-
self.from_h( JSON.parse( json_string ))
|
446
|
-
end
|
447
164
|
end
|
448
165
|
end
|
449
166
|
end
|