rcap 1.3.1 → 2.0.0

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 (88) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/README.md +78 -151
  3. data/Rakefile +1 -1
  4. data/lib/rcap/alert.rb +2 -2
  5. data/lib/rcap/base/alert.rb +446 -0
  6. data/lib/rcap/base/area.rb +228 -0
  7. data/lib/rcap/base/circle.rb +121 -0
  8. data/lib/rcap/base/event_code.rb +6 -0
  9. data/lib/rcap/base/geocode.rb +6 -0
  10. data/lib/rcap/base/info.rb +498 -0
  11. data/lib/rcap/base/parameter.rb +88 -0
  12. data/lib/rcap/base/point.rb +87 -0
  13. data/lib/rcap/base/polygon.rb +120 -0
  14. data/lib/rcap/base/resource.rb +168 -0
  15. data/lib/rcap/cap_1_0/alert.rb +59 -342
  16. data/lib/rcap/cap_1_0/area.rb +13 -188
  17. data/lib/rcap/cap_1_0/circle.rb +2 -100
  18. data/lib/rcap/cap_1_0/event_code.rb +8 -3
  19. data/lib/rcap/cap_1_0/geocode.rb +8 -3
  20. data/lib/rcap/cap_1_0/info.rb +16 -468
  21. data/lib/rcap/cap_1_0/parameter.rb +9 -67
  22. data/lib/rcap/cap_1_0/point.rb +2 -61
  23. data/lib/rcap/cap_1_0/polygon.rb +5 -95
  24. data/lib/rcap/cap_1_0/resource.rb +4 -144
  25. data/lib/rcap/cap_1_1/alert.rb +7 -412
  26. data/lib/rcap/cap_1_1/area.rb +13 -188
  27. data/lib/rcap/cap_1_1/circle.rb +2 -100
  28. data/lib/rcap/cap_1_1/event_code.rb +8 -3
  29. data/lib/rcap/cap_1_1/geocode.rb +7 -3
  30. data/lib/rcap/cap_1_1/info.rb +127 -386
  31. data/lib/rcap/cap_1_1/parameter.rb +4 -76
  32. data/lib/rcap/cap_1_1/point.rb +2 -61
  33. data/lib/rcap/cap_1_1/polygon.rb +5 -95
  34. data/lib/rcap/cap_1_1/resource.rb +37 -143
  35. data/lib/rcap/cap_1_2/alert.rb +8 -413
  36. data/lib/rcap/cap_1_2/area.rb +13 -188
  37. data/lib/rcap/cap_1_2/circle.rb +2 -100
  38. data/lib/rcap/cap_1_2/event_code.rb +8 -3
  39. data/lib/rcap/cap_1_2/geocode.rb +8 -3
  40. data/lib/rcap/cap_1_2/info.rb +132 -419
  41. data/lib/rcap/cap_1_2/parameter.rb +4 -76
  42. data/lib/rcap/cap_1_2/point.rb +2 -61
  43. data/lib/rcap/cap_1_2/polygon.rb +5 -92
  44. data/lib/rcap/cap_1_2/resource.rb +31 -134
  45. data/lib/rcap/config.rb +3 -0
  46. data/lib/{extensions → rcap/extensions}/array.rb +1 -1
  47. data/lib/rcap/extensions/date.rb +11 -0
  48. data/lib/{extensions → rcap/extensions}/date_time.rb +2 -5
  49. data/lib/{extensions → rcap/extensions}/string.rb +1 -1
  50. data/lib/{extensions → rcap/extensions}/time.rb +2 -4
  51. data/lib/rcap/utilities.rb +11 -11
  52. data/lib/rcap/validations.rb +7 -2
  53. data/lib/rcap/version.rb +1 -1
  54. data/lib/rcap.rb +21 -4
  55. data/spec/alert_spec.rb +69 -37
  56. data/spec/cap_1_0/alert_spec.rb +46 -61
  57. data/spec/cap_1_0/area_spec.rb +77 -37
  58. data/spec/cap_1_0/circle_spec.rb +26 -6
  59. data/spec/cap_1_0/event_code_spec.rb +10 -3
  60. data/spec/cap_1_0/geocode_spec.rb +11 -4
  61. data/spec/cap_1_0/info_spec.rb +74 -77
  62. data/spec/cap_1_0/parameter_spec.rb +18 -5
  63. data/spec/cap_1_0/point_spec.rb +9 -2
  64. data/spec/cap_1_0/polygon_spec.rb +52 -9
  65. data/spec/cap_1_0/resource_spec.rb +28 -21
  66. data/spec/cap_1_1/alert_spec.rb +47 -60
  67. data/spec/cap_1_1/area_spec.rb +66 -43
  68. data/spec/cap_1_1/circle_spec.rb +29 -6
  69. data/spec/cap_1_1/event_code_spec.rb +11 -3
  70. data/spec/cap_1_1/geocode_spec.rb +11 -3
  71. data/spec/cap_1_1/info_spec.rb +262 -118
  72. data/spec/cap_1_1/parameter_spec.rb +12 -3
  73. data/spec/cap_1_1/point_spec.rb +8 -2
  74. data/spec/cap_1_1/polygon_spec.rb +57 -18
  75. data/spec/cap_1_1/resource_spec.rb +70 -20
  76. data/spec/cap_1_2/alert_spec.rb +97 -110
  77. data/spec/cap_1_2/area_spec.rb +59 -41
  78. data/spec/cap_1_2/circle_spec.rb +15 -8
  79. data/spec/cap_1_2/event_code_spec.rb +11 -3
  80. data/spec/cap_1_2/geocode_spec.rb +11 -3
  81. data/spec/cap_1_2/info_spec.rb +266 -119
  82. data/spec/cap_1_2/parameter_spec.rb +11 -3
  83. data/spec/cap_1_2/point_spec.rb +10 -3
  84. data/spec/cap_1_2/polygon_spec.rb +25 -10
  85. data/spec/cap_1_2/resource_spec.rb +33 -28
  86. data/spec/{utilities_spec.rb → extensions_spec.rb} +0 -0
  87. data/spec/validations_spec.rb +18 -2
  88. metadata +20 -46
