rcap 1.0.0.rc.4 → 1.0.0.rc.5
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.
- data/lib/rcap/cap_1_1/alert.rb +18 -20
- data/lib/rcap/cap_1_1/area.rb +9 -11
- data/lib/rcap/cap_1_1/info.rb +26 -28
- data/lib/rcap/cap_1_2/alert.rb +18 -20
- data/lib/rcap/cap_1_2/area.rb +9 -11
- data/lib/rcap/cap_1_2/info.rb +26 -28
- data/lib/rcap/utilities.rb +1 -1
- data/lib/rcap/validations.rb +1 -1
- data/lib/rcap/version.rb +1 -1
- data/spec/utilities_spec.rb +14 -0
- metadata +2 -2
data/lib/rcap/cap_1_1/alert.rb
CHANGED
@@ -179,26 +179,24 @@ module RCAP
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def inspect # :nodoc:
|
182
|
-
alert_inspect =
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
#{ self.
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
EOF
|
201
|
-
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
182
|
+
alert_inspect = "CAP Version: #{ CAP_VERSION }\n"+
|
183
|
+
"Identifier: #{ self.identifier }\n"+
|
184
|
+
"Sender: #{ self.sender }\n"+
|
185
|
+
"Sent: #{ self.sent }\n"+
|
186
|
+
"Status: #{ self.status }\n"+
|
187
|
+
"Message Type: #{ self.msg_type }\n"+
|
188
|
+
"Source: #{ self.source }\n"+
|
189
|
+
"Scope: #{ self.scope }\n"+
|
190
|
+
"Restriction: #{ self.restriction }\n"+
|
191
|
+
"Addresses: #{ self.addresses.to_s_for_cap }\n"+
|
192
|
+
"Codes:\n"+
|
193
|
+
self.codes.map{ |code| " " + code }.join("\n")+"\n"+
|
194
|
+
"Note: #{ self.note }\n"+
|
195
|
+
"References: #{ self.references.join( ' ' )}\n"+
|
196
|
+
"Incidents: #{ self.incidents.join( ' ')}\n"+
|
197
|
+
"Information:\n"+
|
198
|
+
self.infos.map{ |info| " " + info.to_s }.join( "\n" )
|
199
|
+
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
202
200
|
end
|
203
201
|
|
204
202
|
# Returns a string representation of the alert of the form
|
data/lib/rcap/cap_1_1/area.rb
CHANGED
@@ -95,14 +95,12 @@ module RCAP
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def inspect # :nodoc:
|
98
|
-
area_inspect =
|
99
|
-
|
100
|
-
|
101
|
-
#{ self.
|
102
|
-
|
103
|
-
|
104
|
-
EOF
|
105
|
-
RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
98
|
+
area_inspect = "Area Description: #{ self.area_desc }\n"+
|
99
|
+
"Polygons:\n"+
|
100
|
+
self.polygons.map{ |polygon| " " + polygon.inspect }.join("\n" )+"\n"+
|
101
|
+
"Circles: #{ self.circles.inspect }\n"+
|
102
|
+
"Geocodes: #{ self.geocodes.inspect }\n"
|
103
|
+
RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
106
104
|
end
|
107
105
|
|
108
106
|
# Returns a string representation of the area of the form
|
@@ -171,9 +169,9 @@ RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
|
171
169
|
:area_desc => area_hash[ AREA_DESC_KEY ],
|
172
170
|
:altitude => area_hash[ ALTITUDE_KEY ],
|
173
171
|
:ceiling => area_hash[ CEILING_KEY ],
|
174
|
-
:circles => area_hash[ CIRCLES_KEY ].map{ |circle_hash| Circle.from_h( circle_hash )},
|
175
|
-
:geocodes => area_hash[ GEOCODES_KEY ].map{ |geocode_hash| Geocode.from_h( geocode_hash )},
|
176
|
-
:polygons => area_hash[ POLYGONS_KEY ].map{ |polygon_hash| Polygon.from_h( polygon_hash )})
|
172
|
+
:circles => Array( area_hash[ CIRCLES_KEY ]).map{ |circle_hash| Circle.from_h( circle_hash )},
|
173
|
+
:geocodes => Array( area_hash[ GEOCODES_KEY ]).map{ |geocode_hash| Geocode.from_h( geocode_hash )},
|
174
|
+
:polygons => Array( area_hash[ POLYGONS_KEY ]).map{ |polygon_hash| Polygon.from_h( polygon_hash )})
|
177
175
|
end
|
178
176
|
end
|
179
177
|
end
|
data/lib/rcap/cap_1_1/info.rb
CHANGED
@@ -252,34 +252,32 @@ module RCAP
|
|
252
252
|
end
|
253
253
|
|
254
254
|
def inspect # :nodoc:
|
255
|
-
info_inspect =
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
#{ self.
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
EOF
|
282
|
-
RCAP.format_lines_for_inspect( 'INFO', info_inspect )
|
255
|
+
info_inspect = "Language: #{ self.language }\n"+
|
256
|
+
"Categories: #{ self.categories.to_s_for_cap }\n"+
|
257
|
+
"Event: #{ self.event }\n"+
|
258
|
+
"Response Types: #{ self.response_types.to_s_for_cap }\n"+
|
259
|
+
"Urgency: #{ self.urgency }\n"+
|
260
|
+
"Severity: #{ self.severity }\n"+
|
261
|
+
"Certainty: #{ self.certainty }\n"+
|
262
|
+
"Audience: #{ self.audience }\n"+
|
263
|
+
"Event Codes: #{ self.event_codes.inspect }\n"+
|
264
|
+
"Effective: #{ self.effective }\n"+
|
265
|
+
"Onset: #{ self.onset }\n"+
|
266
|
+
"Expires: #{ self.expires }\n"+
|
267
|
+
"Sender Name: #{ self.sender_name }\n"+
|
268
|
+
"Headline: #{ self.headline }\n"+
|
269
|
+
"Description:\n"+
|
270
|
+
self.description.to_s.lines.map{ |line| " " + line }.join( "\n")+"\n"+
|
271
|
+
"Instruction: #{ self.instruction }\n"+
|
272
|
+
"Web: #{ self.web }\n"+
|
273
|
+
"Contact: #{ self.contact }\n"+
|
274
|
+
"Parameters:\n"+
|
275
|
+
self.parameters.map{ |parameter| parameter.inspect }.join( "\n" )+"\n"+
|
276
|
+
"Resources:\n"+
|
277
|
+
self.resources.map{ |resource| " " + resource.inspect }.join( "\n" )+"\n"+
|
278
|
+
"Area:\n"+
|
279
|
+
self.areas.map{ |area| " #{ area }" }.join( "\n" )+"\n"
|
280
|
+
RCAP.format_lines_for_inspect( 'INFO', info_inspect )
|
283
281
|
end
|
284
282
|
|
285
283
|
# Returns a string representation of the event of the form
|
data/lib/rcap/cap_1_2/alert.rb
CHANGED
@@ -179,26 +179,24 @@ module RCAP
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def inspect # :nodoc:
|
182
|
-
alert_inspect =
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
#{ self.
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
EOF
|
201
|
-
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
182
|
+
alert_inspect = "CAP Version: #{ CAP_VERSION }\n"+
|
183
|
+
"Identifier: #{ self.identifier }\n"+
|
184
|
+
"Sender: #{ self.sender }\n"+
|
185
|
+
"Sent: #{ self.sent }\n"+
|
186
|
+
"Status: #{ self.status }\n"+
|
187
|
+
"Message Type: #{ self.msg_type }\n"+
|
188
|
+
"Source: #{ self.source }\n"+
|
189
|
+
"Scope: #{ self.scope }\n"+
|
190
|
+
"Restriction: #{ self.restriction }\n"+
|
191
|
+
"Addresses: #{ self.addresses.to_s_for_cap }\n"+
|
192
|
+
"Codes:\n"+
|
193
|
+
" #{ self.codes.map{ |code| " #{ code }" }.join("\n")}\n"+
|
194
|
+
"Note: #{ self.note }\n"+
|
195
|
+
"References: #{ self.references.join( ' ' )}\n"+
|
196
|
+
"Incidents: #{ self.incidents.join( ' ')}\n"+
|
197
|
+
"Information:\n"+
|
198
|
+
" #{ self.infos.map{ |info| " " + info.to_s }.join( "\n" )}\n"
|
199
|
+
RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
|
202
200
|
end
|
203
201
|
|
204
202
|
# Returns a string representation of the alert of the form
|
data/lib/rcap/cap_1_2/area.rb
CHANGED
@@ -95,14 +95,12 @@ module RCAP
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def inspect # :nodoc:
|
98
|
-
area_inspect =
|
99
|
-
|
100
|
-
|
101
|
-
#{ self.
|
102
|
-
|
103
|
-
|
104
|
-
EOF
|
105
|
-
RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
98
|
+
area_inspect = "Area Description: #{ self.area_desc }\n"+
|
99
|
+
"Polygons:\n"+
|
100
|
+
self.polygons.map{ |polygon| " " + polygon.inspect }.join("\n" )+"\n"+
|
101
|
+
"Circles: #{ self.circles.inspect }\n"+
|
102
|
+
"Geocodes: #{ self.geocodes.inspect }\n"
|
103
|
+
RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
106
104
|
end
|
107
105
|
|
108
106
|
# Returns a string representation of the area of the form
|
@@ -171,9 +169,9 @@ RCAP.format_lines_for_inspect( 'AREA', area_inspect )
|
|
171
169
|
:area_desc => area_hash[ AREA_DESC_KEY ],
|
172
170
|
:altitude => area_hash[ ALTITUDE_KEY ],
|
173
171
|
:ceiling => area_hash[ CEILING_KEY ],
|
174
|
-
:circles => area_hash[ CIRCLES_KEY ].map{ |circle_hash| Circle.from_h( circle_hash )},
|
175
|
-
:geocodes => area_hash[ GEOCODES_KEY ].map{ |geocode_hash| Geocode.from_h( geocode_hash )},
|
176
|
-
:polygons => area_hash[ POLYGONS_KEY ].map{ |polygon_hash| Polygon.from_h( polygon_hash )})
|
172
|
+
:circles => Array( area_hash[ CIRCLES_KEY ]).map{ |circle_hash| Circle.from_h( circle_hash )},
|
173
|
+
:geocodes => Array( area_hash[ GEOCODES_KEY ]).map{ |geocode_hash| Geocode.from_h( geocode_hash )},
|
174
|
+
:polygons => Array( area_hash[ POLYGONS_KEY ]).map{ |polygon_hash| Polygon.from_h( polygon_hash )})
|
177
175
|
end
|
178
176
|
end
|
179
177
|
end
|
data/lib/rcap/cap_1_2/info.rb
CHANGED
@@ -254,34 +254,32 @@ module RCAP
|
|
254
254
|
end
|
255
255
|
|
256
256
|
def inspect # :nodoc:
|
257
|
-
info_inspect =
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
#{ self.
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
EOF
|
284
|
-
RCAP.format_lines_for_inspect( 'INFO', info_inspect )
|
257
|
+
info_inspect = "Language: #{ self.language }\n"+
|
258
|
+
"Categories: #{ self.categories.to_s_for_cap }\n"+
|
259
|
+
"Event: #{ self.event }\n"+
|
260
|
+
"Response Types: #{ self.response_types.to_s_for_cap }\n"+
|
261
|
+
"Urgency: #{ self.urgency }\n"+
|
262
|
+
"Severity: #{ self.severity }\n"+
|
263
|
+
"Certainty: #{ self.certainty }\n"+
|
264
|
+
"Audience: #{ self.audience }\n"+
|
265
|
+
"Event Codes: #{ self.event_codes.inspect }\n"+
|
266
|
+
"Effective: #{ self.effective }\n"+
|
267
|
+
"Onset: #{ self.onset }\n"+
|
268
|
+
"Expires: #{ self.expires }\n"+
|
269
|
+
"Sender Name: #{ self.sender_name }\n"+
|
270
|
+
"Headline: #{ self.headline }\n"+
|
271
|
+
"Description:\n"+
|
272
|
+
self.description.to_s.lines.map{ |line| " " + line }.join( "\n" )+"\n"+
|
273
|
+
"Instruction: #{ self.instruction }\n"+
|
274
|
+
"Web: #{ self.web }\n"+
|
275
|
+
"Contact: #{ self.contact }\n"+
|
276
|
+
"Parameters:\n"+
|
277
|
+
self.parameters.map{ |parameter| parameter.inspect }.join( "\n" )+"\n"+
|
278
|
+
"Resources:\n"+
|
279
|
+
self.resources.map{ |resource| " " + resource.inspect }.join( "\n" )+"\n"+
|
280
|
+
"Area:\n"+
|
281
|
+
self.areas.map{ |area| " #{ area }" }.join( "\n" )+"\n"
|
282
|
+
RCAP.format_lines_for_inspect( 'INFO', info_inspect )
|
285
283
|
end
|
286
284
|
|
287
285
|
# Returns a string representation of the event of the form
|
data/lib/rcap/utilities.rb
CHANGED
@@ -70,7 +70,7 @@ module RCAP # :nodoc:
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.attribute_values_to_hash( *attribute_values )
|
73
|
-
Hash[ *attribute_values.reject{ |key, value| value.nil? || ( value.respond_to?( :'
|
73
|
+
Hash[ *attribute_values.reject{ |key, value| value.nil? || ( value.respond_to?( :'empty?' ) && value.empty? )}.flatten( 1 )]
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.to_s_for_cap( object )
|
data/lib/rcap/validations.rb
CHANGED
@@ -36,7 +36,7 @@ module Validation # :nodoc:
|
|
36
36
|
}.merge!( attributes.extract_options! )
|
37
37
|
|
38
38
|
validates_each( *attributes ) do |object, attribute, collection|
|
39
|
-
next if ( collection.nil? && options[ :allow_nil ])
|
39
|
+
next if ( collection.nil? && options[ :allow_nil ]) || ( collection.empty? && options[ :allow_empty ])
|
40
40
|
unless options[ :minimum ] && collection.length >= options[ :minimum ]
|
41
41
|
object.errors[ attribute ] << options[ :message ]
|
42
42
|
end
|
data/lib/rcap/version.rb
CHANGED
data/spec/utilities_spec.rb
CHANGED
@@ -54,4 +54,18 @@ describe( String ) do
|
|
54
54
|
'Item1 Item2 Item3'.unpack_cap_list.should == [ "Item1", "Item2", "Item3" ]
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
describe( 'attribute_values_to_hash' ) do
|
59
|
+
it( 'should reject nil values' ) do
|
60
|
+
RCAP.attribute_values_to_hash( ["a", nil ]).should == {}
|
61
|
+
end
|
62
|
+
|
63
|
+
it( 'should reject empty values' ) do
|
64
|
+
RCAP.attribute_values_to_hash( ["a", []]).should == {}
|
65
|
+
end
|
66
|
+
|
67
|
+
it( 'should not reject non-nil and non-empty values' ) do
|
68
|
+
RCAP.attribute_values_to_hash( [ "a", 1 ], [ "b", [ 2 ]]).should == { "a" => 1, "b" => [ 2 ]}
|
69
|
+
end
|
70
|
+
end
|
57
71
|
end
|