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