@@ -1,80 +1,253 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_1::Info ) do
4
+ before( :each ) do
5
+ @info_constructor = lambda do |info|
6
+ [ RCAP::CAP_1_1::Info::CATEGORY_GEO, RCAP::CAP_1_1::Info::CATEGORY_FIRE ].each do |category|
7
+ info.categories << category
8
+ end
9
+
10
+ info.event = 'Event Description'
11
+
12
+ [ RCAP::CAP_1_1::Info::RESPONSE_TYPE_MONITOR, RCAP::CAP_1_1::Info::RESPONSE_TYPE_ASSESS ].each do |response_type|
13
+ info.response_types << response_type
14
+ end
15
+
16
+ info.urgency = RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE
17
+ info.severity = RCAP::CAP_1_1::Info::SEVERITY_EXTREME
18
+ info.certainty = RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED
19
+ info.audience = 'Audience'
20
+ info.effective = DateTime.now
21
+ info.onset = DateTime.now + 1
22
+ info.expires = DateTime.now + 2
23
+ info.sender_name = 'Sender Name'
24
+ info.headline = 'Headline'
25
+ info.description = 'Description'
26
+ info.instruction = 'Instruction'
27
+ info.web = 'http://website'
28
+ info.contact = 'contact@address'
29
+
30
+ info.add_resource do |resource|
31
+ resource.resource_desc = 'Resource Description'
32
+ resource.uri = 'http://tempuri.org/resource'
33
+ end
34
+
35
+ [{ :name => 'name1', :value => 'value1' }, { :name => 'name2', :value => 'value2' }].each do |event_code_hash|
36
+ info.add_event_code do |event_code|
37
+ event_code.name = event_code_hash[ :name ]
38
+ event_code.value = event_code_hash[ :value ]
39
+ end
40
+ end
41
+
42
+ [{ :name => 'name1', :value => 'value1' }, { :name => 'name2', :value => 'value2' }].each do |parameter_hash|
43
+ info.add_parameter do |parameter|
44
+ parameter.name = parameter_hash[ :name ]
45
+ parameter.value = parameter_hash[ :value ]
46
+ end
47
+ end
48
+
49
+ [ 'Area1', 'Area2' ].each do |area_desc|
50
+ info.add_area do |area|
51
+ area.area_desc = area_desc
52
+ end
53
+ end
54
+ end
55
+ end
56
+
4
57
  context( 'on initialisation' ) do
5
58
  before( :each ) do
6
59
  @info = RCAP::CAP_1_1::Info.new
7
60
  end
8
61
 
