rcap 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/CHANGELOG.rdoc +4 -0
  2. data/lib/rcap.rb +10 -0
  3. data/lib/rcap/alert.rb +7 -1
  4. data/lib/rcap/cap_1_0/alert.rb +383 -0
  5. data/lib/rcap/cap_1_0/area.rb +178 -0
  6. data/lib/rcap/cap_1_0/circle.rb +81 -0
  7. data/lib/rcap/cap_1_0/event_code.rb +8 -0
  8. data/lib/rcap/cap_1_0/geocode.rb +8 -0
  9. data/lib/rcap/cap_1_0/info.rb +435 -0
  10. data/lib/rcap/cap_1_0/parameter.rb +71 -0
  11. data/lib/rcap/cap_1_0/point.rb +55 -0
  12. data/lib/rcap/cap_1_0/polygon.rb +89 -0
  13. data/lib/rcap/cap_1_0/resource.rb +132 -0
  14. data/lib/rcap/cap_1_1/event_code.rb +0 -14
  15. data/lib/rcap/cap_1_1/geocode.rb +0 -14
  16. data/lib/rcap/cap_1_1/parameter.rb +5 -5
  17. data/lib/rcap/cap_1_1/resource.rb +5 -5
  18. data/lib/rcap/cap_1_2/event_code.rb +0 -14
  19. data/lib/rcap/cap_1_2/geocode.rb +0 -14
  20. data/lib/rcap/cap_1_2/parameter.rb +2 -3
  21. data/lib/rcap/cap_1_2/resource.rb +5 -5
  22. data/lib/rcap/version.rb +1 -1
  23. data/rcap.gemspec +0 -1
  24. data/spec/alert_spec.rb +64 -0
  25. data/spec/cap_1_0/alert_spec.rb +222 -0
  26. data/spec/cap_1_0/area_spec.rb +247 -0
  27. data/spec/cap_1_0/circle_spec.rb +88 -0
  28. data/spec/cap_1_0/event_code_spec.rb +37 -0
  29. data/spec/cap_1_0/geocode_spec.rb +38 -0
  30. data/spec/cap_1_0/info_spec.rb +324 -0
  31. data/spec/cap_1_0/parameter_spec.rb +65 -0
  32. data/spec/cap_1_0/point_spec.rb +46 -0
  33. data/spec/cap_1_0/polygon_spec.rb +97 -0
  34. data/spec/cap_1_0/resource_spec.rb +140 -0
  35. data/spec/cap_1_1/event_code_spec.rb +38 -0
  36. data/spec/cap_1_1/parameter_spec.rb +37 -0
  37. data/spec/cap_1_2/event_code_spec.rb +38 -0
  38. data/spec/cap_1_2/parameter_spec.rb +37 -0
  39. metadata +49 -34
@@ -1,22 +1,8 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
3
  class Geocode < Parameter
4
-
5
4
  XML_ELEMENT_NAME = 'geocode' # :nodoc:
6
-
7
5
  XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
8
-
9
- def to_xml_element # :nodoc:
10
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
11
- xml_element.add_element( NAME_ELEMENT_NAME ).add_text( @name )
12
- xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( @value )
13
- xml_element
14
- end
15
-
16
- def self.from_xml_element( geocode_xml_element ) # :nodoc:
17
- self.new( :name => RCAP.xpath_text( geocode_xml_element, NAME_XPATH, Alert::XMLNS ),
18
- :value => RCAP.xpath_text( geocode_xml_element, VALUE_XPATH, Alert::XMLNS ))
19
- end
20
6
  end
21
7
  end
22
8
  end
@@ -24,7 +24,7 @@ module RCAP
24
24
  end
25
25
 
26
26
  def to_xml_element # :nodoc:
27
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
27
+ xml_element = REXML::Element.new( self.class::XML_ELEMENT_NAME )
28
28
  xml_element.add_element( NAME_ELEMENT_NAME ).add_text( self.name )
29
29
  xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( self.value )
30
30
  xml_element
@@ -55,8 +55,7 @@ module RCAP
55
55
  end
56
56
 
