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.
@@ -179,26 +179,24 @@ module RCAP
179
179
  end
180
180
 
181
181
  def inspect # :nodoc:
182
- alert_inspect = <<EOF
183
- CAP Version: #{ CAP_VERSION }
184
- Identifier: #{ self.identifier }
185
- Sender: #{ self.sender }
186
- Sent: #{ self.sent }
187
- Status: #{ self.status }
188
- Message Type: #{ self.msg_type }
189
- Source: #{ self.source }
190
- Scope: #{ self.scope }
191
- Restriction: #{ self.restriction }
192
- Addresses: #{ self.addresses.to_s_for_cap }
193
- Codes:
194
- #{ self.codes.map{ |code| " #{ code }" }.join("\n")}
195
- Note: #{ self.note }
196
- References: #{ self.references.join( ' ' )}
197
- Incidents: #{ self.incidents.join( ' ')}
198
- Information:
199
- #{ self.infos.map{ |info| " " + info.to_s }.join( "\n" )}
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
@@ -95,14 +95,12 @@ module RCAP
95
95
  end
96
96
 
97
97
  def inspect # :nodoc:
98
- area_inspect = <<EOF
99
- Area Description: #{ self.area_desc }
100
- Polygons:
101
- #{ self.polygons.map{ |polygon| " " + polygon.inspect }.join("\n" )}
102
- Circles: #{ self.circles.inspect }
103
- Geocodes: #{ self.geocodes.inspect }
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
@@ -252,34 +252,32 @@ module RCAP
252
252
  end
253
253
 
254
254
  def inspect # :nodoc:
255
- info_inspect = <<EOF
256
- Language: #{ self.language }
257
- Categories: #{ self.categories.to_s_for_cap }
258
- Event: #{ self.event }
259
- Response Types: #{ self.response_types.to_s_for_cap }
260
- Urgency: #{ self.urgency }
261
- Severity: #{ self.severity }
262
- Certainty: #{ self.certainty }
263
- Audience: #{ self.audience }
264
- Event Codes: #{ self.event_codes.inspect }
265
- Effective: #{ self.effective }
266
- Onset: #{ self.onset }
267
- Expires: #{ self.expires }
268
- Sender Name: #{ self.sender_name }
269
- Headline: #{ self.headline }
270
- Description:
271
- #{ self.description.to_s.lines.map{ |line| " " + line }.join }
272
- Instruction: #{ self.instruction }
273
- Web: #{ self.web }
274
- Contact: #{ self.contact }
275
- Parameters:
276
- #{ self.parameters.map{ |parameter| parameter.inspect }.join( "\n" )}
277
- Resources:
278
- #{ self.resources.map{ |resource| " " + resource.inspect }.join( "\n" )}
279
- Area:
280
- #{ self.areas.map{ |area| " #{ area }" }.join( "\n" )}
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
@@ -179,26 +179,24 @@ module RCAP
179
179
  end
180
180
 
181
181
  def inspect # :nodoc:
182
- alert_inspect = <<EOF
183
- CAP Version: #{ CAP_VERSION }
184
- Identifier: #{ self.identifier }
185
- Sender: #{ self.sender }
186
- Sent: #{ self.sent }
187
- Status: #{ self.status }
188
- Message Type: #{ self.msg_type }
189
- Source: #{ self.source }
190
- Scope: #{ self.scope }
191
- Restriction: #{ self.restriction }
192
- Addresses: #{ self.addresses.to_s_for_cap }
193
- Codes:
194
- #{ self.codes.map{ |code| " #{ code }" }.join("\n")}
195
- Note: #{ self.note }
196
- References: #{ self.references.join( ' ' )}
197
- Incidents: #{ self.incidents.join( ' ')}
198
- Information:
199
- #{ self.infos.map{ |info| " " + info.to_s }.join( "\n" )}
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
@@ -95,14 +95,12 @@ module RCAP
95
95
  end
96
96
 
97
97
  def inspect # :nodoc:
98
- area_inspect = <<EOF
99
- Area Description: #{ self.area_desc }
100
- Polygons:
101
- #{ self.polygons.map{ |polygon| " " + polygon.inspect }.join("\n" )}
102
- Circles: #{ self.circles.inspect }
103
- Geocodes: #{ self.geocodes.inspect }
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
@@ -254,34 +254,32 @@ module RCAP
254
254
  end
255
255
 
256
256
  def inspect # :nodoc:
257
- info_inspect = <<EOF
258
- Language: #{ self.language }
259
- Categories: #{ self.categories.to_s_for_cap }
260
- Event: #{ self.event }
261
- Response Types: #{ self.response_types.to_s_for_cap }
262
- Urgency: #{ self.urgency }
263
- Severity: #{ self.severity }
264
- Certainty: #{ self.certainty }
265
- Audience: #{ self.audience }
266
- Event Codes: #{ self.event_codes.inspect }
267
- Effective: #{ self.effective }
268
- Onset: #{ self.onset }
269
- Expires: #{ self.expires }
270
- Sender Name: #{ self.sender_name }
271
- Headline: #{ self.headline }
272
- Description:
273
- #{ self.description.to_s.lines.map{ |line| " " + line }.join }
274
- Instruction: #{ self.instruction }
275
- Web: #{ self.web }
276
- Contact: #{ self.contact }
277
- Parameters:
278
- #{ self.parameters.map{ |parameter| parameter.inspect }.join( "\n" )}
279
- Resources:
280
- #{ self.resources.map{ |resource| " " + resource.inspect }.join( "\n" )}
281
- Area:
282
- #{ self.areas.map{ |area| " #{ area }" }.join( "\n" )}
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
@@ -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?( :'emtpy?' ) && value.empty? )}.flatten( 1 )]
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 )
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RCAP
2
- VERSION = '1.0.0.rc.4'
2
+ VERSION = '1.0.0.rc.5'
3
3
  end
@@ -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
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - rc
10
- - 4
11
- version: 1.0.0.rc.4
10
+ - 5
11
+ version: 1.0.0.rc.5
12
12
  platform: ruby
13
13
  authors:
14
14
  - Farrel Lifson