9
- it( 'should have a default language of en-US' ) { @info.language.should == 'en-US' }
10
- it( 'should have no categories' ) { @info.categories.should( be_empty )}
11
- it( 'should have no event' ) { @info.event.should( be_nil )}
12
- it( 'should have no response types' ) { @info.response_types.should( be_empty )}
13
- it( 'should have no urgency' ) { @info.urgency.should( be_nil )}
14
- it( 'should have no severity' ) { @info.severity.should( be_nil )}
15
- it( 'should have no certainty' ) { @info.certainty.should( be_nil )}
16
- it( 'should have no audience' ) { @info.audience.should( be_nil )}
17
- it( 'should have no event_codes' ) { @info.event_codes.should( be_empty )}
18
- it( 'should have no effective datetime' ) { @info.effective.should( be_nil )}
19
- it( 'should have no onset datetime' ) { @info.onset.should( be_nil )}
20
- it( 'should have no expires datetime' ) { @info.expires.should( be_nil )}
21
- it( 'should have no sender name ' ) { @info.sender_name.should( be_nil )}
22
- it( 'should have no headline' ) { @info.headline.should( be_nil )}
23
- it( 'should have no description' ) { @info.description.should( be_nil )}
24
- it( 'should have no instruction' ) { @info.instruction.should( be_nil )}
25
- it( 'should have no web' ) { @info.web.should( be_nil )}
26
- it( 'should have no contact' ) { @info.contact.should( be_nil )}
27
- it( 'should have no parameters' ) { @info.parameters.should( be_empty )}
62
+ it( 'should have a default language of en-US' ) do
63
+ @info.language.should == 'en-US'
64
+ end
65
+
66
+ it( 'should have no categories' ) do
67
+ @info.categories.should( be_empty )
68
+ end
69
+
70
+ it( 'should have no event' ) do
71
+ @info.event.should( be_nil )
72
+ end
73
+
74
+ it( 'should have no response types' ) do
75
+ @info.response_types.should( be_empty )
76
+ end
77
+
78
+ it( 'should have no urgency' ) do
79
+ @info.urgency.should( be_nil )
80
+ end
81
+
82
+ it( 'should have no severity' ) do
83
+ @info.severity.should( be_nil )
84
+ end
85
+
86
+ it( 'should have no certainty' ) do
87
+ @info.certainty.should( be_nil )
88
+ end
89
+
90
+ it( 'should have no audience' ) do
91
+ @info.audience.should( be_nil )
92
+ end
93
+
94
+ it( 'should have no event_codes' ) do
95
+ @info.event_codes.should( be_empty )
96
+ end
97
+
98
+ it( 'should have no effective datetime' ) do
99
+ @info.effective.should( be_nil )
100
+ end
101
+
102
+ it( 'should have no onset datetime' ) do
103
+ @info.onset.should( be_nil )
104
+ end
105
+
106
+ it( 'should have no expires datetime' ) do
107
+ @info.expires.should( be_nil )
108
+ end
109
+
110
+ it( 'should have no sender name ' ) do
111
+ @info.sender_name.should( be_nil )
112
+ end
113
+
114
+ it( 'should have no headline' ) do
115
+ @info.headline.should( be_nil )
116
+ end
117
+
118
+ it( 'should have no description' ) do
119
+ @info.description.should( be_nil )
120
+ end
121
+
122
+ it( 'should have no instruction' ) do
123
+ @info.instruction.should( be_nil )
124
+ end
125
+
126
+ it( 'should have no web' ) do
127
+ @info.web.should( be_nil )
128
+ end
129
+
130
+ it( 'should have no contact' ) do
131
+ @info.contact.should( be_nil )
132
+ end
133
+
134
+ it( 'should have no parameters' ) do
135
+ @info.parameters.should( be_empty )
136
+ end
137
+
28
138
 
29
139
  shared_examples_for( 'it can parse into a CAP 1.1 Info object' ) do
