rcap 0.3 → 0.4
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.rdoc +6 -0
- data/README.rdoc +44 -10
- data/lib/rcap.rb +3 -1
- data/lib/rcap/alert.rb +165 -103
- data/lib/rcap/area.rb +28 -2
- data/lib/rcap/circle.rb +27 -19
- data/lib/rcap/info.rb +73 -3
- data/lib/rcap/parameter.rb +10 -0
- data/lib/rcap/point.rb +13 -0
- data/lib/rcap/polygon.rb +10 -0
- data/lib/rcap/resource.rb +31 -4
- data/lib/rcap/utilities.rb +46 -26
- data/lib/rcap/validations.rb +17 -17
- data/spec/alert_spec.rb +52 -13
- data/spec/area_spec.rb +79 -20
- data/spec/circle_spec.rb +39 -10
- data/spec/geocode_spec.rb +18 -6
- data/spec/info_spec.rb +172 -21
- data/spec/point_spec.rb +13 -1
- data/spec/polygon_spec.rb +24 -1
- data/spec/resource_spec.rb +88 -6
- data/spec/spec_helper.rb +2 -1
- data/spec/utilities_spec.rb +1 -1
- data/spec/validations_spec.rb +1 -1
- metadata +36 -12
data/spec/alert_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe( RCAP::Alert ) do
|
4
4
|
context( 'on initialisation' ) do
|
@@ -21,19 +21,19 @@ describe( RCAP::Alert ) do
|
|
21
21
|
it( 'should not have any infos' ){ @alert.infos.should( be_empty )}
|
22
22
|
|
23
23
|
shared_examples_for( "a successfully parsed alert" ) do
|
24
|
-
it( 'should parse identifier correctly' ){ @alert.identifier.should
|
25
|
-
it( 'should parse sender correctly' ){ @alert.sender.should
|
26
|
-
it( 'should parse sent correctly' ){ @alert.sent.should( be_close( @original_alert.sent, Rational( 1, 86400 )))}
|
27
|
-
it( 'should parse status correctly' ){ @alert.status.should
|
28
|
-
it( 'should parse msg_type correctly' ){ @alert.msg_type.should
|
29
|
-
it( 'should parse source correctly' ){ @alert.source.should
|
30
|
-
it( 'should parse scope correctly' ){ @alert.scope.should
|
24
|
+
it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
|
25
|
+
it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
|
26
|
+
it( 'should parse sent correctly' ) { @alert.sent.should( be_close( @original_alert.sent, Rational( 1, 86400 )))}
|
27
|
+
it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
|
28
|
+
it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
|
29
|
+
it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
|
30
|
+
it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
|
31
31
|
it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
|
32
|
-
it( 'should parse addresses correctly' ){ @alert.addresses.should
|
33
|
-
it( 'should parse code correctly' ){ @alert.code.should
|
34
|
-
it( 'should parse note correctly' ){ @alert.note.should
|
35
|
-
it( 'should parse references correctly' ){ @alert.references.should
|
36
|
-
it( 'should parse incidents correctly' ){ @alert.incidents.should
|
32
|
+
it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
|
33
|
+
it( 'should parse code correctly' ) { @alert.code.should == @original_alert.code }
|
34
|
+
it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
|
35
|
+
it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
|
36
|
+
it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
|
37
37
|
it( 'should parse infos correctly' ) do
|
38
38
|
@alert.infos.size.should == @original_alert.infos.size
|
39
39
|
@alert.infos.each{ |info| info.class.should == RCAP::Info }
|
@@ -79,8 +79,47 @@ describe( RCAP::Alert ) do
|
|
79
79
|
@yaml_string = @original_alert.to_yaml
|
80
80
|
@alert = RCAP::Alert.from_yaml( @yaml_string )
|
81
81
|
end
|
82
|
+
|
82
83
|
it_should_behave_like( "a successfully parsed alert" )
|
83
84
|
end
|
85
|
+
|
86
|
+
context( 'from a hash' ) do
|
87
|
+
before( :each ) do
|
88
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
89
|
+
:status => RCAP::Alert::STATUS_TEST,
|
90
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
91
|
+
:source => 'Source',
|
92
|
+
:restriction => 'No Restriction',
|
93
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
94
|
+
:code => 'Code',
|
95
|
+
:note => 'Note',
|
96
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
97
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
98
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
99
|
+
@alert = RCAP::Alert.from_h( @original_alert.to_h )
|
100
|
+
end
|
101
|
+
|
102
|
+
it_should_behave_like( "a successfully parsed alert" )
|
103
|
+
end
|
104
|
+
|
105
|
+
context( 'from JSON' ) do
|
106
|
+
before( :each ) do
|
107
|
+
@original_alert = RCAP::Alert.new( :sender => 'Sender',
|
108
|
+
:status => RCAP::Alert::STATUS_TEST,
|
109
|
+
:scope => RCAP::Alert::SCOPE_PUBLIC,
|
110
|
+
:source => 'Source',
|
111
|
+
:restriction => 'No Restriction',
|
112
|
+
:addresses => [ 'Address 1', 'Address 2'],
|
113
|
+
:code => 'Code',
|
114
|
+
:note => 'Note',
|
115
|
+
:references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
|
116
|
+
:incidents => [ 'Incident1', 'Incident2' ],
|
117
|
+
:infos => [ RCAP::Info.new, RCAP::Info.new ])
|
118
|
+
@alert = RCAP::Alert.from_json( @original_alert.to_json )
|
119
|
+
end
|
120
|
+
|
121
|
+
it_should_behave_like( "a successfully parsed alert" )
|
122
|
+
end
|
84
123
|
end
|
85
124
|
|
86
125
|
describe( 'is not valid if it' ) do
|
data/spec/area_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe( RCAP::Area ) do
|
4
4
|
context( 'on initialisation' ) do
|
@@ -16,23 +16,7 @@ describe( RCAP::Area ) do
|
|
16
16
|
it( 'should have an empty circles' ){ @area.circles.should( be_empty )}
|
17
17
|
it( 'should have an empty geocodes' ){ @area.geocodes.should( be_empty )}
|
18
18
|
|
19
|
-
|
20
|
-
before( :each ) do
|
21
|
-
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
22
|
-
:altitude => 100,
|
23
|
-
:ceiling => 200,
|
24
|
-
:circles => RCAP::Circle.new( :point => RCAP::Point.new( :lattitude => 0, :longitude => 0 ), :radius => 100 ),
|
25
|
-
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
26
|
-
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
27
|
-
|
28
|
-
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => @original_area ))
|
29
|
-
@xml_string = @alert.to_xml
|
30
|
-
@xml_document = REXML::Document.new( @xml_string )
|
31
|
-
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
32
|
-
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
33
|
-
@area = RCAP::Area.from_xml_element( @area_xml_element )
|
34
|
-
end
|
35
|
-
|
19
|
+
shared_examples_for( "it can parse into an Area object" ) do
|
36
20
|
it( 'should parse the area_desc correctly' ) do
|
37
21
|
@area.area_desc.should == @original_area.area_desc
|
38
22
|
end
|
@@ -56,9 +40,84 @@ describe( RCAP::Area ) do
|
|
56
40
|
it( 'should parse the polygons correctly' ) do
|
57
41
|
@area.polygons.should == @original_area.polygons
|
58
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context( 'from XML' ) do
|
46
|
+
before( :each ) do
|
47
|
+
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
48
|
+
:altitude => 100,
|
49
|
+
:ceiling => 200,
|
50
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
51
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
52
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
53
|
+
|
54
|
+
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => @original_area ))
|
55
|
+
@xml_string = @alert.to_xml
|
56
|
+
@xml_document = REXML::Document.new( @xml_string )
|
57
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
58
|
+
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
59
|
+
@area = RCAP::Area.from_xml_element( @area_xml_element )
|
60
|
+
end
|
61
|
+
|
62
|
+
it_should_behave_like( "it can parse into an Area object" )
|
59
63
|
end
|
64
|
+
|
65
|
+
context( 'from a hash' ) do
|
66
|
+
before( :each ) do
|
67
|
+
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
68
|
+
:altitude => 100,
|
69
|
+
:ceiling => 200,
|
70
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
71
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
72
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
73
|
+
|
74
|
+
@area = RCAP::Area.from_h( @original_area.to_h )
|
75
|
+
end
|
76
|
+
|
77
|
+
it_should_behave_like( "it can parse into an Area object" )
|
78
|
+
end
|
60
79
|
end
|
61
80
|
|
81
|
+
context( 'when exported' ) do
|
82
|
+
before( :each ) do
|
83
|
+
@area = RCAP::Area.new( :area_desc => 'Area Description',
|
84
|
+
:altitude => 100,
|
85
|
+
:ceiling => 200,
|
86
|
+
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
87
|
+
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
88
|
+
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
89
|
+
end
|
90
|
+
context( 'to a hash' ) do
|
91
|
+
before( :each ) do
|
92
|
+
@area_hash = @area.to_h
|
93
|
+
end
|
94
|
+
|
95
|
+
it( 'should export the area description correctly' ) do
|
96
|
+
@area_hash[ RCAP::Area::AREA_DESC_KEY ].should == @area.area_desc
|
97
|
+
end
|
98
|
+
|
99
|
+
it( 'should export the altitude correctly' ) do
|
100
|
+
@area_hash[ RCAP::Area::ALTITUDE_KEY ].should == @area.altitude
|
101
|
+
end
|
102
|
+
|
103
|
+
it( 'should set the ceiling correctly' ) do
|
104
|
+
@area_hash[ RCAP::Area::CEILING_KEY ].should == @area.ceiling
|
105
|
+
end
|
106
|
+
|
107
|
+
it( 'should export the circles correctly' ) do
|
108
|
+
@area_hash[ RCAP::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
|
109
|
+
end
|
110
|
+
|
111
|
+
it( 'should export the geocodes correctly' ) do
|
112
|
+
@area_hash[ RCAP::Area::GEOCODES_KEY ].should == @area.geocodes.map{ |geocode| geocode.to_h }
|
113
|
+
end
|
114
|
+
|
115
|
+
it( 'should export the polygons correctly' ) do
|
116
|
+
@area_hash[ RCAP::Area::POLYGONS_KEY ].should == @area.polygons.map{ |polygon| polygon.to_h }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
62
121
|
context( 'is not valid if' ) do
|
63
122
|
before( :each ) do
|
64
123
|
@area = RCAP::Area.new( :area_desc => "Cape Town Metropole" )
|
@@ -78,12 +137,12 @@ describe( RCAP::Area ) do
|
|
78
137
|
|
79
138
|
context( 'it contains circles and it' ) do
|
80
139
|
before( :each ) do
|
81
|
-
@area.circles << RCAP::Circle.new( :
|
140
|
+
@area.circles << RCAP::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
|
82
141
|
@area.should( be_valid )
|
83
142
|
end
|
84
143
|
|
85
144
|
it( 'has an invalid circle' ) do
|
86
|
-
@area.circles.first.
|
145
|
+
@area.circles.first.lattitude = nil
|
87
146
|
@area.should_not( be_valid )
|
88
147
|
end
|
89
148
|
end
|
data/spec/circle_spec.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe( RCAP::Circle ) do
|
4
4
|
describe( 'should not be valid if' ) do
|
5
5
|
before( :each ) do
|
6
|
-
@circle = RCAP::Circle.new( :
|
6
|
+
@circle = RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
|
7
7
|
@circle.should( be_valid )
|
8
8
|
end
|
9
9
|
|
10
|
-
it( 'does not have a
|
11
|
-
@circle.
|
10
|
+
it( 'does not have a lattitude defined' ) do
|
11
|
+
@circle.lattitude = nil
|
12
12
|
@circle.should_not( be_valid )
|
13
13
|
end
|
14
14
|
|
15
|
-
it( 'does not have a
|
16
|
-
@circle.
|
15
|
+
it( 'does not have a longitude defined' ) do
|
16
|
+
@circle.longitude = nil
|
17
17
|
@circle.should_not( be_valid )
|
18
18
|
end
|
19
|
+
|
19
20
|
it( 'does not have a radius defined' ) do
|
20
21
|
@circle.radius = nil
|
21
22
|
@circle.should_not( be_valid )
|
@@ -36,7 +37,7 @@ describe( RCAP::Circle ) do
|
|
36
37
|
context( 'from XML' ) do
|
37
38
|
before( :each ) do
|
38
39
|
@original_circle = RCAP::Circle.new( :radius => 10.5,
|
39
|
-
|
40
|
+
:lattitude => 30, :longitude => 60 )
|
40
41
|
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :circles => @original_circle )))
|
41
42
|
@xml_string = @alert.to_xml
|
42
43
|
@xml_document = REXML::Document.new( @xml_string )
|
@@ -50,10 +51,38 @@ describe( RCAP::Circle ) do
|
|
50
51
|
@circle.radius.should == @original_circle.radius
|
51
52
|
end
|
52
53
|
|
53
|
-
it( 'should parse the
|
54
|
-
@circle.
|
55
|
-
@circle.
|
54
|
+
it( 'should parse the lattitude and longitude correctly' ) do
|
55
|
+
@circle.lattitude.should == @original_circle.lattitude
|
56
|
+
@circle.longitude.should == @original_circle.longitude
|
56
57
|
end
|
57
58
|
end
|
59
|
+
|
60
|
+
context( 'from a hash' ) do
|
61
|
+
before( :each ) do
|
62
|
+
@original_circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
|
63
|
+
@circle = RCAP::Circle.from_h( @original_circle.to_h )
|
64
|
+
end
|
65
|
+
|
66
|
+
it( 'should set the radius correctly' ) do
|
67
|
+
@circle.radius.should == @original_circle.radius
|
68
|
+
end
|
69
|
+
|
70
|
+
it( 'should parse the lattitude and longitude correctly' ) do
|
71
|
+
@circle.lattitude.should == @original_circle.lattitude
|
72
|
+
@circle.longitude.should == @original_circle.longitude
|
73
|
+
end
|
74
|
+
end
|
58
75
|
end
|
76
|
+
|
77
|
+
context( 'when exported' ) do
|
78
|
+
before( :each ) do
|
79
|
+
@circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
|
80
|
+
end
|
81
|
+
|
82
|
+
context( 'to hash' ) do
|
83
|
+
it( 'should be correct' ) do
|
84
|
+
@circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
59
88
|
end
|
data/spec/geocode_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe( RCAP::Geocode ) do
|
4
4
|
context( 'when initialised' ) do
|
@@ -7,11 +7,11 @@ describe( RCAP::Geocode ) do
|
|
7
7
|
@original_geocode = RCAP::Geocode.new( :name => 'name', :value => 'value' )
|
8
8
|
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :geocodes => @original_geocode )))
|
9
9
|
@xml_string = @alert.to_xml
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
12
|
+
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
13
|
+
@geocode_xml_element = RCAP.xpath_first( @area_xml_element, RCAP::Geocode::XPATH )
|
14
|
+
@geocode = RCAP::Geocode.from_xml_element( @geocode_xml_element )
|
15
15
|
end
|
16
16
|
|
17
17
|
it( 'should parse the name correctly' ) do
|
@@ -23,4 +23,16 @@ describe( RCAP::Geocode ) do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
context( 'when exported' ) do
|
28
|
+
before( :each ) do
|
29
|
+
@geocode = RCAP::Geocode.new( :name => 'name', :value => 'value' )
|
30
|
+
end
|
31
|
+
|
32
|
+
context( 'to a hash' ) do
|
33
|
+
it( 'should export correctly' ) do
|
34
|
+
@geocode.to_h.should == { 'name' => 'value' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
26
38
|
end
|
data/spec/info_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe( RCAP::Info ) do
|
4
4
|
context( 'on initialisation' ) do
|
@@ -26,6 +26,29 @@ describe( RCAP::Info ) do
|
|
26
26
|
it( 'should have no contact' ) { @info.contact.should( be_nil )}
|
27
27
|
it( 'should have no parameters' ) { @info.parameters.should( be_empty )}
|
28
28
|
|
29
|
+
shared_examples_for( 'it can parse into an Info object' ) do
|
30
|
+
it( 'should parse categories correctly' ){ @info .categories.should == @original_info.categories }
|
31
|
+
it( 'should parse event correctly' ){ @info .event.should == @original_info.event }
|
32
|
+
it( 'should parse response_types correctly' ){ @info .response_types.should == @original_info.response_types }
|
33
|
+
it( 'should parse urgency correctly' ){ @info .urgency.should == @original_info.urgency }
|
34
|
+
it( 'should parse severity correctly' ){ @info .severity.should == @original_info.severity }
|
35
|
+
it( 'should parse certainty correctly' ){ @info .certainty.should == @original_info.certainty }
|
36
|
+
it( 'should parse audience correctly' ){ @info .audience.should == @original_info.audience }
|
37
|
+
it( 'should parse effective correctly' ){ @info .effective.should( be_close( @original_info.effective, Rational( 1, 86400 )))}
|
38
|
+
it( 'should parse onset correctly' ){ @info .onset.should( be_close( @original_info.onset, Rational( 1, 86400 )))}
|
39
|
+
it( 'should parse expires correctly' ){ @info .expires.should( be_close( @original_info.expires, Rational( 1, 86400 )))}
|
40
|
+
it( 'should parse sender_name correctly' ){ @info .sender_name.should == @original_info.sender_name }
|
41
|
+
it( 'should parse headline correctly' ){ @info .headline.should == @original_info.headline }
|
42
|
+
it( 'should parse description correctly' ){ @info .description.should == @original_info.description }
|
43
|
+
it( 'should parse instruction correctly' ){ @info .instruction.should == @original_info.instruction }
|
44
|
+
it( 'should parse web correctly' ){ @info .web.should == @original_info.web }
|
45
|
+
it( 'should parse contact correctly' ){ @info .contact.should == @original_info.contact }
|
46
|
+
it( 'should parse event_codes correctly' ){ @info .event_codes.should == @original_info.event_codes }
|
47
|
+
it( 'should parse parameters correctly' ){ @info .parameters.should == @original_info.parameters }
|
48
|
+
it( 'should parse resources correctly' ){ @info .resources.should == @original_info.resources }
|
49
|
+
it( 'should parse areas correctly' ){ @info .areas.should == @original_info.areas }
|
50
|
+
end
|
51
|
+
|
29
52
|
context( 'from XML' ) do
|
30
53
|
before( :each ) do
|
31
54
|
@original_info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
@@ -56,26 +79,38 @@ describe( RCAP::Info ) do
|
|
56
79
|
@xml_document = REXML::Document.new( @xml_string )
|
57
80
|
@info = RCAP::Info.from_xml_element( RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH ))
|
58
81
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
|
83
|
+
it_should_behave_like( "it can parse into an Info object" )
|
84
|
+
end
|
85
|
+
|
86
|
+
context( 'from a hash' ) do
|
87
|
+
before( :each ) do
|
88
|
+
@original_info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
89
|
+
:event => 'Event Description',
|
90
|
+
:response_types => [ RCAP::Info::RESPONSE_TYPE_MONITOR, RCAP::Info::RESPONSE_TYPE_ASSESS ],
|
91
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
92
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
93
|
+
:certainty => RCAP::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::EventCode.new( :name => 'name1', :value => 'value1' ),
|
105
|
+
RCAP::EventCode.new( :name => 'name2', :value => 'value2' )],
|
106
|
+
:parameters => [ RCAP::Parameter.new( :name => 'name1', :value => 'value1' ),
|
107
|
+
RCAP::Parameter.new( :name => 'name2', :value => 'value2' )],
|
108
|
+
:areas => [ RCAP::Area.new( :area_desc => 'Area1' ),
|
109
|
+
RCAP::Area.new( :area_desc => 'Area2' )]
|
110
|
+
)
|
111
|
+
@info = RCAP::Info.from_h( @original_info.to_h )
|
112
|
+
end
|
113
|
+
it_should_behave_like( "it can parse into an Info object" )
|
79
114
|
end
|
80
115
|
end
|
81
116
|
|
@@ -116,4 +151,120 @@ describe( RCAP::Info ) do
|
|
116
151
|
@info.should_not( be_valid )
|
117
152
|
end
|
118
153
|
end
|
154
|
+
|
155
|
+
|
156
|
+
describe( 'when exported' ) do
|
157
|
+
context( 'to hash' ) do
|
158
|
+
before( :each ) do
|
159
|
+
@info = RCAP::Info.new( :categories => [ RCAP::Info::CATEGORY_GEO, RCAP::Info::CATEGORY_FIRE ],
|
160
|
+
:event => 'Event Description',
|
161
|
+
:response_types => [ RCAP::Info::RESPONSE_TYPE_MONITOR, RCAP::Info::RESPONSE_TYPE_ASSESS ],
|
162
|
+
:urgency => RCAP::Info::URGENCY_IMMEDIATE,
|
163
|
+
:severity => RCAP::Info::SEVERITY_EXTREME,
|
164
|
+
:certainty => RCAP::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::Resource.new( :resource_desc => 'Resource Description', :uri => 'http://tempuri.org/resource' )],
|
176
|
+
:event_codes => [ RCAP::EventCode.new( :name => 'name1', :value => 'value1' ),
|
177
|
+
RCAP::EventCode.new( :name => 'name2', :value => 'value2' )],
|
178
|
+
:parameters => [ RCAP::Parameter.new( :name => 'name1', :value => 'value1' ),
|
179
|
+
RCAP::Parameter.new( :name => 'name2', :value => 'value2' )],
|
180
|
+
:areas => [ RCAP::Area.new( :area_desc => 'Area1' ),
|
181
|
+
RCAP::Area.new( :area_desc => 'Area2' )])
|
182
|
+
@info_hash = @info.to_h
|
183
|
+
end
|
184
|
+
|
185
|
+
it( 'should export the language correctly' ) do
|
186
|
+
@info_hash[ RCAP::Info::LANGUAGE_KEY ].should == @info.language
|
187
|
+
end
|
188
|
+
|
189
|
+
it( 'should export the categories' ) do
|
190
|
+
@info_hash[ RCAP::Info::CATEGORIES_KEY ].should == @info.categories
|
191
|
+
end
|
192
|
+
|
193
|
+
it( 'should export the event' ) do
|
194
|
+
@info_hash[ RCAP::Info::EVENT_KEY ].should == @info.event
|
195
|
+
end
|
196
|
+
|
197
|
+
it( 'should export the response types' ) do
|
198
|
+
@info_hash[ RCAP::Info::RESPONSE_TYPES_KEY ].should == @info.response_types
|
199
|
+
end
|
200
|
+
|
201
|
+
it( 'should export the urgency' ) do
|
202
|
+
@info_hash[ RCAP::Info:: URGENCY_KEY ].should == @info.urgency
|
203
|
+
end
|
204
|
+
|
205
|
+
it( 'should export the severity' ) do
|
206
|
+
@info_hash[ RCAP::Info:: SEVERITY_KEY ].should == @info.severity
|
207
|
+
end
|
208
|
+
|
209
|
+
it( 'should export the certainty' ) do
|
210
|
+
@info_hash[ RCAP::Info:: CERTAINTY_KEY ].should == @info.certainty
|
211
|
+
end
|
212
|
+
|
213
|
+
it( 'should export the audience' ) do
|
214
|
+
@info_hash[ RCAP::Info:: AUDIENCE_KEY ].should == @info.audience
|
215
|
+
end
|
216
|
+
|
217
|
+
it( 'should export the effective date' ) do
|
218
|
+
@info_hash[ RCAP::Info::EFFECTIVE_KEY ].should == @info.effective.to_s_for_cap
|
219
|
+
end
|
220
|
+
|
221
|
+
it( 'should export the onset date' ) do
|
222
|
+
@info_hash[ RCAP::Info::ONSET_KEY ].should == @info.onset.to_s_for_cap
|
223
|
+
end
|
224
|
+
|
225
|
+
it( 'should export the expires date' ) do
|
226
|
+
@info_hash[ RCAP::Info::EXPIRES_KEY ].should == @info.expires.to_s_for_cap
|
227
|
+
end
|
228
|
+
|
229
|
+
it( 'should export the sender name' ) do
|
230
|
+
@info_hash[ RCAP::Info::SENDER_NAME_KEY ].should == @info.sender_name
|
231
|
+
end
|
232
|
+
|
233
|
+
it( 'should export the headline' ) do
|
234
|
+
@info_hash[ RCAP::Info::HEADLINE_KEY ].should == @info.headline
|
235
|
+
end
|
236
|
+
|
237
|
+
it( 'should export the description' ) do
|
238
|
+
@info_hash[ RCAP::Info::DESCRIPTION_KEY ].should == @info.description
|
239
|
+
end
|
240
|
+
|
241
|
+
it( 'should export the instruction' ) do
|
242
|
+
@info_hash[ RCAP::Info::INSTRUCTION_KEY ].should == @info.instruction
|
243
|
+
end
|
244
|
+
|
245
|
+
it( 'should export the web address ' ) do
|
246
|
+
@info_hash[ RCAP::Info::WEB_KEY ].should == @info.web
|
247
|
+
end
|
248
|
+
|
249
|
+
it( 'should export the contact' ) do
|
250
|
+
@info_hash[ RCAP::Info::CONTACT_KEY ].should == @info.contact
|
251
|
+
end
|
252
|
+
|
253
|
+
it( 'should export the event codes' ) do
|
254
|
+
@info_hash[ RCAP::Info::EVENT_CODES_KEY ].should == @info.event_codes.map{ |event_code| event_code.to_h }
|
255
|
+
end
|
256
|
+
|
257
|
+
it( 'should export the parameters ' ) do
|
258
|
+
@info_hash[ RCAP::Info::PARAMETERS_KEY ].should == @info.parameters.map{ |parameter| parameter.to_h }
|
259
|
+
end
|
260
|
+
|
261
|
+
it( 'should export the resources ' ) do
|
262
|
+
@info_hash[ RCAP::Info::RESOURCES_KEY ].should == @info.resources.map{ |resource| resource.to_h }
|
263
|
+
end
|
264
|
+
|
265
|
+
it( 'should export the areas' ) do
|
266
|
+
@info_hash[ RCAP::Info::AREAS_KEY ].should == @info.areas.map{ |area| area.to_h }
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
119
270
|
end
|