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.
- 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
@@ -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(
|
8
|
-
@alert = RCAP::CAP_1_2::Alert.new
|
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(
|
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(
|
8
|
-
@alert = RCAP::CAP_1_2::Alert.new
|
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(
|
41
|
+
@geocode = RCAP::CAP_1_2::Geocode.new( &@geocode_builder )
|
34
42
|
end
|
35
43
|
|
36
44
|
context( 'to a hash' ) do
|
data/spec/cap_1_2/info_spec.rb
CHANGED
@@ -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' )
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it( 'should have no
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
it( 'should have no
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
it( 'should have no
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it( 'should have no
|
26
|
-
|
27
|
-
|
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' )
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
it( 'should parse
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
it( 'should parse
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
it( 'should parse
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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(
|
55
|
-
|
56
|
-
|
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(
|
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
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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(
|
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
|
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
|
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
|
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
|
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(
|
8
|
-
@alert = RCAP::CAP_1_2::Alert.new
|
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(
|
40
|
+
@parameter = RCAP::CAP_1_2::Parameter.new( &@parameter_builder )
|
33
41
|
end
|
34
42
|
|
35
43
|
context( 'to a hash' ) do
|
data/spec/cap_1_2/point_spec.rb
CHANGED
@@ -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(
|
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(
|
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 =>
|
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(
|
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
|
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(
|
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(
|
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.
|
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
|
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
|