30
- it( 'should parse categories correctly' ){ @info.categories.should_not( be_nil ) ; @info.categories.should == @original_info.categories }
31
- it( 'should parse event correctly' ){ @info.event.should_not( be_nil ) ; @info.event.should == @original_info.event }
32
- it( 'should parse response_types correctly' ){ @info.response_types.should_not( be_nil ); @info.response_types.should == @original_info.response_types }
33
- it( 'should parse urgency correctly' ){ @info.urgency.should_not( be_nil ) ; @info.urgency.should == @original_info.urgency }
34
- it( 'should parse severity correctly' ){ @info.severity.should_not( be_nil ) ; @info.severity.should == @original_info.severity }
35
- it( 'should parse certainty correctly' ){ @info.certainty.should_not( be_nil ) ; @info.certainty.should == @original_info.certainty }
36
- it( 'should parse audience correctly' ){ @info.audience.should_not( be_nil ) ; @info.audience.should == @original_info.audience }
37
- it( 'should parse effective correctly' ){ @info.effective.should_not( be_nil ) ; @info.effective.should( be_within(Rational( 1, 86400 )).of( @original_info.effective ))}
38
- it( 'should parse onset correctly' ){ @info.onset.should_not( be_nil ) ; @info.onset.should( be_within( Rational( 1, 86400 )).of( @original_info.onset ))}
39
- it( 'should parse expires correctly' ){ @info.expires.should_not( be_nil ) ; @info.expires.should( be_within( Rational( 1, 86400 )).of( @original_info.expires ))}
40
- it( 'should parse sender_name correctly' ){ @info.sender_name.should_not( be_nil ) ; @info.sender_name.should == @original_info.sender_name }
41
- it( 'should parse headline correctly' ){ @info.headline.should_not( be_nil ) ; @info.headline.should == @original_info.headline }
42
- it( 'should parse description correctly' ){ @info.description.should_not( be_nil ) ; @info.description.should == @original_info.description }
43
- it( 'should parse instruction correctly' ){ @info.instruction.should_not( be_nil ) ; @info.instruction.should == @original_info.instruction }
44
- it( 'should parse web correctly' ){ @info.web.should_not( be_nil ) ; @info.web.should == @original_info.web }
45
- it( 'should parse contact correctly' ){ @info.contact.should_not( be_nil ) ; @info.contact.should == @original_info.contact }
46
- it( 'should parse event_codes correctly' ){ @info.event_codes.should_not( be_nil ) ; @info.event_codes.should == @original_info.event_codes }
47
- it( 'should parse parameters correctly' ){ @info.parameters.should_not( be_nil ) ; @info.parameters.should == @original_info.parameters }
48
- it( 'should parse resources correctly' ){ @info.resources.should_not( be_nil ) ; @info.resources.should == @original_info.resources }
49
- it( 'should parse areas correctly' ){ @info.areas.should_not( be_nil ) ; @info.areas.should == @original_info.areas }
140
+ it( 'should parse categories correctly' ) do
141
+ @info.categories.should_not( be_nil )
142
+ @info.categories.should == @original_info.categories
143
+ end
144
+
145
+ it( 'should parse event correctly' ) do
146
+ @info.event.should_not( be_nil )
147
+ @info.event.should == @original_info.event
148
+ end
149
+
150
+ it( 'should parse response_types correctly' ) do
151
+ @info.response_types.should_not( be_nil )
152
+ @info.response_types.should == @original_info.response_types
153
+ end
154
+
155
+ it( 'should parse urgency correctly' ) do
156
+ @info.urgency.should_not( be_nil )
157
+ @info.urgency.should == @original_info.urgency
158
+ end
159
+
160
+ it( 'should parse severity correctly' ) do
161
+ @info.severity.should_not( be_nil )
162
+ @info.severity.should == @original_info.severity
163
+ end
164
+
165
+ it( 'should parse certainty correctly' ) do
166
+ @info.certainty.should_not( be_nil )
167
+ @info.certainty.should == @original_info.certainty
168
+ end
169
+
170
+ it( 'should parse audience correctly' ) do
171
+ @info.audience.should_not( be_nil )
172
+ @info.audience.should == @original_info.audience
173
+ end
174
+
175
+ it( 'should parse effective correctly' ) do
176
+ @info.effective.should_not( be_nil )
177
+ @info.effective.should( be_within(Rational( 1, 86400 )).of( @original_info.effective ))
178
+ end
179
+
180
+ it( 'should parse onset correctly' ) do
181
+ @info.onset.should_not( be_nil )
182
+ @info.onset.should( be_within( Rational( 1, 86400 )).of( @original_info.onset ))
183
+ end
184
+
185
+ it( 'should parse expires correctly' ) do
186
+ @info.expires.should_not( be_nil )
187
+ @info.expires.should( be_within( Rational( 1, 86400 )).of( @original_info.expires ))
188
+ end
189
+
190
+ it( 'should parse sender_name correctly' ) do
191
+ @info.sender_name.should_not( be_nil )
192
+ @info.sender_name.should == @original_info.sender_name
193
+ end
194
+
195
+ it( 'should parse headline correctly' ) do
196
+ @info.headline.should_not( be_nil )
197
+ @info.headline.should == @original_info.headline
198
+ end
199
+
200
+ it( 'should parse description correctly' ) do
201
+ @info.description.should_not( be_nil )
202
+ @info.description.should == @original_info.description
203
+ end
204
+
205
+ it( 'should parse instruction correctly' ) do
206
+ @info.instruction.should_not( be_nil )
207
+ @info.instruction.should == @original_info.instruction
208
+ end
209
+
210
+ it( 'should parse web correctly' ) do
211
+ @info.web.should_not( be_nil )
212
+ @info.web.should == @original_info.web
213
+ end
214
+
215
+ it( 'should parse contact correctly' ) do
216
+ @info.contact.should_not( be_nil )
217
+ @info.contact.should == @original_info.contact
218
+ end
219
+
220
+ it( 'should parse event_codes correctly' ) do
221
+ @info.event_codes.should_not( be_nil )
222
+ @info.event_codes.should == @original_info.event_codes
223
+ end
224
+
225
+ it( 'should parse parameters correctly' ) do
226
+ @info.parameters.should_not( be_nil )
227
+ @info.parameters.should == @original_info.parameters
228
+ end
229
+
230
+ it( 'should parse resources correctly' ) do
231
+ @info.resources.should_not( be_empty )
232
+
233
+ comparison_attributes = lambda do |resource|
234
+ resource.resource_desc
235
+ resource.uri
236
+ end
237
+ @info.resources.map( &comparison_attributes ).should == @original_info.resources.map( &comparison_attributes )
238
+ end
239
+
240
+ it( 'should parse areas correctly' ) do
241
+ @info.areas.should_not( be_nil )
242
+ @info.areas.should == @original_info.areas
243
+ end
50
244
  end
