rcap 2.4.1 → 2.7.3
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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/CHANGELOG.md +18 -0
- data/README.md +1 -0
- data/lib/rcap.rb +3 -1
- data/lib/rcap/alert.rb +30 -29
- data/lib/rcap/base/alert.rb +208 -205
- data/lib/rcap/base/area.rb +95 -91
- data/lib/rcap/base/circle.rb +45 -34
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +273 -272
- data/lib/rcap/base/parameter.rb +29 -28
- data/lib/rcap/base/point.rb +26 -24
- data/lib/rcap/base/polygon.rb +43 -35
- data/lib/rcap/base/resource.rb +65 -65
- data/lib/rcap/cap_1_0/alert.rb +85 -86
- data/lib/rcap/cap_1_0/area.rb +2 -2
- data/lib/rcap/cap_1_0/circle.rb +2 -1
- data/lib/rcap/cap_1_0/event_code.rb +3 -1
- data/lib/rcap/cap_1_0/geocode.rb +3 -1
- data/lib/rcap/cap_1_0/info.rb +3 -3
- data/lib/rcap/cap_1_0/parameter.rb +13 -13
- data/lib/rcap/cap_1_0/point.rb +2 -1
- data/lib/rcap/cap_1_0/polygon.rb +3 -3
- data/lib/rcap/cap_1_0/resource.rb +2 -3
- data/lib/rcap/cap_1_1/alert.rb +6 -6
- data/lib/rcap/cap_1_1/area.rb +2 -2
- data/lib/rcap/cap_1_1/circle.rb +2 -1
- data/lib/rcap/cap_1_1/event_code.rb +3 -1
- data/lib/rcap/cap_1_1/geocode.rb +3 -1
- data/lib/rcap/cap_1_1/info.rb +125 -132
- data/lib/rcap/cap_1_1/parameter.rb +2 -3
- data/lib/rcap/cap_1_1/point.rb +2 -1
- data/lib/rcap/cap_1_1/polygon.rb +3 -3
- data/lib/rcap/cap_1_1/resource.rb +37 -38
- data/lib/rcap/cap_1_2/alert.rb +6 -6
- data/lib/rcap/cap_1_2/area.rb +2 -2
- data/lib/rcap/cap_1_2/circle.rb +2 -1
- data/lib/rcap/cap_1_2/event_code.rb +3 -1
- data/lib/rcap/cap_1_2/geocode.rb +3 -1
- data/lib/rcap/cap_1_2/info.rb +120 -123
- data/lib/rcap/cap_1_2/parameter.rb +2 -3
- data/lib/rcap/cap_1_2/point.rb +2 -1
- data/lib/rcap/cap_1_2/polygon.rb +4 -4
- data/lib/rcap/cap_1_2/resource.rb +38 -38
- data/lib/rcap/config.rb +5 -3
- data/lib/rcap/custom_validators.rb +75 -78
- data/lib/rcap/extensions/array.rb +3 -1
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +5 -2
- data/lib/rcap/extensions/float.rb +2 -0
- data/lib/rcap/extensions/integer.rb +7 -0
- data/lib/rcap/extensions/nil_class.rb +2 -0
- data/lib/rcap/extensions/string.rb +6 -4
- data/lib/rcap/extensions/time.rb +5 -3
- data/lib/rcap/formatters/yaml.rb +5 -0
- data/lib/rcap/info.rb +6 -5
- data/lib/rcap/utilities.rb +27 -30
- data/lib/rcap/validation.rb +22 -21
- data/lib/rcap/version.rb +3 -1
- data/rcap.gemspec +5 -5
- data/spec/alert_spec.rb +141 -141
- data/spec/cap_1_0/alert_spec.rb +92 -94
- data/spec/cap_1_0/area_spec.rb +86 -86
- data/spec/cap_1_0/circle_spec.rb +48 -39
- data/spec/cap_1_0/event_code_spec.rb +15 -15
- data/spec/cap_1_0/geocode_spec.rb +16 -16
- data/spec/cap_1_0/info_spec.rb +175 -177
- data/spec/cap_1_0/parameter_spec.rb +27 -27
- data/spec/cap_1_0/point_spec.rb +18 -18
- data/spec/cap_1_0/polygon_spec.rb +43 -41
- data/spec/cap_1_0/resource_spec.rb +63 -64
- data/spec/cap_1_1/alert_spec.rb +107 -109
- data/spec/cap_1_1/area_spec.rb +90 -90
- data/spec/cap_1_1/circle_spec.rb +43 -34
- data/spec/cap_1_1/event_code_spec.rb +15 -16
- data/spec/cap_1_1/geocode_spec.rb +16 -16
- data/spec/cap_1_1/info_spec.rb +194 -196
- data/spec/cap_1_1/parameter_spec.rb +17 -17
- data/spec/cap_1_1/point_spec.rb +18 -18
- data/spec/cap_1_1/polygon_spec.rb +43 -41
- data/spec/cap_1_1/resource_spec.rb +106 -107
- data/spec/cap_1_2/alert_spec.rb +98 -99
- data/spec/cap_1_2/area_spec.rb +90 -90
- data/spec/cap_1_2/circle_spec.rb +52 -43
- data/spec/cap_1_2/event_code_spec.rb +19 -20
- data/spec/cap_1_2/geocode_spec.rb +20 -20
- data/spec/cap_1_2/info_spec.rb +196 -198
- data/spec/cap_1_2/parameter_spec.rb +19 -19
- data/spec/cap_1_2/point_spec.rb +21 -21
- data/spec/cap_1_2/polygon_spec.rb +55 -47
- data/spec/cap_1_2/resource_spec.rb +96 -97
- data/spec/extensions_spec.rb +29 -29
- data/spec/info_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -3
- data/spec/validations_spec.rb +73 -73
- metadata +12 -11
- data/lib/rcap/extensions/fixnum.rb +0 -5
data/spec/cap_1_0/alert_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_0::Alert) do
|
4
|
+
context('on initialisation') do
|
5
|
+
before(:each) do
|
6
6
|
@alert = RCAP::CAP_1_0::Alert.new
|
7
7
|
|
8
8
|
@original_alert = RCAP::CAP_1_0::Alert.new do |alert|
|
@@ -12,160 +12,158 @@ describe( RCAP::CAP_1_0::Alert ) do
|
|
12
12
|
alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
|
13
13
|
alert.source = 'Source'
|
14
14
|
alert.restriction = 'No Restriction'
|
15
|
-
[
|
15
|
+
['Address 1', 'Address 2'].each do |address|
|
16
16
|
alert.addresses << address
|
17
17
|
end
|
18
|
-
|
18
|
+
%w(Code1 Code2).each do |code|
|
19
19
|
alert.codes << code
|
20
20
|
end
|
21
21
|
alert.note = 'Note'
|
22
|
-
|
22
|
+
%w(Sender1 Sender2).each do |sender|
|
23
23
|
a = RCAP::CAP_1_0::Alert.new do |a|
|
24
24
|
a.sender = sender
|
25
25
|
end
|
26
26
|
alert.references << a.to_reference
|
27
27
|
end
|
28
|
-
|
28
|
+
%w(Incident1 Incident2).each do |incident|
|
29
29
|
alert.incidents << incident
|
30
30
|
end
|
31
|
-
2.times{ alert.add_info }
|
31
|
+
2.times { alert.add_info }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
it(
|
36
|
-
it(
|
37
|
-
it(
|
38
|
-
it(
|
39
|
-
it(
|
40
|
-
it(
|
41
|
-
it(
|
42
|
-
it(
|
43
|
-
it(
|
44
|
-
it(
|
45
|
-
it(
|
46
|
-
it(
|
47
|
-
it(
|
48
|
-
|
49
|
-
shared_examples_for(
|
50
|
-
it(
|
51
|
-
it(
|
52
|
-
it(
|
53
|
-
it(
|
54
|
-
it(
|
55
|
-
it(
|
56
|
-
it(
|
57
|
-
it(
|
58
|
-
it(
|
59
|
-
it(
|
60
|
-
it(
|
61
|
-
it(
|
62
|
-
it(
|
63
|
-
it(
|
35
|
+
it('should have a identifier') { @alert.identifier.should_not(be_nil) }
|
36
|
+
it('should not have a sender') { @alert.sender.should(be_nil) }
|
37
|
+
it('should not have a sent time') { @alert.sent.should(be_nil) }
|
38
|
+
it('should not have a status') { @alert.status.should(be_nil) }
|
39
|
+
it('should not have a scope') { @alert.scope.should(be_nil) }
|
40
|
+
it('should not have a source') { @alert.source.should(be_nil) }
|
41
|
+
it('should not have a restriction') { @alert.restriction.should(be_nil) }
|
42
|
+
it('should not have any addresses') { @alert.addresses.should(be_empty) }
|
43
|
+
it('should not have any codes') { @alert.codes.should(be_empty) }
|
44
|
+
it('should not have a note') { @alert.note.should(be_nil) }
|
45
|
+
it('should not have any references') { @alert.references.should(be_empty) }
|
46
|
+
it('should not have any incidents') { @alert.incidents.should(be_empty) }
|
47
|
+
it('should not have any infos') { @alert.infos.should(be_empty) }
|
48
|
+
|
49
|
+
shared_examples_for('a successfully parsed CAP 1.0 alert') do
|
50
|
+
it('should parse identifier correctly') { @alert.identifier.should == @original_alert.identifier }
|
51
|
+
it('should parse sender correctly') { @alert.sender.should == @original_alert.sender }
|
52
|
+
it('should parse sent correctly') { @alert.sent.should(be_within(1).of(@original_alert.sent)) }
|
53
|
+
it('should parse status correctly') { @alert.status.should == @original_alert.status }
|
54
|
+
it('should parse msg_type correctly') { @alert.msg_type.should == @original_alert.msg_type }
|
55
|
+
it('should parse source correctly') { @alert.source.should == @original_alert.source }
|
56
|
+
it('should parse scope correctly') { @alert.scope.should == @original_alert.scope }
|
57
|
+
it('should parse restriction correctly') { @alert.restriction.should == @original_alert.restriction }
|
58
|
+
it('should parse addresses correctly') { @alert.addresses.should == @original_alert.addresses }
|
59
|
+
it('should parse code correctly') { @alert.codes.should == @original_alert.codes }
|
60
|
+
it('should parse note correctly') { @alert.note.should == @original_alert.note }
|
61
|
+
it('should parse references correctly') { @alert.references.should == @original_alert.references }
|
62
|
+
it('should parse incidents correctly') { @alert.incidents.should == @original_alert.incidents }
|
63
|
+
it('should parse infos correctly') do
|
64
64
|
@alert.infos.size.should == @original_alert.infos.size
|
65
|
-
@alert.infos.each{ |info| info.class.should == RCAP::CAP_1_0::Info }
|
65
|
+
@alert.infos.each { |info| info.class.should == RCAP::CAP_1_0::Info }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context(
|
70
|
-
before(
|
69
|
+
context('from XML') do
|
70
|
+
before(:each) do
|
71
71
|
@xml_string = @original_alert.to_xml
|
72
|
-
@xml_document = REXML::Document.new(
|
72
|
+
@xml_document = REXML::Document.new(@xml_string)
|
73
73
|
@alert_element = @xml_document.root
|
74
|
-
@alert = RCAP::CAP_1_0::Alert.from_xml_element(
|
74
|
+
@alert = RCAP::CAP_1_0::Alert.from_xml_element(@alert_element)
|
75
75
|
end
|
76
76
|
|
77
|
-
it_should_behave_like(
|
77
|
+
it_should_behave_like('a successfully parsed CAP 1.0 alert')
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
|
-
context(
|
82
|
-
before(
|
81
|
+
context('from YAML') do
|
82
|
+
before(:each) do
|
83
83
|
@yaml_string = @original_alert.to_yaml
|
84
|
-
@alert = RCAP::CAP_1_0::Alert.from_yaml(
|
84
|
+
@alert = RCAP::CAP_1_0::Alert.from_yaml(@yaml_string)
|
85
85
|
end
|
86
86
|
|
87
|
-
it_should_behave_like(
|
87
|
+
it_should_behave_like('a successfully parsed CAP 1.0 alert')
|
88
88
|
end
|
89
89
|
|
90
|
-
context(
|
91
|
-
before(
|
92
|
-
@alert = RCAP::CAP_1_0::Alert.from_h(
|
90
|
+
context('from a hash') do
|
91
|
+
before(:each) do
|
92
|
+
@alert = RCAP::CAP_1_0::Alert.from_h(@original_alert.to_h)
|
93
93
|
end
|
94
94
|
|
95
|
-
it_should_behave_like(
|
95
|
+
it_should_behave_like('a successfully parsed CAP 1.0 alert')
|
96
96
|
end
|
97
97
|
|
98
|
-
context(
|
99
|
-
before(
|
100
|
-
@alert = RCAP::CAP_1_0::Alert.from_json(
|
98
|
+
context('from JSON') do
|
99
|
+
before(:each) do
|
100
|
+
@alert = RCAP::CAP_1_0::Alert.from_json(@original_alert.to_json)
|
101
101
|
end
|
102
102
|
|
103
|
-
it_should_behave_like(
|
103
|
+
it_should_behave_like('a successfully parsed CAP 1.0 alert')
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
describe(
|
108
|
-
before(
|
107
|
+
describe('is not valid if it') do
|
108
|
+
before(:each) do
|
109
109
|
@alert = RCAP::CAP_1_0::Alert.new do |alert|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
alert.identifier = 'Identifier'
|
111
|
+
alert.sender = 'cap@tempuri.org'
|
112
|
+
alert.sent = DateTime.now
|
113
|
+
alert.status = RCAP::CAP_1_0::Alert::STATUS_TEST
|
114
|
+
alert.msg_type = RCAP::CAP_1_0::Alert::MSG_TYPE_ALERT
|
115
|
+
alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
|
116
116
|
end
|
117
|
-
@alert.should(
|
117
|
+
@alert.should(be_valid)
|
118
118
|
end
|
119
119
|
|
120
|
-
it(
|
120
|
+
it('does not have a identifier') do
|
121
121
|
@alert.identifier = nil
|
122
|
-
@alert.should_not(
|
122
|
+
@alert.should_not(be_valid)
|
123
123
|
end
|
124
124
|
|
125
|
-
it(
|
125
|
+
it('does not have a sender') do
|
126
126
|
@alert.sender = nil
|
127
|
-
@alert.should_not(
|
127
|
+
@alert.should_not(be_valid)
|
128
128
|
end
|
129
129
|
|
130
|
-
it(
|
130
|
+
it('does not have a sent time (sent)') do
|
131
131
|
@alert.sent = nil
|
132
|
-
@alert.should_not(
|
132
|
+
@alert.should_not(be_valid)
|
133
133
|
end
|
134
134
|
|
135
|
-
it(
|
135
|
+
it('does not have a status') do
|
136
136
|
@alert.status = nil
|
137
|
-
@alert.should_not(
|
137
|
+
@alert.should_not(be_valid)
|
138
138
|
end
|
139
139
|
|
140
|
-
it(
|
140
|
+
it('does not have a message type (msg_type)') do
|
141
141
|
@alert.msg_type = nil
|
142
|
-
@alert.should_not(
|
142
|
+
@alert.should_not(be_valid)
|
143
143
|
end
|
144
144
|
|
145
|
-
it(
|
145
|
+
it('does not have a scope') do
|
146
146
|
@alert.scope = nil
|
147
|
-
@alert.should_not(
|
147
|
+
@alert.should_not(be_valid)
|
148
148
|
end
|
149
149
|
|
150
|
-
|
151
|
-
it( 'does not have a valid status' ) do
|
150
|
+
it('does not have a valid status') do
|
152
151
|
@alert.status = 'incorrect value'
|
153
|
-
@alert.should_not(
|
152
|
+
@alert.should_not(be_valid)
|
154
153
|
end
|
155
154
|
|
156
|
-
it(
|
155
|
+
it('does not have a valid message type msg_type') do
|
157
156
|
@alert.msg_type = 'incorrect value'
|
158
|
-
@alert.should_not(
|
157
|
+
@alert.should_not(be_valid)
|
159
158
|
end
|
160
159
|
|
161
|
-
it(
|
160
|
+
it('does not have a valid scope') do
|
162
161
|
@alert.scope = 'incorrect value'
|
163
|
-
@alert.should_not(
|
162
|
+
@alert.should_not(be_valid)
|
164
163
|
end
|
165
164
|
|
166
|
-
|
167
|
-
|
168
|
-
it( 'is not valid' ) do
|
165
|
+
context('has an info element and it') do
|
166
|
+
it('is not valid') do
|
169
167
|
@info = @alert.add_info do |info|
|
170
168
|
info.event = 'Info Event'
|
171
169
|
info.urgency = RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE
|
@@ -175,19 +173,19 @@ describe( RCAP::CAP_1_0::Alert ) do
|
|
175
173
|
@info.categories << RCAP::CAP_1_0::Info::CATEGORY_GEO
|
176
174
|
@info.event = nil
|
177
175
|
|
178
|
-
@info.should_not(
|
179
|
-
@alert.should_not(
|
176
|
+
@info.should_not(be_valid)
|
177
|
+
@alert.should_not(be_valid)
|
180
178
|
end
|
181
179
|
end
|
182
180
|
end
|
183
181
|
|
184
|
-
describe(
|
185
|
-
before(
|
182
|
+
describe('instance methods') do
|
183
|
+
before(:each) do
|
186
184
|
@alert = RCAP::CAP_1_0::Alert.new
|
187
185
|
end
|
188
186
|
|
189
|
-
describe(
|
190
|
-
before(
|
187
|
+
describe('#add_info') do
|
188
|
+
before(:each) do
|
191
189
|
@info = @alert.add_info do |info|
|
192
190
|
info.urgency = 'urgent'
|
193
191
|
end
|
@@ -195,11 +193,11 @@ describe( RCAP::CAP_1_0::Alert ) do
|
|
195
193
|
@info.urgency.should == 'urgent'
|
196
194
|
end
|
197
195
|
|
198
|
-
it(
|
196
|
+
it('should return a CAP 1.0 Info object') do
|
199
197
|
@info.class.should == RCAP::CAP_1_0::Info
|
200
198
|
end
|
201
199
|
|
202
|
-
it(
|
200
|
+
it('should add an Info object to the infos array') do
|
203
201
|
@alert.infos.size.should == 1
|
204
202
|
end
|
205
203
|
end
|
data/spec/cap_1_0/area_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_0::Area) do
|
4
|
+
context('on initialisation') do
|
5
|
+
before(:each) do
|
6
6
|
@area = RCAP::CAP_1_0::Area.new
|
7
7
|
|
8
8
|
@original_area = RCAP::CAP_1_0::Area.new do |area|
|
@@ -29,77 +29,77 @@ describe( RCAP::CAP_1_0::Area ) do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Atomic
|
32
|
-
it(
|
33
|
-
it(
|
34
|
-
it(
|
32
|
+
it('should not have a area_desc') { @area.area_desc.should(be_nil) }
|
33
|
+
it('should not have a altitude') { @area.altitude.should(be_nil) }
|
34
|
+
it('should not have a ceiling') { @area.ceiling.should(be_nil) }
|
35
35
|
|
36
36
|
# Group
|
37
|
-
it(
|
38
|
-
it(
|
39
|
-
it(
|
37
|
+
it('should have an empty polygons') { @area.polygons.should(be_empty) }
|
38
|
+
it('should have an empty circles') { @area.circles.should(be_empty) }
|
39
|
+
it('should have an empty geocodes') { @area.geocodes.should(be_empty) }
|
40
40
|
|
41
|
-
shared_examples_for(
|
42
|
-
it(
|
41
|
+
shared_examples_for('it can parse into a CAP 1.0 Area object') do
|
42
|
+
it('should parse the area_desc correctly') do
|
43
43
|
@area.area_desc.should == @original_area.area_desc
|
44
44
|
end
|
45
45
|
|
46
|
-
it(
|
46
|
+
it('should parse the altitude correctly') do
|
47
47
|
@area.altitude.should == @original_area.altitude
|
48
48
|
end
|
49
49
|
|
50
|
-
it(
|
50
|
+
it('should parse the ceiling correctly') do
|
51
51
|
@area.ceiling.should == @original_area.ceiling
|
52
52
|
end
|
53
53
|
|
54
|
-
it(
|
54
|
+
it('should parse the circles correctly') do
|
55
55
|
@area.circles.should == @original_area.circles
|
56
56
|
end
|
57
57
|
|
58
|
-
it(
|
58
|
+
it('should parse the geocodes correctly') do
|
59
59
|
@area.geocodes.should == @original_area.geocodes
|
60
60
|
end
|
61
61
|
|
62
|
-
it(
|
62
|
+
it('should parse the polygons correctly') do
|
63
63
|
@area.polygons.should == @original_area.polygons
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context(
|
68
|
-
before(
|
67
|
+
context('from XML') do
|
68
|
+
before(:each) do
|
69
69
|
|
70
70
|
@alert = RCAP::CAP_1_0::Alert.new
|
71
71
|
@alert.add_info.areas << @original_area
|
72
72
|
@xml_string = @alert.to_xml
|
73
|
-
@xml_document = REXML::Document.new(
|
74
|
-
@info_xml_element = RCAP.xpath_first(
|
75
|
-
@area_xml_element = RCAP.xpath_first(
|
76
|
-
@area = RCAP::CAP_1_0::Area.from_xml_element(
|
73
|
+
@xml_document = REXML::Document.new(@xml_string)
|
74
|
+
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
|
75
|
+
@area_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
|
76
|
+
@area = RCAP::CAP_1_0::Area.from_xml_element(@area_xml_element)
|
77
77
|
end
|
78
78
|
|
79
|
-
it_should_behave_like(
|
79
|
+
it_should_behave_like('it can parse into a CAP 1.0 Area object')
|
80
80
|
end
|
81
81
|
|
82
|
-
context(
|
83
|
-
before(
|
82
|
+
context('from YAML Data') do
|
83
|
+
before(:each) do
|
84
84
|
|
85
|
-
@area = RCAP::CAP_1_0::Area.from_yaml_data(
|
85
|
+
@area = RCAP::CAP_1_0::Area.from_yaml_data(YAML.load(@original_area.to_yaml))
|
86
86
|
end
|
87
87
|
|
88
|
-
it_should_behave_like(
|
88
|
+
it_should_behave_like('it can parse into a CAP 1.0 Area object')
|
89
89
|
end
|
90
90
|
|
91
|
-
context(
|
92
|
-
before(
|
91
|
+
context('from a hash') do
|
92
|
+
before(:each) do
|
93
93
|
|
94
|
-
@area = RCAP::CAP_1_0::Area.from_h(
|
94
|
+
@area = RCAP::CAP_1_0::Area.from_h(@original_area.to_h)
|
95
95
|
end
|
96
96
|
|
97
|
-
it_should_behave_like(
|
97
|
+
it_should_behave_like('it can parse into a CAP 1.0 Area object')
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
context(
|
102
|
-
before(
|
101
|
+
context('when exported') do
|
102
|
+
before(:each) do
|
103
103
|
@area = RCAP::CAP_1_0::Area.new do |area|
|
104
104
|
area.area_desc = 'Area Description'
|
105
105
|
area.altitude = 100
|
@@ -123,76 +123,76 @@ describe( RCAP::CAP_1_0::Area ) do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
context(
|
127
|
-
before(
|
126
|
+
context('to a hash') do
|
127
|
+
before(:each) do
|
128
128
|
@area_hash = @area.to_h
|
129
129
|
end
|
130
130
|
|
131
|
-
it(
|
132
|
-
@area_hash[ RCAP::CAP_1_0::Area::AREA_DESC_KEY
|
131
|
+
it('should export the area description correctly') do
|
132
|
+
@area_hash[ RCAP::CAP_1_0::Area::AREA_DESC_KEY].should == @area.area_desc
|
133
133
|
end
|
134
134
|
|
135
|
-
it(
|
136
|
-
@area_hash[ RCAP::CAP_1_0::Area::ALTITUDE_KEY
|
135
|
+
it('should export the altitude correctly') do
|
136
|
+
@area_hash[ RCAP::CAP_1_0::Area::ALTITUDE_KEY].should == @area.altitude
|
137
137
|
end
|
138
138
|
|
139
|
-
it(
|
140
|
-
@area_hash[ RCAP::CAP_1_0::Area::CEILING_KEY
|
139
|
+
it('should set the ceiling correctly') do
|
140
|
+
@area_hash[ RCAP::CAP_1_0::Area::CEILING_KEY].should == @area.ceiling
|
141
141
|
end
|
142
142
|
|
143
|
-
it(
|
144
|
-
@area_hash[ RCAP::CAP_1_0::Area::CIRCLES_KEY
|
143
|
+
it('should export the circles correctly') do
|
144
|
+
@area_hash[ RCAP::CAP_1_0::Area::CIRCLES_KEY].should == @area.circles.map { |circle| circle.to_a }
|
145
145
|
end
|
146
146
|
|
147
|
-
it(
|
148
|
-
@area_hash[ RCAP::CAP_1_0::Area::GEOCODES_KEY
|
147
|
+
it('should export the geocodes correctly') do
|
148
|
+
@area_hash[ RCAP::CAP_1_0::Area::GEOCODES_KEY].should == @area.geocodes.map { |geocode| geocode.to_h }
|
149
149
|
end
|
150
150
|
|
151
|
-
it(
|
152
|
-
@area_hash[ RCAP::CAP_1_0::Area::POLYGONS_KEY
|
151
|
+
it('should export the polygons correctly') do
|
152
|
+
@area_hash[ RCAP::CAP_1_0::Area::POLYGONS_KEY].should == @area.polygons.map { |polygon| polygon.to_h }
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
context(
|
158
|
-
before(
|
157
|
+
context('is not valid if') do
|
158
|
+
before(:each) do
|
159
159
|
@area = RCAP::CAP_1_0::Area.new do |area|
|
160
|
-
area.area_desc =
|
160
|
+
area.area_desc = 'Cape Town Metropole'
|
161
161
|
end
|
162
|
-
@area.should(
|
162
|
+
@area.should(be_valid)
|
163
163
|
end
|
164
164
|
|
165
|
-
it(
|
165
|
+
it('does not have an area descrtiption (area_desc)') do
|
166
166
|
@area.area_desc = nil
|
167
|
-
@area.should_not(
|
167
|
+
@area.should_not(be_valid)
|
168
168
|
end
|
169
169
|
|
170
|
-
it(
|
170
|
+
it('has a ceiling defined but no altitude') do
|
171
171
|
@area.ceiling = 1
|
172
172
|
@area.altitude = nil
|
173
|
-
@area.should_not(
|
173
|
+
@area.should_not(be_valid)
|
174
174
|
end
|
175
175
|
|
176
|
-
context(
|
177
|
-
before(
|
176
|
+
context('it contains circles and it') do
|
177
|
+
before(:each) do
|
178
178
|
@area.add_circle do |circle|
|
179
179
|
circle.lattitude = 0
|
180
180
|
circle.longitude = 0
|
181
181
|
circle.radius = 1
|
182
182
|
end
|
183
|
-
@area.should(
|
183
|
+
@area.should(be_valid)
|
184
184
|
end
|
185
185
|
|
186
|
-
it(
|
186
|
+
it('has an invalid circle') do
|
187
187
|
@area.circles.first.lattitude = nil
|
188
|
-
@area.should_not(
|
188
|
+
@area.should_not(be_valid)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
context(
|
193
|
-
before(
|
192
|
+
context('it contains polygons and it') do
|
193
|
+
before(:each) do
|
194
194
|
@polygon = RCAP::CAP_1_0::Polygon.new
|
195
|
-
[[
|
195
|
+
[[0, 0], [0, 1], [0, 0]].each do |lattitude, longitude|
|
196
196
|
@polygon.add_point do |point|
|
197
197
|
point.lattitude = lattitude
|
198
198
|
point.longitude = longitude
|
@@ -200,52 +200,52 @@ describe( RCAP::CAP_1_0::Area ) do
|
|
200
200
|
end
|
201
201
|
|
202
202
|
@area.polygons << @polygon
|
203
|
-
@area.should(
|
203
|
+
@area.should(be_valid)
|
204
204
|
end
|
205
205
|
|
206
|
-
it(
|
206
|
+
it('has an invalid polygon') do
|
207
207
|
@polygon.points.first.lattitude = nil
|
208
|
-
@area.should_not(
|
208
|
+
@area.should_not(be_valid)
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
-
context(
|
213
|
-
before(
|
212
|
+
context('it contains geocodes and it') do
|
213
|
+
before(:each) do
|
214
214
|
@area.add_geocode do |geocode|
|
215
215
|
geocode.name = 'foo'
|
216
216
|
geocode.value = 'bar'
|
217
217
|
end
|
218
|
-
@area.should(
|
218
|
+
@area.should(be_valid)
|
219
219
|
end
|
220
220
|
|
221
|
-
it(
|
222
|
-
@area.geocodes.first.
|
223
|
-
@area.should_not(
|
221
|
+
it('has an invalid geocode') do
|
222
|
+
@area.geocodes.first.name = nil
|
223
|
+
@area.should_not(be_valid)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
describe(
|
229
|
-
before(
|
228
|
+
describe('instance methods') do
|
229
|
+
before(:each) do
|
230
230
|
@area = RCAP::CAP_1_0::Area.new
|
231
231
|
end
|
232
232
|
|
233
|
-
describe(
|
234
|
-
before(
|
233
|
+
describe('#add_polygon') do
|
234
|
+
before(:each) do
|
235
235
|
@polygon = @area.add_polygon
|
236
236
|
end
|
237
237
|
|
238
|
-
it(
|
238
|
+
it('should return a CAP 1.0 Polygon') do
|
239
239
|
@polygon.class.should == RCAP::CAP_1_0::Polygon
|
240
240
|
end
|
241
241
|
|
242
|
-
it(
|
242
|
+
it('should add a Polygon to the polygons attribute') do
|
243
243
|
@area.polygons.size.should == 1
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
247
|
-
describe(
|
248
|
-
before(
|
247
|
+
describe('#add_circle') do
|
248
|
+
before(:each) do
|
249
249
|
@circle = @area.add_circle do |circle|
|
250
250
|
circle.lattitude = 1
|
251
251
|
circle.longitude = 1
|
@@ -253,33 +253,33 @@ describe( RCAP::CAP_1_0::Area ) do
|
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
|
-
it(
|
256
|
+
it('should return a CAP 1.0 Circle') do
|
257
257
|
@circle.class.should == RCAP::CAP_1_0::Circle
|
258
258
|
@circle.lattitude.should == 1
|
259
259
|
@circle.longitude.should == 1
|
260
260
|
@circle.radius.should == 1
|
261
261
|
end
|
262
262
|
|
263
|
-
it(
|
263
|
+
it('should add a circle to the circles attribute') do
|
264
264
|
@area.circles.size.should == 1
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
|
-
describe(
|
269
|
-
before(
|
268
|
+
describe('#add_geocode') do
|
269
|
+
before(:each) do
|
270
270
|
@geocode = @area.add_geocode do |geocode|
|
271
271
|
geocode.name = 'Geocode'
|
272
272
|
geocode.value = '123'
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
|
-
it(
|
276
|
+
it('should return a CAP 1.0 Geocode') do
|
277
277
|
@geocode.class.should == RCAP::CAP_1_0::Geocode
|
278
278
|
@geocode.name.should == 'Geocode'
|
279
279
|
@geocode.value.should == '123'
|
280
280
|
end
|
281
281
|
|
282
|
-
it(
|
282
|
+
it('should add a geocode to the geocodes attribute') do
|
283
283
|
@area.geocodes.size.should == 1
|
284
284
|
end
|
285
285
|
end
|