57
57
  def to_h # :nodoc:
58
- RCAP.attribute_values_to_hash(
59
- [ @name, @value ])
58
+ RCAP.attribute_values_to_hash( [ self.name, self.value ])
60
59
  end
61
60
 
62
61
  def self.from_h( hash ) # :nodoc:
@@ -136,11 +136,11 @@ module RCAP
136
136
  def self.from_h( resource_hash ) # :nodoc:
137
137
  self.new(
138
138
  :resource_desc => resource_hash[ RESOURCE_DESC_KEY ],
139
- :uri => resource_hash[ URI_KEY ],
140
- :mime_type => resource_hash[ MIME_TYPE_KEY ],
141
- :deref_uri => resource_hash[ DEREF_URI_KEY ],
142
- :size => resource_hash[ SIZE_KEY ],
143
- :digest => resource_hash[ DIGEST_KEY ])
139
+ :uri => resource_hash[ URI_KEY ],
140
+ :mime_type => resource_hash[ MIME_TYPE_KEY ],
141
+ :deref_uri => resource_hash[ DEREF_URI_KEY ],
142
+ :size => resource_hash[ SIZE_KEY ],
143
+ :digest => resource_hash[ DIGEST_KEY ])
144
144
  end
145
145
  end
146
146
  end
data/lib/rcap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RCAP
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
data/rcap.gemspec CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.has_rdoc = true
23
22
  s.extra_rdoc_files = ['README.rdoc','CHANGELOG.rdoc']
24
23
  s.add_dependency('assistance', '>= 0.1.5')
25
24
  s.add_dependency('json', '>= 1.5.1')
data/spec/alert_spec.rb CHANGED
@@ -1,6 +1,70 @@
1
1
  describe( RCAP::Alert ) do
2
2
  describe( 'initialising' ) do
3
3
 
4
+ context( 'a CAP 1.0 alert' ) do
5
+ before( :each ) do
6
+ @original_alert = RCAP::CAP_1_0::Alert.new( :sender => 'Sender',
7
+ :sent => DateTime.now,
8
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
9
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC,
10
+ :source => 'Source',
11
+ :restriction => 'No Restriction',
12
+ :addresses => [ 'Address 1', 'Address 2'],
13
+ :code => ['Code1', 'Code2'],
14
+ :note => 'Note',
15
+ :references => [ "1.0,1", "1.0,2" ],
16
+ :incidents => [ 'Incident1', 'Incident2' ],
17
+ :infos => [ RCAP::CAP_1_0::Info.new, RCAP::CAP_1_0::Info.new ])
18
+ end
19
+
20
+
21
+
22
+ shared_examples_for( 'it has parsed a CAP 1.0 alert correctly' ) do
23
+ it( 'should use the correct CAP Version' ){ @alert.class.should == RCAP::CAP_1_0::Alert }
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_within( 1 ).of( @original_alert.sent ))}
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
+ it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
32
+ it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
33
+ it( 'should parse code correctly' ) { @alert.codes.should == @original_alert.codes }
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
+ it( 'should parse infos correctly' ) do
38
+ @alert.infos.size.should == @original_alert.infos.size
39
+ @alert.infos.each{ |info| info.class.should == RCAP::CAP_1_0::Info }
40
+ end
41
+ end
42
+
43
+ context( 'from XML' ) do
44
+ before( :each ) do
45
+ @alert = RCAP::Alert.from_xml( @original_alert.to_xml )
46
+ end
47
+
48
+ it_should_behave_like( 'it has parsed a CAP 1.0 alert correctly' )
49
+ end
50
+
51
+ context( 'from YAML' ) do
52
+ before( :each ) do
53
+ @alert = RCAP::Alert.from_yaml( @original_alert.to_yaml )
54
+ end
55
+
56
+ it_should_behave_like( 'it has parsed a CAP 1.0 alert correctly' )
57
+ end
58
+
59
+ context( 'from JSON' ) do
60
+ before( :each ) do
61
+ @alert = RCAP::Alert.from_json( @original_alert.to_json )
62
+ end
63
+
64
+ it_should_behave_like( 'it has parsed a CAP 1.0 alert correctly' )
65
+ end
66
+ end
67
+
4
68
  context( 'a CAP 1.1 alert' ) do