51
245
 
52
246
  context( 'from XML' ) do
53
247
  before( :each ) do
54
- @original_info = RCAP::CAP_1_1::Info.new( :categories => [ RCAP::CAP_1_1::Info::CATEGORY_GEO, RCAP::CAP_1_1::Info::CATEGORY_FIRE ],
55
- :event => 'Event Description',
56
- :response_types => [ RCAP::CAP_1_1::Info::RESPONSE_TYPE_MONITOR, RCAP::CAP_1_1::Info::RESPONSE_TYPE_ASSESS ],
57
- :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
58
- :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
59
- :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED,
60
- :audience => 'Audience',
61
- :effective => DateTime.now,
62
- :onset => DateTime.now + 1,
63
- :expires => DateTime.now + 2,
64
- :sender_name => 'Sender Name',
65
- :headline => 'Headline',
66
- :description => 'Description',
67
- :instruction => 'Instruction',
68
- :web => 'http://website',
69
- :contact => 'contact@address',
70
- :event_codes => [ RCAP::CAP_1_1::EventCode.new( :name => 'name1', :value => 'value1' ),
71
- RCAP::CAP_1_1::EventCode.new( :name => 'name2', :value => 'value2' )],
72
- :parameters => [ RCAP::CAP_1_1::Parameter.new( :name => 'name1', :value => 'value1' ),
73
- RCAP::CAP_1_1::Parameter.new( :name => 'name2', :value => 'value2' )],
74
- :areas => [ RCAP::CAP_1_1::Area.new( :area_desc => 'Area1' ),
75
- RCAP::CAP_1_1::Area.new( :area_desc => 'Area2' )]
76
- )
77
- @alert = RCAP::CAP_1_1::Alert.new( :infos => @original_info )
248
+ @original_info = RCAP::CAP_1_1::Info.new( &@info_constructor )
249
+ @alert = RCAP::CAP_1_1::Alert.new
250
+ @alert.add_info( &@info_constructor )
78
251
  @xml_string = @alert.to_xml
79
252
  @xml_document = REXML::Document.new( @xml_string )
80
253
  @info = RCAP::CAP_1_1::Info.from_xml_element( RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS ))
@@ -85,42 +258,24 @@ describe( RCAP::CAP_1_1::Info ) do
85
258
 
86
259
  context( 'from a hash' ) do
87
260
  before( :each ) do
