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_1/circle_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
describe(
|
5
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Circle) do
|
4
|
+
describe('should not be valid if') do
|
5
|
+
before(:each) do
|
6
6
|
@circle = RCAP::CAP_1_1::Circle.new do |circle|
|
7
7
|
circle.lattitude = 0
|
8
8
|
circle.longitude = 0
|
9
9
|
circle.radius = 0
|
10
10
|
end
|
11
11
|
|
12
|
-
@circle.should(
|
12
|
+
@circle.should(be_valid)
|
13
13
|
end
|
14
14
|
|
15
|
-
it(
|
15
|
+
it('does not have a lattitude defined') do
|
16
16
|
@circle.lattitude = nil
|
17
|
-
@circle.should_not(
|
17
|
+
@circle.should_not(be_valid)
|
18
18
|
end
|
19
19
|
|
20
|
-
it(
|
20
|
+
it('does not have a longitude defined') do
|
21
21
|
@circle.longitude = nil
|
22
|
-
@circle.should_not(
|
22
|
+
@circle.should_not(be_valid)
|
23
23
|
end
|
24
24
|
|
25
|
-
it(
|
25
|
+
it('does not have a radius defined') do
|
26
26
|
@circle.radius = nil
|
27
|
-
@circle.should_not(
|
27
|
+
@circle.should_not(be_valid)
|
28
28
|
end
|
29
29
|
|
30
|
-
it(
|
31
|
-
@circle.radius =
|
32
|
-
@circle.should_not(
|
30
|
+
it('does not have a numeric radius') do
|
31
|
+
@circle.radius = 'not a number'
|
32
|
+
@circle.should_not(be_valid)
|
33
33
|
end
|
34
34
|
|
35
|
-
it(
|
35
|
+
it('does not have a positive radius') do
|
36
36
|
@circle.radius = -1
|
37
|
-
@circle.should_not(
|
37
|
+
@circle.should_not(be_valid)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context(
|
42
|
-
context(
|
43
|
-
before(
|
41
|
+
context('on initialisation') do
|
42
|
+
context('from XML') do
|
43
|
+
before(:each) do
|
44
44
|
@original_circle = RCAP::CAP_1_1::Circle.new do |circle|
|
45
45
|
circle.lattitude = 30
|
46
46
|
circle.longitude = 60
|
@@ -55,46 +55,46 @@ describe( RCAP::CAP_1_1::Circle ) do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
@xml_string = @alert.to_xml
|
58
|
-
@xml_document = REXML::Document.new(
|
59
|
-
@info_element = RCAP.xpath_first(
|
60
|
-
@area_element = RCAP.xpath_first(
|
61
|
-
@circle_element = RCAP.xpath_first(
|
62
|
-
@circle = RCAP::CAP_1_1::Circle.from_xml_element(
|
58
|
+
@xml_document = REXML::Document.new(@xml_string)
|
59
|
+
@info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
60
|
+
@area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
61
|
+
@circle_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_1::Circle::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
62
|
+
@circle = RCAP::CAP_1_1::Circle.from_xml_element(@circle_element)
|
63
63
|
end
|
64
64
|
|
65
|
-
it(
|
65
|
+
it('should parse the radius correctly') do
|
66
66
|
@circle.radius.should == @original_circle.radius
|
67
67
|
end
|
68
68
|
|
69
|
-
it(
|
69
|
+
it('should parse the lattitude and longitude correctly') do
|
70
70
|
@circle.lattitude.should == @original_circle.lattitude
|
71
71
|
@circle.longitude.should == @original_circle.longitude
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context(
|
76
|
-
before(
|
75
|
+
context('from a hash') do
|
76
|
+
before(:each) do
|
77
77
|
@original_circle = RCAP::CAP_1_1::Circle.new do |circle|
|
78
78
|
circle.lattitude = 30
|
79
79
|
circle.longitude = 60
|
80
80
|
circle.radius = 10.5
|
81
81
|
end
|
82
|
-
@circle = RCAP::CAP_1_1::Circle.from_h(
|
82
|
+
@circle = RCAP::CAP_1_1::Circle.from_h(@original_circle.to_h)
|
83
83
|
end
|
84
84
|
|
85
|
-
it(
|
85
|
+
it('should set the radius correctly') do
|
86
86
|
@circle.radius.should == @original_circle.radius
|
87
87
|
end
|
88
88
|
|
89
|
-
it(
|
89
|
+
it('should parse the lattitude and longitude correctly') do
|
90
90
|
@circle.lattitude.should == @original_circle.lattitude
|
91
91
|
@circle.longitude.should == @original_circle.longitude
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
context(
|
97
|
-
before(
|
96
|
+
context('when exported') do
|
97
|
+
before(:each) do
|
98
98
|
@circle = RCAP::CAP_1_1::Circle.new do |circle|
|
99
99
|
circle.lattitude = 30
|
100
100
|
circle.longitude = 60
|
@@ -102,8 +102,17 @@ describe( RCAP::CAP_1_1::Circle ) do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
context(
|
106
|
-
it(
|
105
|
+
context('to geojson') do
|
106
|
+
it('should be valid geojson') do
|
107
|
+
@circle.longitude = 5.6
|
108
|
+
expected = '{"type":"Feature","geometry":{"type":"Point",' \
|
109
|
+
'"coordinates":[5.6,30]},"properties":{"radius":10.5}}'
|
110
|
+
expect(@circle.to_geojson).to eq expected
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context('to hash') do
|
115
|
+
it('should be correct') do
|
107
116
|
@circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
|
108
117
|
end
|
109
118
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
context(
|
6
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::EventCode) do
|
4
|
+
context('when initialised') do
|
5
|
+
context('from XML') do
|
6
|
+
before(:each) do
|
7
7
|
@alert = RCAP::CAP_1_1::Alert.new do |alert|
|
8
8
|
alert.add_info.add_event_code do |event_code|
|
9
9
|
event_code.name = 'name'
|
@@ -12,39 +12,38 @@ describe( RCAP::CAP_1_1::EventCode ) do
|
|
12
12
|
end
|
13
13
|
@original_event_code = @alert.infos.first.event_codes.first
|
14
14
|
@xml_string = @alert.to_xml
|
15
|
-
@xml_document = REXML::Document.new(
|
16
|
-
@info_xml_element = RCAP.xpath_first(
|
17
|
-
@event_code_xml_element = RCAP.xpath_first(
|
18
|
-
@event_code = RCAP::CAP_1_1::EventCode.from_xml_element(
|
15
|
+
@xml_document = REXML::Document.new(@xml_string)
|
16
|
+
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
17
|
+
@event_code_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_1::EventCode::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
18
|
+
@event_code = RCAP::CAP_1_1::EventCode.from_xml_element(@event_code_xml_element)
|
19
19
|
end
|
20
20
|
|
21
|
-
it(
|
21
|
+
it('should parse into the correct class') do
|
22
22
|
@event_code.class.should == RCAP::CAP_1_1::EventCode
|
23
23
|
end
|
24
24
|
|
25
|
-
it(
|
25
|
+
it('should parse the name correctly') do
|
26
26
|
@event_code.name.should == @original_event_code.name
|
27
27
|
end
|
28
28
|
|
29
|
-
it(
|
29
|
+
it('should parse the value correctly') do
|
30
30
|
@event_code.value.should == @original_event_code.value
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context(
|
36
|
-
before(
|
35
|
+
context('when exported') do
|
36
|
+
before(:each) do
|
37
37
|
@event_code = RCAP::CAP_1_1::EventCode.new do |event_code|
|
38
38
|
event_code.name = 'name'
|
39
39
|
event_code.value = 'value'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context(
|
44
|
-
it(
|
43
|
+
context('to a hash') do
|
44
|
+
it('should export correctly') do
|
45
45
|
@event_code.to_h.should == { 'name' => 'value' }
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
context(
|
5
|
-
context(
|
6
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Geocode) do
|
4
|
+
context('when initialised') do
|
5
|
+
context('from XML') do
|
6
|
+
before(:each) do
|
7
7
|
@alert = RCAP::CAP_1_1::Alert.new do |alert|
|
8
8
|
alert.add_info.add_area.add_geocode do |geocode|
|
9
9
|
geocode.name = 'name'
|
@@ -12,37 +12,37 @@ describe( RCAP::CAP_1_1::Geocode ) do
|
|
12
12
|
end
|
13
13
|
@original_geocode = @alert.infos.first.areas.first.geocodes.first
|
14
14
|
@xml_string = @alert.to_xml
|
15
|
-
@xml_document = REXML::Document.new(
|
16
|
-
@info_xml_element = RCAP.xpath_first(
|
17
|
-
@area_xml_element = RCAP.xpath_first(
|
18
|
-
@geocode_xml_element = RCAP.xpath_first(
|
19
|
-
@geocode = RCAP::CAP_1_1::Geocode.from_xml_element(
|
15
|
+
@xml_document = REXML::Document.new(@xml_string)
|
16
|
+
@info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
17
|
+
@area_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
18
|
+
@geocode_xml_element = RCAP.xpath_first(@area_xml_element, RCAP::CAP_1_1::Geocode::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
|
19
|
+
@geocode = RCAP::CAP_1_1::Geocode.from_xml_element(@geocode_xml_element)
|
20
20
|
end
|
21
21
|
|
22
|
-
it(
|
22
|
+
it('should parse into the correct class') do
|
23
23
|
@geocode.class.should == RCAP::CAP_1_1::Geocode
|
24
24
|
end
|
25
25
|
|
26
|
-
it(
|
26
|
+
it('should parse the name correctly') do
|
27
27
|
@geocode.name.should == @original_geocode.name
|
28
28
|
end
|
29
29
|
|
30
|
-
it(
|
30
|
+
it('should parse the value correctly') do
|
31
31
|
@geocode.value.should == @original_geocode.value
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context(
|
37
|
-
before(
|
36
|
+
context('when exported') do
|
37
|
+
before(:each) do
|
38
38
|
@geocode = RCAP::CAP_1_1::Geocode.new do |geocode|
|
39
39
|
geocode.name = 'name'
|
40
40
|
geocode.value = 'value'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
context(
|
45
|
-
it(
|
44
|
+
context('to a hash') do
|
45
|
+
it('should export correctly') do
|
46
46
|
@geocode.to_h.should == { 'name' => 'value' }
|
47
47
|
end
|
48
48
|
end
|
data/spec/cap_1_1/info_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe(
|
4
|
-
before(
|
3
|
+
describe(RCAP::CAP_1_1::Info) do
|
4
|
+
before(:each) do
|
5
5
|
@info_constructor = lambda do |info|
|
6
|
-
[
|
6
|
+
[RCAP::CAP_1_1::Info::CATEGORY_GEO, RCAP::CAP_1_1::Info::CATEGORY_FIRE].each do |category|
|
7
7
|
info.categories << category
|
8
8
|
end
|
9
9
|
|
10
10
|
info.event = 'Event Description'
|
11
11
|
|
12
|
-
[
|
12
|
+
[RCAP::CAP_1_1::Info::RESPONSE_TYPE_MONITOR, RCAP::CAP_1_1::Info::RESPONSE_TYPE_ASSESS].each do |response_type|
|
13
13
|
info.response_types << response_type
|
14
14
|
end
|
15
15
|
|
@@ -32,21 +32,21 @@ describe( RCAP::CAP_1_1::Info ) do
|
|
32
32
|
resource.uri = 'http://tempuri.org/resource'
|
33
33
|
end
|
34
34
|
|
35
|
-
[{ :
|
35
|
+
[{ name: 'name1', value: 'value1' }, { name: 'name2', value: 'value2' }].each do |event_code_hash|
|
36
36
|
info.add_event_code do |event_code|
|
37
|
-
event_code.name = event_code_hash[ :name
|
38
|
-
event_code.value = event_code_hash[ :value
|
37
|
+
event_code.name = event_code_hash[ :name]
|
38
|
+
event_code.value = event_code_hash[ :value]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
[{ :
|
42
|
+
[{ name: 'name1', value: 'value1' }, { name: 'name2', value: 'value2' }].each do |parameter_hash|
|
43
43
|
info.add_parameter do |parameter|
|
44
|
-
parameter.name = parameter_hash[ :name
|
45
|
-
parameter.value = parameter_hash[ :value
|
44
|
+
parameter.name = parameter_hash[ :name]
|
45
|
+
parameter.value = parameter_hash[ :value]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
49
|
+
%w(Area1 Area2).each do |area_desc|
|
50
50
|
info.add_area do |area|
|
51
51
|
area.area_desc = area_desc
|
52
52
|
end
|
@@ -54,221 +54,220 @@ describe( RCAP::CAP_1_1::Info ) do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context(
|
58
|
-
before(
|
57
|
+
context('on initialisation') do
|
58
|
+
before(:each) do
|
59
59
|
@info = RCAP::CAP_1_1::Info.new
|
60
60
|
end
|
61
61
|
|
62
|
-
it(
|
62
|
+
it('should have a default language of en-US') do
|
63
63
|
@info.language.should == 'en-US'
|
64
64
|
end
|
65
65
|
|
66
|
-
it(
|
67
|
-
@info.categories.should(
|
66
|
+
it('should have no categories') do
|
67
|
+
@info.categories.should(be_empty)
|
68
68
|
end
|
69
69
|
|
70
|
-
it(
|
71
|
-
@info.event.should(
|
70
|
+
it('should have no event') do
|
71
|
+
@info.event.should(be_nil)
|
72
72
|
end
|
73
73
|
|
74
|
-
it(
|
75
|
-
@info.response_types.should(
|
74
|
+
it('should have no response types') do
|
75
|
+
@info.response_types.should(be_empty)
|
76
76
|
end
|
77
77
|
|
78
|
-
it(
|
79
|
-
@info.urgency.should(
|
78
|
+
it('should have no urgency') do
|
79
|
+
@info.urgency.should(be_nil)
|
80
80
|
end
|
81
81
|
|
82
|
-
it(
|
83
|
-
@info.severity.should(
|
82
|
+
it('should have no severity') do
|
83
|
+
@info.severity.should(be_nil)
|
84
84
|
end
|
85
85
|
|
86
|
-
it(
|
87
|
-
@info.certainty.should(
|
86
|
+
it('should have no certainty') do
|
87
|
+
@info.certainty.should(be_nil)
|
88
88
|
end
|
89
89
|
|
90
|
-
it(
|
91
|
-
@info.audience.should(
|
90
|
+
it('should have no audience') do
|
91
|
+
@info.audience.should(be_nil)
|
92
92
|
end
|
93
93
|
|
94
|
-
it(
|
95
|
-
@info.event_codes.should(
|
94
|
+
it('should have no event_codes') do
|
95
|
+
@info.event_codes.should(be_empty)
|
96
96
|
end
|
97
97
|
|
98
|
-
it(
|
99
|
-
@info.effective.should(
|
98
|
+
it('should have no effective datetime') do
|
99
|
+
@info.effective.should(be_nil)
|
100
100
|
end
|
101
101
|
|
102
|
-
it(
|
103
|
-
@info.onset.should(
|
102
|
+
it('should have no onset datetime') do
|
103
|
+
@info.onset.should(be_nil)
|
104
104
|
end
|
105
105
|
|
106
|
-
it(
|
107
|
-
@info.expires.should(
|
106
|
+
it('should have no expires datetime') do
|
107
|
+
@info.expires.should(be_nil)
|
108
108
|
end
|
109
109
|
|
110
|
-
it(
|
111
|
-
@info.sender_name.should(
|
110
|
+
it('should have no sender name ') do
|
111
|
+
@info.sender_name.should(be_nil)
|
112
112
|
end
|
113
113
|
|
114
|
-
it(
|
115
|
-
@info.headline.should(
|
114
|
+
it('should have no headline') do
|
115
|
+
@info.headline.should(be_nil)
|
116
116
|
end
|
117
117
|
|
118
|
-
it(
|
119
|
-
@info.description.should(
|
118
|
+
it('should have no description') do
|
119
|
+
@info.description.should(be_nil)
|
120
120
|
end
|
121
121
|
|
122
|
-
it(
|
123
|
-
@info.instruction.should(
|
122
|
+
it('should have no instruction') do
|
123
|
+
@info.instruction.should(be_nil)
|
124
124
|
end
|
125
125
|
|
126
|
-
it(
|
127
|
-
@info.web.should(
|
126
|
+
it('should have no web') do
|
127
|
+
@info.web.should(be_nil)
|
128
128
|
end
|
129
129
|
|
130
|
-
it(
|
131
|
-
@info.contact.should(
|
130
|
+
it('should have no contact') do
|
131
|
+
@info.contact.should(be_nil)
|
132
132
|
end
|
133
133
|
|
134
|
-
it(
|
135
|
-
@info.parameters.should(
|
134
|
+
it('should have no parameters') do
|
135
|
+
@info.parameters.should(be_empty)
|
136
136
|
end
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
@info.categories.should_not( be_nil )
|
138
|
+
shared_examples_for('it can parse into a CAP 1.1 Info object') do
|
139
|
+
it('should parse categories correctly') do
|
140
|
+
@info.categories.should_not(be_nil)
|
142
141
|
@info.categories.should == @original_info.categories
|
143
142
|
end
|
144
143
|
|
145
|
-
it(
|
146
|
-
@info.event.should_not(
|
144
|
+
it('should parse event correctly') do
|
145
|
+
@info.event.should_not(be_nil)
|
147
146
|
@info.event.should == @original_info.event
|
148
147
|
end
|
149
148
|
|
150
|
-
it(
|
151
|
-
@info.response_types.should_not(
|
149
|
+
it('should parse response_types correctly') do
|
150
|
+
@info.response_types.should_not(be_nil)
|
152
151
|
@info.response_types.should == @original_info.response_types
|
153
152
|
end
|
154
153
|
|
155
|
-
it(
|
156
|
-
@info.urgency.should_not(
|
154
|
+
it('should parse urgency correctly') do
|
155
|
+
@info.urgency.should_not(be_nil)
|
157
156
|
@info.urgency.should == @original_info.urgency
|
158
157
|
end
|
159
158
|
|
160
|
-
it(
|
161
|
-
@info.severity.should_not(
|
159
|
+
it('should parse severity correctly') do
|
160
|
+
@info.severity.should_not(be_nil)
|
162
161
|
@info.severity.should == @original_info.severity
|
163
162
|
end
|
164
163
|
|
165
|
-
it(
|
166
|
-
@info.certainty.should_not(
|
164
|
+
it('should parse certainty correctly') do
|
165
|
+
@info.certainty.should_not(be_nil)
|
167
166
|
@info.certainty.should == @original_info.certainty
|
168
167
|
end
|
169
168
|
|
170
|
-
it(
|
171
|
-
@info.audience.should_not(
|
169
|
+
it('should parse audience correctly') do
|
170
|
+
@info.audience.should_not(be_nil)
|
172
171
|
@info.audience.should == @original_info.audience
|
173
172
|
end
|
174
173
|
|
175
|
-
it(
|
176
|
-
@info.effective.should_not(
|
177
|
-
@info.effective.should(
|
174
|
+
it('should parse effective correctly') do
|
175
|
+
@info.effective.should_not(be_nil)
|
176
|
+
@info.effective.should(be_within(Rational(1, 86_400)).of(@original_info.effective))
|
178
177
|
end
|
179
178
|
|
180
|
-
it(
|
181
|
-
@info.onset.should_not(
|
182
|
-
@info.onset.should(
|
179
|
+
it('should parse onset correctly') do
|
180
|
+
@info.onset.should_not(be_nil)
|
181
|
+
@info.onset.should(be_within(Rational(1, 86_400)).of(@original_info.onset))
|
183
182
|
end
|
184
183
|
|
185
|
-
it(
|
186
|
-
@info.expires.should_not(
|
187
|
-
@info.expires.should(
|
184
|
+
it('should parse expires correctly') do
|
185
|
+
@info.expires.should_not(be_nil)
|
186
|
+
@info.expires.should(be_within(Rational(1, 86_400)).of(@original_info.expires))
|
188
187
|
end
|
189
188
|
|
190
|
-
it(
|
191
|
-
@info.sender_name.should_not(
|
189
|
+
it('should parse sender_name correctly') do
|
190
|
+
@info.sender_name.should_not(be_nil)
|
192
191
|
@info.sender_name.should == @original_info.sender_name
|
193
192
|
end
|
194
193
|
|
195
|
-
it(
|
196
|
-
@info.headline.should_not(
|
194
|
+
it('should parse headline correctly') do
|
195
|
+
@info.headline.should_not(be_nil)
|
197
196
|
@info.headline.should == @original_info.headline
|
198
197
|
end
|
199
198
|
|
200
|
-
it(
|
201
|
-
@info.description.should_not(
|
199
|
+
it('should parse description correctly') do
|
200
|
+
@info.description.should_not(be_nil)
|
202
201
|
@info.description.should == @original_info.description
|
203
202
|
end
|
204
203
|
|
205
|
-
it(
|
206
|
-
@info.instruction.should_not(
|
204
|
+
it('should parse instruction correctly') do
|
205
|
+
@info.instruction.should_not(be_nil)
|
207
206
|
@info.instruction.should == @original_info.instruction
|
208
207
|
end
|
209
208
|
|
210
|
-
it(
|
211
|
-
@info.web.should_not(
|
209
|
+
it('should parse web correctly') do
|
210
|
+
@info.web.should_not(be_nil)
|
212
211
|
@info.web.should == @original_info.web
|
213
212
|
end
|
214
213
|
|
215
|
-
it(
|
216
|
-
@info.contact.should_not(
|
214
|
+
it('should parse contact correctly') do
|
215
|
+
@info.contact.should_not(be_nil)
|
217
216
|
@info.contact.should == @original_info.contact
|
218
217
|
end
|
219
218
|
|
220
|
-
it(
|
221
|
-
@info.event_codes.should_not(
|
219
|
+
it('should parse event_codes correctly') do
|
220
|
+
@info.event_codes.should_not(be_nil)
|
222
221
|
@info.event_codes.should == @original_info.event_codes
|
223
222
|
end
|
224
223
|
|
225
|
-
it(
|
226
|
-
@info.parameters.should_not(
|
224
|
+
it('should parse parameters correctly') do
|
225
|
+
@info.parameters.should_not(be_nil)
|
227
226
|
@info.parameters.should == @original_info.parameters
|
228
227
|
end
|
229
228
|
|
230
|
-
it(
|
231
|
-
@info.resources.should_not(
|
229
|
+
it('should parse resources correctly') do
|
230
|
+
@info.resources.should_not(be_empty)
|
232
231
|
|
233
232
|
comparison_attributes = lambda do |resource|
|
234
233
|
resource.resource_desc
|
235
234
|
resource.uri
|
236
235
|
end
|
237
|
-
@info.resources.map(
|
236
|
+
@info.resources.map(&comparison_attributes).should == @original_info.resources.map(&comparison_attributes)
|
238
237
|
end
|
239
238
|
|
240
|
-
it(
|
241
|
-
@info.areas.should_not(
|
239
|
+
it('should parse areas correctly') do
|
240
|
+
@info.areas.should_not(be_nil)
|
242
241
|
@info.areas.should == @original_info.areas
|
243
242
|
end
|
244
243
|
end
|
245
244
|
|
246
|
-
context(
|
247
|
-
before(
|
248
|
-
@original_info = RCAP::CAP_1_1::Info.new(
|
245
|
+
context('from XML') do
|
246
|
+
before(:each) do
|
247
|
+
@original_info = RCAP::CAP_1_1::Info.new(&@info_constructor)
|
249
248
|
@alert = RCAP::CAP_1_1::Alert.new
|
250
|
-
@alert.add_info(
|
249
|
+
@alert.add_info(&@info_constructor)
|
251
250
|
@xml_string = @alert.to_xml
|
252
|
-
@xml_document = REXML::Document.new(
|
253
|
-
@info = RCAP::CAP_1_1::Info.from_xml_element(
|
251
|
+
@xml_document = REXML::Document.new(@xml_string)
|
252
|
+
@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))
|
254
253
|
end
|
255
254
|
|
256
|
-
it_should_behave_like(
|
255
|
+
it_should_behave_like('it can parse into a CAP 1.1 Info object')
|
257
256
|
end
|
258
257
|
|
259
|
-
context(
|
260
|
-
before(
|
261
|
-
@original_info = RCAP::CAP_1_1::Info.new(
|
258
|
+
context('from a hash') do
|
259
|
+
before(:each) do
|
260
|
+
@original_info = RCAP::CAP_1_1::Info.new(&@info_constructor)
|
262
261
|
|
263
|
-
@info = RCAP::CAP_1_1::Info.from_h(
|
262
|
+
@info = RCAP::CAP_1_1::Info.from_h(@original_info.to_h)
|
264
263
|
end
|
265
264
|
|
266
|
-
it_should_behave_like(
|
265
|
+
it_should_behave_like('it can parse into a CAP 1.1 Info object')
|
267
266
|
end
|
268
267
|
end
|
269
268
|
|
270
|
-
context(
|
271
|
-
before(
|
269
|
+
context('is not valid if it') do
|
270
|
+
before(:each) do
|
272
271
|
@info = RCAP::CAP_1_1::Info.new do |info|
|
273
272
|
info.event = 'Info Event'
|
274
273
|
info.categories << RCAP::CAP_1_1::Info::CATEGORY_GEO
|
@@ -278,203 +277,202 @@ describe( RCAP::CAP_1_1::Info ) do
|
|
278
277
|
end
|
279
278
|
@info.valid?
|
280
279
|
puts @info.errors.full_messages
|
281
|
-
@info.should(
|
280
|
+
@info.should(be_valid)
|
282
281
|
end
|
283
282
|
|
284
|
-
it(
|
283
|
+
it('does not have an event') do
|
285
284
|
@info.event = nil
|
286
|
-
@info.should_not(
|
285
|
+
@info.should_not(be_valid)
|
287
286
|
end
|
288
287
|
|
289
|
-
it(
|
288
|
+
it('does not have categories') do
|
290
289
|
@info.categories.clear
|
291
|
-
@info.should_not(
|
290
|
+
@info.should_not(be_valid)
|
292
291
|
end
|
293
292
|
|
294
|
-
it(
|
293
|
+
it('does not have an urgency') do
|
295
294
|
@info.urgency = nil
|
296
|
-
@info.should_not(
|
295
|
+
@info.should_not(be_valid)
|
297
296
|
end
|
298
297
|
|
299
|
-
it(
|
298
|
+
it('does not have an severity') do
|
300
299
|
@info.severity = nil
|
301
|
-
@info.should_not(
|
300
|
+
@info.should_not(be_valid)
|
302
301
|
end
|
303
302
|
|
304
|
-
it(
|
303
|
+
it('does not have an certainty') do
|
305
304
|
@info.certainty = nil
|
306
|
-
@info.should_not(
|
305
|
+
@info.should_not(be_valid)
|
307
306
|
end
|
308
307
|
end
|
309
308
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
@info = RCAP::CAP_1_1::Info.new( &@info_constructor )
|
309
|
+
describe('when exported') do
|
310
|
+
context('to hash') do
|
311
|
+
before(:each) do
|
312
|
+
@info = RCAP::CAP_1_1::Info.new(&@info_constructor)
|
315
313
|
|
316
314
|
@info_hash = @info.to_h
|
317
315
|
end
|
318
316
|
|
319
|
-
it(
|
320
|
-
@info_hash[ RCAP::CAP_1_1::Info::LANGUAGE_KEY
|
317
|
+
it('should export the language correctly') do
|
318
|
+
@info_hash[ RCAP::CAP_1_1::Info::LANGUAGE_KEY].should == @info.language
|
321
319
|
end
|
322
320
|
|
323
|
-
it(
|
324
|
-
@info_hash[ RCAP::CAP_1_1::Info::CATEGORIES_KEY
|
321
|
+
it('should export the categories') do
|
322
|
+
@info_hash[ RCAP::CAP_1_1::Info::CATEGORIES_KEY].should == @info.categories
|
325
323
|
end
|
326
324
|
|
327
|
-
it(
|
328
|
-
@info_hash[ RCAP::CAP_1_1::Info::EVENT_KEY
|
325
|
+
it('should export the event') do
|
326
|
+
@info_hash[ RCAP::CAP_1_1::Info::EVENT_KEY].should == @info.event
|
329
327
|
end
|
330
328
|
|
331
|
-
it(
|
332
|
-
@info_hash[ RCAP::CAP_1_1::Info::RESPONSE_TYPES_KEY
|
329
|
+
it('should export the response types') do
|
330
|
+
@info_hash[ RCAP::CAP_1_1::Info::RESPONSE_TYPES_KEY].should == @info.response_types
|
333
331
|
end
|
334
332
|
|
335
|
-
it(
|
336
|
-
@info_hash[ RCAP::CAP_1_1::Info:: URGENCY_KEY
|
333
|
+
it('should export the urgency') do
|
334
|
+
@info_hash[ RCAP::CAP_1_1::Info:: URGENCY_KEY].should == @info.urgency
|
337
335
|
end
|
338
336
|
|
339
|
-
it(
|
340
|
-
@info_hash[ RCAP::CAP_1_1::Info:: SEVERITY_KEY
|
337
|
+
it('should export the severity') do
|
338
|
+
@info_hash[ RCAP::CAP_1_1::Info:: SEVERITY_KEY].should == @info.severity
|
341
339
|
end
|
342
340
|
|
343
|
-
it(
|
344
|
-
@info_hash[ RCAP::CAP_1_1::Info:: CERTAINTY_KEY
|
341
|
+
it('should export the certainty') do
|
342
|
+
@info_hash[ RCAP::CAP_1_1::Info:: CERTAINTY_KEY].should == @info.certainty
|
345
343
|
end
|
346
344
|
|
347
|
-
it(
|
348
|
-
@info_hash[ RCAP::CAP_1_1::Info:: AUDIENCE_KEY
|
345
|
+
it('should export the audience') do
|
346
|
+
@info_hash[ RCAP::CAP_1_1::Info:: AUDIENCE_KEY].should == @info.audience
|
349
347
|
end
|
350
348
|
|
351
|
-
it(
|
352
|
-
@info_hash[ RCAP::CAP_1_1::Info::EFFECTIVE_KEY
|
349
|
+
it('should export the effective date') do
|
350
|
+
@info_hash[ RCAP::CAP_1_1::Info::EFFECTIVE_KEY].should == @info.effective.to_s_for_cap
|
353
351
|
end
|
354
352
|
|
355
|
-
it(
|
356
|
-
@info_hash[ RCAP::CAP_1_1::Info::ONSET_KEY
|
353
|
+
it('should export the onset date') do
|
354
|
+
@info_hash[ RCAP::CAP_1_1::Info::ONSET_KEY].should == @info.onset.to_s_for_cap
|
357
355
|
end
|
358
356
|
|
359
|
-
it(
|
360
|
-
@info_hash[ RCAP::CAP_1_1::Info::EXPIRES_KEY
|
357
|
+
it('should export the expires date') do
|
358
|
+
@info_hash[ RCAP::CAP_1_1::Info::EXPIRES_KEY].should == @info.expires.to_s_for_cap
|
361
359
|
end
|
362
360
|
|
363
|
-
|
364
|
-
|
365
|
-
|
361
|
+
it('should export the sender name') do
|
362
|
+
@info_hash[ RCAP::CAP_1_1::Info::SENDER_NAME_KEY].should == @info.sender_name
|
363
|
+
end
|
366
364
|
|
367
|
-
|
368
|
-
|
369
|
-
|
365
|
+
it('should export the headline') do
|
366
|
+
@info_hash[ RCAP::CAP_1_1::Info::HEADLINE_KEY].should == @info.headline
|
367
|
+
end
|
370
368
|
|
371
|
-
|
372
|
-
|
373
|
-
|
369
|
+
it('should export the description') do
|
370
|
+
@info_hash[ RCAP::CAP_1_1::Info::DESCRIPTION_KEY].should == @info.description
|
371
|
+
end
|
374
372
|
|
375
|
-
|
376
|
-
|
377
|
-
|
373
|
+
it('should export the instruction') do
|
374
|
+
@info_hash[ RCAP::CAP_1_1::Info::INSTRUCTION_KEY].should == @info.instruction
|
375
|
+
end
|
378
376
|
|
379
|
-
|
380
|
-
|
381
|
-
|
377
|
+
it('should export the web address ') do
|
378
|
+
@info_hash[ RCAP::CAP_1_1::Info::WEB_KEY].should == @info.web
|
379
|
+
end
|
382
380
|
|
383
|
-
|
384
|
-
|
385
|
-
|
381
|
+
it('should export the contact') do
|
382
|
+
@info_hash[ RCAP::CAP_1_1::Info::CONTACT_KEY].should == @info.contact
|
383
|
+
end
|
386
384
|
|
387
|
-
|
388
|
-
|
389
|
-
|
385
|
+
it('should export the event codes') do
|
386
|
+
@info_hash[ RCAP::CAP_1_1::Info::EVENT_CODES_KEY].should == @info.event_codes.map { |event_code| event_code.to_h }
|
387
|
+
end
|
390
388
|
|
391
|
-
|
392
|
-
|
393
|
-
|
389
|
+
it('should export the parameters ') do
|
390
|
+
@info_hash[ RCAP::CAP_1_1::Info::PARAMETERS_KEY].should == @info.parameters.map { |parameter| parameter.to_h }
|
391
|
+
end
|
394
392
|
|
395
|
-
|
396
|
-
|
397
|
-
|
393
|
+
it('should export the resources ') do
|
394
|
+
@info_hash[ RCAP::CAP_1_1::Info::RESOURCES_KEY].should == @info.resources.map { |resource| resource.to_h }
|
395
|
+
end
|
398
396
|
|
399
|
-
|
400
|
-
|
401
|
-
|
397
|
+
it('should export the areas') do
|
398
|
+
@info_hash[ RCAP::CAP_1_1::Info::AREAS_KEY].should == @info.areas.map { |area| area.to_h }
|
399
|
+
end
|
402
400
|
end
|
403
401
|
end
|
404
402
|
|
405
|
-
describe(
|
406
|
-
before(
|
403
|
+
describe('instance methods') do
|
404
|
+
before(:each) do
|
407
405
|
@info = RCAP::CAP_1_1::Info.new
|
408
406
|
end
|
409
407
|
|
410
|
-
describe(
|
411
|
-
before(
|
408
|
+
describe('#add_event_code') do
|
409
|
+
before(:each) do
|
412
410
|
@event_code = @info.add_event_code do |event_code|
|
413
411
|
event_code.name = 'Event Code'
|
414
412
|
event_code.value = '1234'
|
415
413
|
end
|
416
414
|
end
|
417
415
|
|
418
|
-
it(
|
416
|
+
it('should return a 1.1 EventCode') do
|
419
417
|
@event_code.class.should == RCAP::CAP_1_1::EventCode
|
420
418
|
@event_code.name.should == 'Event Code'
|
421
419
|
@event_code.value.should == '1234'
|
422
420
|
end
|
423
421
|
|
424
|
-
it(
|
422
|
+
it('should add an EventCode to the event_codes attribute') do
|
425
423
|
@info.event_codes.size.should == 1
|
426
424
|
end
|
427
425
|
end
|
428
426
|
|
429
|
-
describe(
|
430
|
-
before(
|
427
|
+
describe('#add_parameter') do
|
428
|
+
before(:each) do
|
431
429
|
@parameter = @info.add_parameter do |parameter|
|
432
430
|
parameter.name = 'Parameter'
|
433
431
|
parameter.value = '1234'
|
434
432
|
end
|
435
433
|
end
|
436
434
|
|
437
|
-
it(
|
435
|
+
it('should return a 1.1 Parameter') do
|
438
436
|
@parameter.class.should == RCAP::CAP_1_1::Parameter
|
439
437
|
@parameter.name.should == 'Parameter'
|
440
438
|
@parameter.value.should == '1234'
|
441
439
|
end
|
442
440
|
|
443
|
-
it(
|
441
|
+
it('should add a Parameter to the parameters attribute') do
|
444
442
|
@info.parameters.size.should == 1
|
445
443
|
end
|
446
444
|
end
|
447
445
|
|
448
|
-
describe(
|
449
|
-
before(
|
446
|
+
describe('#add_resource') do
|
447
|
+
before(:each) do
|
450
448
|
@resource = @info.add_resource do |resource|
|
451
449
|
resource.resource_desc = 'Resource'
|
452
450
|
end
|
453
451
|
end
|
454
452
|
|
455
|
-
it(
|
453
|
+
it('should return a 1.1 Resource') do
|
456
454
|
@resource.class.should == RCAP::CAP_1_1::Resource
|
457
455
|
@resource.resource_desc.should == 'Resource'
|
458
456
|
end
|
459
457
|
|
460
|
-
it(
|
458
|
+
it('should add a Resource to the resources attribute') do
|
461
459
|
@info.resources.size.should == 1
|
462
460
|
end
|
463
461
|
end
|
464
462
|
|
465
|
-
describe(
|
466
|
-
before(
|
463
|
+
describe('#add_area') do
|
464
|
+
before(:each) do
|
467
465
|
@area = @info.add_area do |area|
|
468
466
|
area.area_desc = 'Area'
|
469
467
|
end
|
470
468
|
end
|
471
469
|
|
472
|
-
it(
|
470
|
+
it('should return a 1.1 area') do
|
473
471
|
@area.class.should == RCAP::CAP_1_1::Area
|
474
472
|
@area.area_desc.should == 'Area'
|
475
473
|
end
|
476
474
|
|
477
|
-
it(
|
475
|
+
it('should add a Area to the areas attribute') do
|
478
476
|
@info.areas.size.should == 1
|
479
477
|
end
|
480
478
|
end
|