5
69
  before( :each ) do
6
70
  @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+
3
+ describe( RCAP::CAP_1_0::Alert ) do
4
+ context( 'on initialisation' ) do
5
+ before( :each ) do
6
+ @alert = RCAP::CAP_1_0::Alert.new
7
+ end
8
+
9
+ it( 'should not have a identifier' ){ @alert.identifier.should( be_nil )}
10
+ it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
11
+ it( 'should not have a sent time' ){ @alert.sent.should( be_nil )}
12
+ it( 'should not have a status' ){ @alert.status.should( be_nil )}
13
+ it( 'should not have a scope' ){ @alert.scope.should( be_nil )}
14
+ it( 'should not have a source'){ @alert.source.should( be_nil )}
15
+ it( 'should not have a restriction'){ @alert.restriction.should( be_nil )}
16
+ it( 'should not have any addresses' ){ @alert.addresses.should( be_empty )}
17
+ it( 'should not have any codes' ){ @alert.codes.should( be_empty )}
18
+ it( 'should not have a note' ){ @alert.note.should( be_nil )}
19
+ it( 'should not have any references' ){ @alert.references.should( be_empty )}
20
+ it( 'should not have any incidents' ){ @alert.incidents.should( be_empty )}
21
+ it( 'should not have any infos' ){ @alert.infos.should( be_empty )}
22
+
23
+ shared_examples_for( "a successfully parsed CAP 1.0 alert" ) do
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_within( 1 ).of( @original_alert.sent ))}
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
+ it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
32
+ it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
33
+ it( 'should parse code correctly' ) { @alert.codes.should == @original_alert.codes }
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
+ it( 'should parse infos correctly' ) do
38
+ @alert.infos.size.should == @original_alert.infos.size
39
+ @alert.infos.each{ |info| info.class.should == RCAP::CAP_1_0::Info }
40
+ end
41
+ end
42
+
43
+ context( 'from XML' ) do
44
+ before( :each ) do
45
+ @original_alert = RCAP::CAP_1_0::Alert.new( :sender => 'Sender',
46
+ :sent => DateTime.now,
47
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
48
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC,
49
+ :source => 'Source',
50
+ :restriction => 'No Restriction',
51
+ :addresses => [ 'Address 1', 'Address 2'],
52
+ :codes => [ 'Code1', 'Code2' ],
53
+ :note => 'Note',
54
+ :references => [ RCAP::CAP_1_0::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_0::Alert.new( :sender => 'Sender2' ).to_reference ],
55
+ :incidents => [ 'Incident1', 'Incident2' ],
56
+ :infos => [ RCAP::CAP_1_0::Info.new, RCAP::CAP_1_0::Info.new ])
57
+ @xml_string = @original_alert.to_xml
58
+ @xml_document = REXML::Document.new( @xml_string )
59
+ @alert_element = @xml_document.root
60
+ @alert = RCAP::CAP_1_0::Alert.from_xml_element( @alert_element )
61
+ end
62
+
63
+ it_should_behave_like( "a successfully parsed CAP 1.0 alert" )
64
+
65
+ end
66
+
67
+ context( 'from YAML' ) do
68
+ before( :each ) do
69
+ @original_alert = RCAP::CAP_1_0::Alert.new( :sender => 'Sender',
70
+ :sent => DateTime.now,
71
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
72
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC,
73
+ :source => 'Source',
74
+ :restriction => 'No Restriction',
75
+ :addresses => [ 'Address 1', 'Address 2'],
76
+ :codes => [ 'Code1', 'Code2' ],
77
+ :note => 'Note',
78
+ :references => [ RCAP::CAP_1_0::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_0::Alert.new( :sender => 'Sender2' ).to_reference ],
79
+ :incidents => [ 'Incident1', 'Incident2' ],
80
+ :infos => [ RCAP::CAP_1_0::Info.new, RCAP::CAP_1_0::Info.new ])
81
+ @yaml_string = @original_alert.to_yaml
82
+ @alert = RCAP::CAP_1_0::Alert.from_yaml( @yaml_string )
83
+ end
84
+
85
+ it_should_behave_like( "a successfully parsed CAP 1.0 alert" )
86
+ end
87
+
88
+ context( 'from a hash' ) do
89
+ before( :each ) do
90
+ @original_alert = RCAP::CAP_1_0::Alert.new( :sender => 'Sender',
91
+ :sent => DateTime.now,
92
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
93
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC,
94
+ :source => 'Source',
95
+ :restriction => 'No Restriction',
96
+ :addresses => [ 'Address 1', 'Address 2'],
97
+ :codes => [ 'Code1', 'Code2' ],
98
+ :note => 'Note',
99
+ :references => [ RCAP::CAP_1_0::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_0::Alert.new( :sender => 'Sender2' ).to_reference ],
100
+ :incidents => [ 'Incident1', 'Incident2' ],
101
+ :infos => [ RCAP::CAP_1_0::Info.new, RCAP::CAP_1_0::Info.new ])
102
+ @alert = RCAP::CAP_1_0::Alert.from_h( @original_alert.to_h )
103
+ end
104
+
105
+ it_should_behave_like( "a successfully parsed CAP 1.0 alert" )
106
+ end
107
+
108
+ context( 'from JSON' ) do
109
+ before( :each ) do
110
+ @original_alert = RCAP::CAP_1_0::Alert.new( :sender => 'Sender',
111
+ :sent => DateTime.now,
112
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
113
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC,
114
+ :source => 'Source',
115
+ :restriction => 'No Restriction',
116
+ :addresses => [ 'Address 1', 'Address 2'],
117
+ :codes => [ 'Code1', 'Code2' ],
118
+ :note => 'Note',
119
+ :references => [ RCAP::CAP_1_0::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_0::Alert.new( :sender => 'Sender2' ).to_reference ],
120
+ :incidents => [ 'Incident1', 'Incident2' ],
121
+ :infos => [ RCAP::CAP_1_0::Info.new, RCAP::CAP_1_0::Info.new ])
122
+ @alert = RCAP::CAP_1_0::Alert.from_json( @original_alert.to_json )
123
+ end
124
+
125
+ it_should_behave_like( "a successfully parsed CAP 1.0 alert" )
126
+ end
127
+ end
128
+
129
+ describe( 'is not valid if it' ) do
130
+ before( :each ) do
131
+ @alert = RCAP::CAP_1_0::Alert.new( :identifier => 'Identifier',
132
+ :sender => "cap@tempuri.org",
133
+ :sent => DateTime.now,
134
+ :status => RCAP::CAP_1_0::Alert::STATUS_TEST,
135
+ :msg_type => RCAP::CAP_1_0::Alert::MSG_TYPE_ALERT,
136
+ :scope => RCAP::CAP_1_0::Alert::SCOPE_PUBLIC )
137
+ @alert.should( be_valid )
138
+ end
139
+
140
+ it( 'does not have a identifier' ) do
141
+ @alert.identifier = nil
142
+ @alert.should_not( be_valid )
143
+ end
144
+
145
+ it( 'does not have a sender' ) do
146
+ @alert.sender = nil
147
+ @alert.should_not( be_valid )
148
+ end
149
+
150
+ it( 'does not have a sent time (sent)' ) do
151
+ @alert.sent = nil
152
+ @alert.should_not( be_valid )
153
+ end
154
+
155
+ it( 'does not have a status' ) do
156
+ @alert.status = nil
157
+ @alert.should_not( be_valid )
158
+ end
159
+
160
+ it( 'does not have a message type (msg_type)' ) do
161
+ @alert.msg_type = nil
162
+ @alert.should_not( be_valid )
163
+ end
164
+
165
+ it( 'does not have a scope' ) do
166
+ @alert.scope = nil
167
+ @alert.should_not( be_valid )
168
+ end
169
+
170
+
171
+ it( 'does not have a valid status' ) do
172
+ @alert.status = 'incorrect value'
173
+ @alert.should_not( be_valid )
174
+ end
175
+
176
+ it( 'does not have a valid message type msg_type' ) do
177
+ @alert.msg_type = 'incorrect value'
178
+ @alert.should_not( be_valid )
179
+ end
180
+
181
+ it( 'does not have a valid scope' ) do
182
+ @alert.scope = 'incorrect value'
183
+ @alert.should_not( be_valid )
184
+ end
185
+
186
+
187
+ context( 'has an info element and it' ) do
188
+ it( 'is not valid' ) do
189
+ @info = RCAP::CAP_1_0::Info.new( :event => 'Info Event',
190
+ :categories => RCAP::CAP_1_0::Info::CATEGORY_GEO,
191
+ :urgency => RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE,
192
+ :severity => RCAP::CAP_1_0::Info::SEVERITY_EXTREME,
193
+ :certainty => RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY )
194
+ @info.event = nil
195
+ @alert.infos << @info
196
+ @info.should_not( be_valid )
197
+ @alert.should_not( be_valid )
198
+ end
199
+ end
200
+ end
201
+
202
+ describe( 'instance methods' ) do
203
+ before( :each ) do
204
+ @alert = RCAP::CAP_1_0::Alert.new
205
+ end
206
+
207
+ describe( '#add_info' ) do
208
+ before( :each ) do
209
+ @info = @alert.add_info( :urgency => 'urgent' )
210
+ @info.urgency.should == 'urgent'
211
+ end
212
+
213
+ it( 'should return a CAP 1.0 Info object' ) do
214
+ @info.class.should == RCAP::CAP_1_0::Info
215
+ end
216
+
217
+ it( 'should add an Info object to the infos array' ) do
218
+ @alert.infos.size.should == 1
219
+ end
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,247 @@
1
+ require 'spec_helper'
2
+
3
+ describe( RCAP::CAP_1_0::Area ) do
4
+ context( 'on initialisation' ) do
5
+ before( :each ) do
6
+ @area = RCAP::CAP_1_0::Area.new
7
+ end
8
+
9
+ # Atomic
10
+ it( 'should not have a area_desc' ){ @area.area_desc.should( be_nil )}
11
+ it( 'should not have a altitude' ){ @area.altitude.should( be_nil )}
12
+ it( 'should not have a ceiling' ){ @area.ceiling.should( be_nil )}
13
+
14
+ # Group
15
+ it( 'should have an empty polygons' ){ @area.polygons.should( be_empty )}
16
+ it( 'should have an empty circles' ){ @area.circles.should( be_empty )}
17
+ it( 'should have an empty geocodes' ){ @area.geocodes.should( be_empty )}
18
+
19
+ shared_examples_for( "it can parse into a CAP 1.0 Area object" ) do
20
+ it( 'should parse the area_desc correctly' ) do
21
+ @area.area_desc.should == @original_area.area_desc
22
+ end
23
+
24
+ it( 'should parse the altitude correctly' ) do
25
+ @area.altitude.should == @original_area.altitude
26
+ end
27
+
28
+ it( 'should parse the ceiling correctly' ) do
29
+ @area.ceiling.should == @original_area.ceiling
30
+ end
31
+
32
+ it( 'should parse the circles correctly' ) do
33
+ @area.circles.should == @original_area.circles
34
+ end
35
+
36
+ it( 'should parse the geocodes correctly' ) do
37
+ @area.geocodes.should == @original_area.geocodes
38
+ end
39
+
40
+ it( 'should parse the polygons correctly' ) do
41
+ @area.polygons.should == @original_area.polygons
42
+ end
43
+ end
44
+
45
+ context( 'from XML' ) do
46
+ before( :each ) do
47
+ @original_area = RCAP::CAP_1_0::Area.new( :area_desc => 'Area Description',
48
+ :altitude => 100,
49
+ :ceiling => 200,
50
+ :circles => RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
51
+ :geocodes => RCAP::CAP_1_0::Geocode.new( :name => 'name', :value => 'value' ),
52
+ :polygons => RCAP::CAP_1_0::Polygon.new( :points => RCAP::CAP_1_0::Point.new( :lattitude =>1, :longitude => 1 )))
53
+
54
+ @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::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::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
58
+ @area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
59
+ @area = RCAP::CAP_1_0::Area.from_xml_element( @area_xml_element )
60
+ end
61
+
62
+ it_should_behave_like( "it can parse into a CAP 1.0 Area object" )
63
+ end
64
+
65
+ context( 'from YAML Data' ) do
66
+ before( :each ) do
67
+ @original_area = RCAP::CAP_1_0::Area.new( :area_desc => 'Area Description',
68
+ :altitude => 100,
69
+ :ceiling => 200,
70
+ :circles => RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
71
+ :geocodes => RCAP::CAP_1_0::Geocode.new( :name => 'name', :value => 'value' ),
72
+ :polygons => RCAP::CAP_1_0::Polygon.new( :points => RCAP::CAP_1_0::Point.new( :lattitude =>1, :longitude => 1 )))
73
+
74
+ @area = RCAP::CAP_1_0::Area.from_yaml_data( YAML.load( @original_area.to_yaml ))
75
+ end
76
+
77
+ it_should_behave_like( "it can parse into a CAP 1.0 Area object" )
78
+ end
79
+
80
+ context( 'from a hash' ) do
81
+ before( :each ) do
82
+ @original_area = RCAP::CAP_1_0::Area.new( :area_desc => 'Area Description',
83
+ :altitude => 100,
84
+ :ceiling => 200,
85
+ :circles => RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
86
+ :geocodes => RCAP::CAP_1_0::Geocode.new( :name => 'name', :value => 'value' ),
87
+ :polygons => RCAP::CAP_1_0::Polygon.new( :points => RCAP::CAP_1_0::Point.new( :lattitude =>1, :longitude => 1 )))
88
+
89
+ @area = RCAP::CAP_1_0::Area.from_h( @original_area.to_h )
90
+ end
91
+
92
+ it_should_behave_like( "it can parse into a CAP 1.0 Area object" )
93
+ end
94
+ end
95
+
96
+ context( 'when exported' ) do
97
+ before( :each ) do
98
+ @area = RCAP::CAP_1_0::Area.new( :area_desc => 'Area Description',
99
+ :altitude => 100,
100
+ :ceiling => 200,
101
+ :circles => RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
102
+ :geocodes => RCAP::CAP_1_0::Geocode.new( :name => 'name', :value => 'value' ),
103
+ :polygons => RCAP::CAP_1_0::Polygon.new( :points => RCAP::CAP_1_0::Point.new( :lattitude =>1, :longitude => 1 )))
104
+ end
105
+ context( 'to a hash' ) do
106
+ before( :each ) do
107
+ @area_hash = @area.to_h
108
+ end
109
+
110
+ it( 'should export the area description correctly' ) do
111
+ @area_hash[ RCAP::CAP_1_0::Area::AREA_DESC_KEY ].should == @area.area_desc
112
+ end
113
+
114
+ it( 'should export the altitude correctly' ) do
115
+ @area_hash[ RCAP::CAP_1_0::Area::ALTITUDE_KEY ].should == @area.altitude
116
+ end
117
+
118
+ it( 'should set the ceiling correctly' ) do
119
+ @area_hash[ RCAP::CAP_1_0::Area::CEILING_KEY ].should == @area.ceiling
120
+ end
121
+
122
+ it( 'should export the circles correctly' ) do
123
+ @area_hash[ RCAP::CAP_1_0::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
124
+ end
125
+
126
+ it( 'should export the geocodes correctly' ) do
127
+ @area_hash[ RCAP::CAP_1_0::Area::GEOCODES_KEY ].should == @area.geocodes.map{ |geocode| geocode.to_h }
128
+ end
129
+
130
+ it( 'should export the polygons correctly' ) do
131
+ @area_hash[ RCAP::CAP_1_0::Area::POLYGONS_KEY ].should == @area.polygons.map{ |polygon| polygon.to_h }
132
+ end
133
+ end
134
+ end
135
+
136
+ context( 'is not valid if' ) do
137
+ before( :each ) do
138
+ @area = RCAP::CAP_1_0::Area.new( :area_desc => "Cape Town Metropole" )
139
+ @area.should( be_valid )
140
+ end
141
+
142
+ it( 'does not have an area descrtiption (area_desc)') do
143
+ @area.area_desc = nil
144
+ @area.should_not( be_valid )
145
+ end
146
+
147
+ it( 'has a ceiling defined but no altitude' ) do
148
+ @area.ceiling = 1
149
+ @area.altitude = nil
150
+ @area.should_not( be_valid )
151
+ end
152
+
153
+ context( 'it contains circles and it' ) do
154
+ before( :each ) do
155
+ @area.circles << RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
156
+ @area.should( be_valid )
157
+ end
158
+
159
+ it( 'has an invalid circle' ) do
160
+ @area.circles.first.lattitude = nil
161
+ @area.should_not( be_valid )
162
+ end
163
+ end
164
+
165
+ context( 'it contains polygons and it' ) do
166
+ before( :each ) do
167
+ @polygon = RCAP::CAP_1_0::Polygon.new
168
+ @polygon.points.push( RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 0 ),
169
+ RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 1 ),
170
+ RCAP::CAP_1_0::Point.new( :lattitude => 1, :longitude => 0 ))
171
+ @area.polygons << @polygon
172
+ @area.should( be_valid )
173
+ end
174
+
175
+ it( 'has an invalid polygon' ) do
176
+ @polygon.points.first.lattitude = nil
177
+ @area.should_not( be_valid )
178
+ end
179
+ end
180
+
181
+ context( 'it contains geocodes and it' ) do
182
+ before( :each ) do
183
+ @geocode = RCAP::CAP_1_0::Geocode.new( :name => 'foo', :value => 'bar' )
184
+ @area.geocodes << @geocode
185
+ @area.should( be_valid )
186
+ end
187
+
188
+ it( 'has an invalid geocode' ) do
189
+ @geocode.value = nil
190
+ @area.should_not( be_valid )
191
+ end
192
+ end
193
+ end
194
+
195
+ describe( 'instance methods' ) do
196
+ before( :each ) do
197
+ @area = RCAP::CAP_1_0::Area.new
198
+ end
199
+
200
+ describe( '#add_polygon' ) do
201
+ before( :each ) do
202
+ @polygon = @area.add_polygon
203
+ end
204
+
205
+ it( 'should return a CAP 1.0 Polygon' ) do
206
+ @polygon.class.should == RCAP::CAP_1_0::Polygon
207
+ end
208
+
209
+ it( 'should add a Polygon to the polygons attribute' ) do
210
+ @area.polygons.size.should == 1
211
+ end
212
+ end
213
+
214
+ describe( '#add_circle' ) do
215
+ before( :each ) do
216
+ @circle = @area.add_circle( lattitude: 1, longitude: 1, radius: 1 )
217
+ end
218
+
219
+ it( 'should return a CAP 1.0 Circle' ) do
220
+ @circle.class.should == RCAP::CAP_1_0::Circle
221
+ @circle.lattitude.should == 1
222
+ @circle.longitude.should == 1
223
+ @circle.radius.should == 1
224
+ end
225
+
226
+ it( 'should add a circle to the circles attribute' ) do
227
+ @area.circles.size.should == 1
228
+ end
229
+ end
230
+
231
+ describe( '#add_geocode' ) do
232
+ before( :each ) do
233
+ @geocode = @area.add_geocode( name: 'Geocode', value: '123' )
234
+ end
235
+
236
+ it( 'should return a CAP 1.0 Geocode' ) do
237
+ @geocode.class.should == RCAP::CAP_1_0::Geocode
238
+ @geocode.name.should == 'Geocode'
239
+ @geocode.value.should == '123'
240
+ end
241
+
242
+ it( 'should add a geocode to the geocodes attribute' ) do
243
+ @area.geocodes.size.should == 1
244
+ end
245
+ end
246
+ end
247
+ end