88
- @original_info = RCAP::CAP_1_1::Info.new( :categories => [ RCAP::CAP_1_1::Info::CATEGORY_GEO, RCAP::CAP_1_1::Info::CATEGORY_FIRE ],
89
- :event => 'Event Description',
90
- :response_types => [ RCAP::CAP_1_1::Info::RESPONSE_TYPE_MONITOR, RCAP::CAP_1_1::Info::RESPONSE_TYPE_ASSESS ],
91
- :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
92
- :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
93
- :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED,
94
- :audience => 'Audience',
95
- :effective => DateTime.now,
96
- :onset => DateTime.now + 1,
97
- :expires => DateTime.now + 2,
98
- :sender_name => 'Sender Name',
99
- :headline => 'Headline',
100
- :description => 'Description',
101
- :instruction => 'Instruction',
102
- :web => 'http://website',
103
- :contact => 'contact@address',
104
- :event_codes => [ RCAP::CAP_1_1::EventCode.new( :name => 'name1', :value => 'value1' ),
105
- RCAP::CAP_1_1::EventCode.new( :name => 'name2', :value => 'value2' )],
106
- :parameters => [ RCAP::CAP_1_1::Parameter.new( :name => 'name1', :value => 'value1' ),
107
- RCAP::CAP_1_1::Parameter.new( :name => 'name2', :value => 'value2' )],
108
- :areas => [ RCAP::CAP_1_1::Area.new( :area_desc => 'Area1' ),
109
- RCAP::CAP_1_1::Area.new( :area_desc => 'Area2' )]
110
- )
261
+ @original_info = RCAP::CAP_1_1::Info.new( &@info_constructor )
262
+
111
263
  @info = RCAP::CAP_1_1::Info.from_h( @original_info.to_h )
112
264
  end
265
+
113
266
  it_should_behave_like( "it can parse into a CAP 1.1 Info object" )
114
267
  end
115
268
  end
116
269
 
117
270
  context( 'is not valid if it' ) do
118
271
  before( :each ) do
119
- @info = RCAP::CAP_1_1::Info.new( :event => 'Info Event',
120
- :categories => RCAP::CAP_1_1::Info::CATEGORY_GEO,
121
- :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
122
- :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
123
- :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED )
272
+ @info = RCAP::CAP_1_1::Info.new do |info|
273
+ info.event = 'Info Event'
274
+ info.categories << RCAP::CAP_1_1::Info::CATEGORY_GEO
275
+ info.urgency = RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE
276
+ info.severity = RCAP::CAP_1_1::Info::SEVERITY_EXTREME
277
+ info.certainty = RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED
278
+ end
124
279
  @info.valid?
125
280
  puts @info.errors.full_messages
126
281
  @info.should( be_valid )
@@ -156,29 +311,8 @@ describe( RCAP::CAP_1_1::Info ) do
156
311
  describe( 'when exported' ) do
157
312
  context( 'to hash' ) do
158
313
  before( :each ) do
159
- @info = RCAP::CAP_1_1::Info.new( :categories => [ RCAP::CAP_1_1::Info::CATEGORY_GEO, RCAP::CAP_1_1::Info::CATEGORY_FIRE ],
160
- :event => 'Event Description',
161
- :response_types => [ RCAP::CAP_1_1::Info::RESPONSE_TYPE_MONITOR, RCAP::CAP_1_1::Info::RESPONSE_TYPE_ASSESS ],
162
- :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
163
- :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
164
- :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED,
165
- :audience => 'Audience',
166
- :effective => DateTime.now,
167
- :onset => DateTime.now + 1,
168
- :expires => DateTime.now + 2,
169
- :sender_name => 'Sender Name',
170
- :headline => 'Headline',
171
- :description => 'Description',
172
- :instruction => 'Instruction',
173
- :web => 'http://website',
174
- :contact => 'contact@address',
175
- :resources => [ RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description', :uri => 'http://tempuri.org/resource' )],
176
- :event_codes => [ RCAP::CAP_1_1::EventCode.new( :name => 'name1', :value => 'value1' ),
177
- RCAP::CAP_1_1::EventCode.new( :name => 'name2', :value => 'value2' )],
178
- :parameters => [ RCAP::CAP_1_1::Parameter.new( :name => 'name1', :value => 'value1' ),
179
- RCAP::CAP_1_1::Parameter.new( :name => 'name2', :value => 'value2' )],
180
- :areas => [ RCAP::CAP_1_1::Area.new( :area_desc => 'Area1' ),
181
- RCAP::CAP_1_1::Area.new( :area_desc => 'Area2' )])
314
+ @info = RCAP::CAP_1_1::Info.new( &@info_constructor )
315
+
182
316
  @info_hash = @info.to_h
183
317
  end
184
318
 
@@ -275,7 +409,10 @@ describe( RCAP::CAP_1_1::Info ) do
275
409
 
276
410
  describe( '#add_event_code' ) do
277
411
  before( :each ) do
278
- @event_code = @info.add_event_code( name: 'Event Code', value: '1234' )
412
+ @event_code = @info.add_event_code do |event_code|
413
+ event_code.name = 'Event Code'
414
+ event_code.value = '1234'
415
+ end
279
416
  end
280
417
 
281
418
  it( 'should return a 1.1 EventCode' ) do
@@ -291,7 +428,10 @@ describe( RCAP::CAP_1_1::Info ) do
291
428
 
292
429
  describe( '#add_parameter' ) do
293
430
  before( :each ) do
294
- @parameter = @info.add_parameter( name: 'Parameter', value: '1234' )
431
+ @parameter = @info.add_parameter do |parameter|
432
+ parameter.name = 'Parameter'
433
+ parameter.value = '1234'
434
+ end
295
435
  end
296
436
 
297
437
  it( 'should return a 1.1 Parameter' ) do
@@ -307,7 +447,9 @@ describe( RCAP::CAP_1_1::Info ) do
307
447
 
308
448
  describe( '#add_resource' ) do
309
449
  before( :each ) do
310
- @resource = @info.add_resource( resource_desc: 'Resource' )
450
+ @resource = @info.add_resource do |resource|
451
+ resource.resource_desc = 'Resource'
452
+ end
311
453
  end
312
454
 
313
455
  it( 'should return a 1.1 Resource' ) do
@@ -322,7 +464,9 @@ describe( RCAP::CAP_1_1::Info ) do
322
464
 
323
465
  describe( '#add_area' ) do
324
466
  before( :each ) do
325
- @area = @info.add_area( area_desc: 'Area' )
467
+ @area = @info.add_area do |area|
468
+ area.area_desc = 'Area'
469
+ end
326
470
  end
327
471
 
328
472
  it( 'should return a 1.1 area' ) do
@@ -4,8 +4,14 @@ describe( RCAP::CAP_1_1::Parameter ) do
4
4
  context( 'when initialised' ) do
5
5
  context( 'from XML' ) do
6
6
  before( :each ) do
7
- @original_parameter = RCAP::CAP_1_1::Parameter.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :parameters => @original_parameter ))
7
+
8
+ @alert = RCAP::CAP_1_1::Alert.new do |alert|
9
+ alert.add_info.add_parameter do |parameter|
10
+ parameter.name = 'name'
11
+ parameter.value = 'value'
12
+ end
13
+ end
14
+ @original_parameter = @alert.infos.first.parameters.first
9
15
  @xml_string = @alert.to_xml
10
16
  @xml_document = REXML::Document.new( @xml_string )
11
17
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -29,7 +35,10 @@ describe( RCAP::CAP_1_1::Parameter ) do
29
35
 
30
36
  context( 'when exported' ) do
31
37
  before( :each ) do
32
- @parameter = RCAP::CAP_1_1::Parameter.new( :name => 'name', :value => 'value' )
38
+ @parameter = RCAP::CAP_1_1::Parameter.new do |parameter|
39
+ parameter.name = 'name'
40
+ parameter.value = 'value'
41
+ end
33
42
  end
34
43
 
35
44
  context( 'to a hash' ) do
@@ -3,7 +3,10 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_1::Point ) do
4
4
  describe( 'is not valid if' ) do
5
5
  before( :each ) do
6
- @point = RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 )
6
+ @point = RCAP::CAP_1_1::Point.new do |point|
7
+ point.lattitude = 0
8
+ point.longitude = 0
9
+ end
7
10
  @point.should( be_valid )
8
11
  end
9
12
 
@@ -34,7 +37,10 @@ describe( RCAP::CAP_1_1::Point ) do
34
37
 
35
38
  context( 'when exported' ) do
36
39
  before( :each ) do
37
- @point = RCAP::CAP_1_1::Point.new( :lattitude => 1, :longitude => 1 )
40
+ @point = RCAP::CAP_1_1::Point.new do |point|
41
+ point.lattitude = 1
42
+ point.longitude = 1
43
+ end
38
44
  end
39
45
 
40
46
  context( 'to hash' ) do
@@ -3,30 +3,52 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_1::Polygon ) do
4
4
  describe( 'is not valid if it' ) do
5
5
  before( :each ) do
6
- @polygon = RCAP::CAP_1_1::Polygon.new
7
- 3.times do
8
- @polygon.points << RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 )
6
+ @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
7
+ 3.times do
8
+ polygon.add_point do |point|
9
+ point.lattitude = 0
10
+ point.longitude = 0
11
+ end
12
+ end
13
+ @polygon.should( be_valid )
9
14
  end
10
- @polygon.should( be_valid )
11
- end
12
15
 
13
- it( 'does not have any points' ) do
14
- @polygon.points.clear
15
- @polygon.should_not( be_valid )
16
- end
16
+ it( 'does not have any points' ) do
17
+ @polygon.points.clear
18
+ @polygon.should_not( be_valid )
19
+ end
17
20
 
18
- it( 'does not have a valid collection of points' ) do
19
- @polygon.points.first.lattitude = nil
20
- @polygon.should_not( be_valid )
21
+ it( 'does not have a valid collection of points' ) do
22
+ @polygon.points.first.lattitude = nil
23
+ @polygon.should_not( be_valid )
24
+ end
21
25
  end
22
26
  end
23
27
 
24
28
  context( 'on initialization' ) do
25
29
  context( 'from XML' ) do
26
30
  before( :each ) do
27
- @original_polygon = RCAP::CAP_1_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::Point.new( :lattitude => i, :longitude => i )})
31
+ @original_polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
32
+ 3.times do |i|
33
+ polygon.add_point do |point|
34
+ point.lattitude = i
35
+ point.longitude = i
36
+ end
37
+ end
38
+ end
28
39
  @empty_original_polygon = RCAP::CAP_1_1::Polygon.new()
29
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :areas => RCAP::CAP_1_1::Area.new( :polygons => [@original_polygon, @empty_original_polygon] )))
40
+ @alert = RCAP::CAP_1_1::Alert.new
41
+ @alert.add_info.add_area do |area|
42
+ area.add_polygon do |polygon|
43
+ 3.times do |i|
44
+ polygon.add_point do |point|
45
+ point.lattitude = i
46
+ point.longitude = i
47
+ end
48
+ end
49
+ end
50
+ area.add_polygon
51
+ end
30
52
  @xml_string = @alert.to_xml
31
53
  @xml_document = REXML::Document.new( @xml_string )
32
54
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -51,7 +73,14 @@ describe( RCAP::CAP_1_1::Polygon ) do
51
73
 
52
74
  context( 'from a hash' ) do
53
75
  before( :each ) do
54
- @polygon = RCAP::CAP_1_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::Point.new( :lattitude => i, :longitude => i )})
76
+ @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
77
+ 3.times do |i|
78
+ polygon.add_point do |point|
79
+ point.lattitude = i
80
+ point.longitude = i
81
+ end
82
+ end
83
+ end
55
84
  end
56
85
 
57
86
  it( 'should load all the points' ) do
@@ -63,12 +92,19 @@ describe( RCAP::CAP_1_1::Polygon ) do
63
92
 
64
93
  context( 'when exported' ) do
65
94
  before( :each ) do
66
- @polygon = RCAP::CAP_1_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::Point.new( :lattitude => i, :longitude => i )})
95
+ @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
96
+ 3.times do |i|
97
+ polygon.add_point do |point|
98
+ point.lattitude = i
99
+ point.longitude = i
100
+ end
101
+ end
102
+ end
67
103
  end
68
104
 
69
105
  context( 'to a hash' ) do
70
106
  it( 'should export correctly' ) do
71
- @polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
107
+ @polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_a }}
72
108
  end
73
109
  end
74
110
  end
@@ -80,7 +116,10 @@ describe( RCAP::CAP_1_1::Polygon ) do
80
116
 
81
117
  describe( '#add_point' ) do
82
118
  before( :each ) do
83
- @point = @polygon.add_point( lattitude: 1, longitude: 1 )
119
+ @point = @polygon.add_point do |point|
120
+ point.lattitude = 1
121
+ point.longitude = 1
122
+ end
84
123
  end
85
124
 
86
125
  it( 'should return a 1.1 Point' ) do