rcap 1.3.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/README.md +78 -151
  3. data/Rakefile +1 -1
  4. data/lib/rcap/alert.rb +2 -2
  5. data/lib/rcap/base/alert.rb +446 -0
  6. data/lib/rcap/base/area.rb +228 -0
  7. data/lib/rcap/base/circle.rb +121 -0
  8. data/lib/rcap/base/event_code.rb +6 -0
  9. data/lib/rcap/base/geocode.rb +6 -0
  10. data/lib/rcap/base/info.rb +498 -0
  11. data/lib/rcap/base/parameter.rb +88 -0
  12. data/lib/rcap/base/point.rb +87 -0
  13. data/lib/rcap/base/polygon.rb +120 -0
  14. data/lib/rcap/base/resource.rb +168 -0
  15. data/lib/rcap/cap_1_0/alert.rb +59 -342
  16. data/lib/rcap/cap_1_0/area.rb +13 -188
  17. data/lib/rcap/cap_1_0/circle.rb +2 -100
  18. data/lib/rcap/cap_1_0/event_code.rb +8 -3
  19. data/lib/rcap/cap_1_0/geocode.rb +8 -3
  20. data/lib/rcap/cap_1_0/info.rb +16 -468
  21. data/lib/rcap/cap_1_0/parameter.rb +9 -67
  22. data/lib/rcap/cap_1_0/point.rb +2 -61
  23. data/lib/rcap/cap_1_0/polygon.rb +5 -95
  24. data/lib/rcap/cap_1_0/resource.rb +4 -144
  25. data/lib/rcap/cap_1_1/alert.rb +7 -412
  26. data/lib/rcap/cap_1_1/area.rb +13 -188
  27. data/lib/rcap/cap_1_1/circle.rb +2 -100
  28. data/lib/rcap/cap_1_1/event_code.rb +8 -3
  29. data/lib/rcap/cap_1_1/geocode.rb +7 -3
  30. data/lib/rcap/cap_1_1/info.rb +127 -386
  31. data/lib/rcap/cap_1_1/parameter.rb +4 -76
  32. data/lib/rcap/cap_1_1/point.rb +2 -61
  33. data/lib/rcap/cap_1_1/polygon.rb +5 -95
  34. data/lib/rcap/cap_1_1/resource.rb +37 -143
  35. data/lib/rcap/cap_1_2/alert.rb +8 -413
  36. data/lib/rcap/cap_1_2/area.rb +13 -188
  37. data/lib/rcap/cap_1_2/circle.rb +2 -100
  38. data/lib/rcap/cap_1_2/event_code.rb +8 -3
  39. data/lib/rcap/cap_1_2/geocode.rb +8 -3
  40. data/lib/rcap/cap_1_2/info.rb +132 -419
  41. data/lib/rcap/cap_1_2/parameter.rb +4 -76
  42. data/lib/rcap/cap_1_2/point.rb +2 -61
  43. data/lib/rcap/cap_1_2/polygon.rb +5 -92
  44. data/lib/rcap/cap_1_2/resource.rb +31 -134
  45. data/lib/rcap/config.rb +3 -0
  46. data/lib/{extensions → rcap/extensions}/array.rb +1 -1
  47. data/lib/rcap/extensions/date.rb +11 -0
  48. data/lib/{extensions → rcap/extensions}/date_time.rb +2 -5
  49. data/lib/{extensions → rcap/extensions}/string.rb +1 -1
  50. data/lib/{extensions → rcap/extensions}/time.rb +2 -4
  51. data/lib/rcap/utilities.rb +11 -11
  52. data/lib/rcap/validations.rb +7 -2
  53. data/lib/rcap/version.rb +1 -1
  54. data/lib/rcap.rb +21 -4
  55. data/spec/alert_spec.rb +69 -37
  56. data/spec/cap_1_0/alert_spec.rb +46 -61
  57. data/spec/cap_1_0/area_spec.rb +77 -37
  58. data/spec/cap_1_0/circle_spec.rb +26 -6
  59. data/spec/cap_1_0/event_code_spec.rb +10 -3
  60. data/spec/cap_1_0/geocode_spec.rb +11 -4
  61. data/spec/cap_1_0/info_spec.rb +74 -77
  62. data/spec/cap_1_0/parameter_spec.rb +18 -5
  63. data/spec/cap_1_0/point_spec.rb +9 -2
  64. data/spec/cap_1_0/polygon_spec.rb +52 -9
  65. data/spec/cap_1_0/resource_spec.rb +28 -21
  66. data/spec/cap_1_1/alert_spec.rb +47 -60
  67. data/spec/cap_1_1/area_spec.rb +66 -43
  68. data/spec/cap_1_1/circle_spec.rb +29 -6
  69. data/spec/cap_1_1/event_code_spec.rb +11 -3
  70. data/spec/cap_1_1/geocode_spec.rb +11 -3
  71. data/spec/cap_1_1/info_spec.rb +262 -118
  72. data/spec/cap_1_1/parameter_spec.rb +12 -3
  73. data/spec/cap_1_1/point_spec.rb +8 -2
  74. data/spec/cap_1_1/polygon_spec.rb +57 -18
  75. data/spec/cap_1_1/resource_spec.rb +70 -20
  76. data/spec/cap_1_2/alert_spec.rb +97 -110
  77. data/spec/cap_1_2/area_spec.rb +59 -41
  78. data/spec/cap_1_2/circle_spec.rb +15 -8
  79. data/spec/cap_1_2/event_code_spec.rb +11 -3
  80. data/spec/cap_1_2/geocode_spec.rb +11 -3
  81. data/spec/cap_1_2/info_spec.rb +266 -119
  82. data/spec/cap_1_2/parameter_spec.rb +11 -3
  83. data/spec/cap_1_2/point_spec.rb +10 -3
  84. data/spec/cap_1_2/polygon_spec.rb +25 -10
  85. data/spec/cap_1_2/resource_spec.rb +33 -28
  86. data/spec/{utilities_spec.rb → extensions_spec.rb} +0 -0
  87. data/spec/validations_spec.rb +18 -2
  88. metadata +20 -46
@@ -15,15 +15,16 @@ describe( RCAP::CAP_1_1::Resource ) do
15
15
 
16
16
  context( 'from XML' ) do
17
17
  before( :each ) do
18
- @original_resource = RCAP::CAP_1_1::Resource.new
19
- @original_resource.resource_desc = "Image of incident"
20
- @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
21
- @original_resource.mime_type = 'image/png'
22
- @original_resource.deref_uri = "IMAGE DATA"
23
- @original_resource.size = 20480
24
- @original_resource.digest = "2048"
25
-
26
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :resources => @original_resource ))
18
+ @alert = RCAP::CAP_1_1::Alert.new
19
+ @alert.add_info.add_resource do |resource|
20
+ resource.resource_desc = "Image of incident"
21
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
22
+ resource.mime_type = 'image/png'
23
+ resource.deref_uri = "IMAGE DATA"
24
+ resource.size = 20480
25
+ resource.digest = "2048"
26
+ end
27
+ @original_resource = @alert.infos.first.resources.first
27
28
  @xml_string = @alert.to_xml
28
29
  @xml_document = REXML::Document.new( @xml_string )
29
30
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -60,13 +61,14 @@ describe( RCAP::CAP_1_1::Resource ) do
60
61
 
61
62
  context( 'from a hash' ) do
62
63
  before( :each ) do
63
- @original_resource = RCAP::CAP_1_1::Resource.new
64
- @original_resource.resource_desc = "Image of incident"
65
- @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
66
- @original_resource.mime_type = 'image/png'
67
- @original_resource.deref_uri = "IMAGE DATA"
68
- @original_resource.size = 20480
69
- @original_resource.digest = "2048"
64
+ @original_resource = RCAP::CAP_1_1::Resource.new do |resource|
65
+ resource.resource_desc = "Image of incident"
66
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
67
+ resource.mime_type = 'image/png'
68
+ resource.deref_uri = "IMAGE DATA"
69
+ resource.size = 20480
70
+ resource.digest = "2048"
71
+ end
70
72
 
71
73
  @resource = RCAP::CAP_1_1::Resource.from_h( @original_resource.to_h )
72
74
  end
@@ -96,6 +98,43 @@ describe( RCAP::CAP_1_1::Resource ) do
96
98
  end
97
99
  end
98
100
 
101
+ context( 'from YAML' ) do
102
+ before( :each ) do
103
+ @original_resource = RCAP::CAP_1_1::Resource.new do |resource|
104
+ resource.resource_desc = "Image of incident"
105
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
106
+ resource.mime_type = 'image/png'
107
+ resource.deref_uri = "IMAGE DATA"
108
+ resource.size = 20480
109
+ resource.digest = "2048"
110
+ end
111
+ @resource = RCAP::CAP_1_1::Resource.from_yaml_data( YAML.load( @original_resource.to_yaml ))
112
+ end
113
+
114
+ it( 'should parse resource_desc correctly' ) do
115
+ @resource.resource_desc.should == @original_resource.resource_desc
116
+ end
117
+
118
+ it( 'should parse uri correctly' ) do
119
+ @resource.uri.should == @original_resource.uri
120
+ end
121
+
122
+ it( 'should parse mime_type correctly' ) do
123
+ @resource.mime_type.should == @original_resource.mime_type
124
+ end
125
+
126
+ it( 'should parse deref_uri correctly' ) do
127
+ @resource.deref_uri.should == @original_resource.deref_uri
128
+ end
129
+
130
+ it( 'should parse size correctly' ) do
131
+ @resource.size.should == @original_resource.size
132
+ end
133
+
134
+ it( 'should parse digest correctly' ) do
135
+ @resource.digest.should == @original_resource.digest
136
+ end
137
+ end
99
138
  end
100
139
 
101
140
  context( 'when exported' ) do
@@ -148,7 +187,9 @@ describe( RCAP::CAP_1_1::Resource ) do
148
187
 
149
188
  context( 'which is valid' ) do
150
189
  before( :each ) do
151
- @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description' )
190
+ @resource = RCAP::CAP_1_1::Resource.new do |resource|
191
+ resource.resource_desc = 'Resource Description'
192
+ end
152
193
  @resource.should( be_valid )
153
194
  end
154
195
 
@@ -162,7 +203,11 @@ describe( RCAP::CAP_1_1::Resource ) do
162
203
 
163
204
  context( 'with a non-rereferenced URI' ) do
164
205
  before( :each ) do
165
- @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description', :mime_type => 'text/csv', :uri => 'http://tempuri.org/resource.csv' )
206
+ @resource = RCAP::CAP_1_1::Resource.new do |resource|
207
+ resource.resource_desc = 'Resource Description'
208
+ resource.mime_type = 'text/csv'
209
+ resource.uri = 'http://tempuri.org/resource.csv'
210
+ end
166
211
  @content = "1,2\n3,4"
167
212
  @encoded_content = Base64.encode64( @content )
168
213
  stub_request( :get, @resource.uri ).to_return( :status => 200, :body => @content )
@@ -184,10 +229,15 @@ describe( RCAP::CAP_1_1::Resource ) do
184
229
  end
185
230
 
186
231
  context( 'with a dereferenced URI' ) do
187
- before( :each ) do
232
+ before( :each ) do
188
233
  @content = "1,2\n3,4"
189
234
  @encoded_content = Base64.encode64( @content )
190
- @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description', :mime_type => 'text/csv', :uri => 'http://tempuri.org/resource.csv', :deref_uri => @encoded_content )
235
+ @resource = RCAP::CAP_1_1::Resource.new do |resource|
236
+ resource.resource_desc = 'Resource Description'
237
+ resource.mime_type = 'text/csv'
238
+ resource.uri = 'http://tempuri.org/resource.csv'
239
+ resource.deref_uri = @encoded_content
240
+ end
191
241
  end
192
242
 
193
243
  describe( '#calculate_hash_and_size' ) do
@@ -1,6 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_2::Alert ) do
4
+ before( :each ) do
5
+ @alert_builder = lambda do |alert|
6
+ alert.sender = 'Sender'
7
+ alert.sent = DateTime.now
8
+ alert.status = RCAP::CAP_1_2::Alert::STATUS_TEST
9
+ alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PUBLIC
10
+ alert.source = 'Source'
11
+ alert.restriction = 'No Restriction'
12
+ [ 'Address 1', 'Address 2'].each do |address|
13
+ alert.addresses << address
14
+ end
15
+ [ 'Code1', 'Code2' ].each do |code|
16
+ alert.codes << code
17
+ end
18
+ alert.note = 'Note'
19
+ [ 'Reference1', 'Reference2' ].each do |reference|
20
+ alert.references << reference
21
+ end
22
+ [ 'Incident1', 'Incident2' ].each do |incident|
23
+ alert.incidents << incident
24
+ end
25
+ 2.times do
26
+ alert.add_info
27
+ end
28
+ end
29
+ end
30
+
4
31
  context( 'on initialisation' ) do
5
32
  before( :each ) do
6
33
  @alert = RCAP::CAP_1_2::Alert.new
@@ -42,18 +69,7 @@ describe( RCAP::CAP_1_2::Alert ) do
42
69
 
43
70
  context( 'from XML' ) do
44
71
  before( :each ) do
45
- @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
46
- :sent => DateTime.now,
47
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
48
- :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
55
- :incidents => [ 'Incident1', 'Incident2' ],
56
- :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
72
+ @original_alert = RCAP::CAP_1_2::Alert.new( &@alert_builder )
57
73
  @xml_string = @original_alert.to_xml
58
74
  @xml_document = REXML::Document.new( @xml_string )
59
75
  @alert_element = @xml_document.root
@@ -66,18 +82,7 @@ describe( RCAP::CAP_1_2::Alert ) do
66
82
 
67
83
  context( 'from YAML' ) do
68
84
  before( :each ) do
69
- @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
70
- :sent => DateTime.now,
71
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
72
- :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
79
- :incidents => [ 'Incident1', 'Incident2' ],
80
- :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
85
+ @original_alert = RCAP::CAP_1_2::Alert.new( &@alert_builder )
81
86
  @yaml_string = @original_alert.to_yaml
82
87
  @alert = RCAP::CAP_1_2::Alert.from_yaml( @yaml_string )
83
88
  end
@@ -87,18 +92,7 @@ describe( RCAP::CAP_1_2::Alert ) do
87
92
 
88
93
  context( 'from a hash' ) do
89
94
  before( :each ) do
90
- @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
91
- :sent => DateTime.now,
92
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
93
- :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
100
- :incidents => [ 'Incident1', 'Incident2' ],
101
- :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
95
+ @original_alert = RCAP::CAP_1_2::Alert.new( &@alert_builder )
102
96
  @alert = RCAP::CAP_1_2::Alert.from_h( @original_alert.to_h )
103
97
  end
104
98
 
@@ -107,18 +101,7 @@ describe( RCAP::CAP_1_2::Alert ) do
107
101
 
108
102
  context( 'from JSON' ) do
109
103
  before( :each ) do
110
- @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
111
- :sent => DateTime.now,
112
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
113
- :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
120
- :incidents => [ 'Incident1', 'Incident2' ],
121
- :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
104
+ @original_alert = RCAP::CAP_1_2::Alert.new( &@alert_builder )
122
105
  @alert = RCAP::CAP_1_2::Alert.from_json( @original_alert.to_json )
123
106
  end
124
107
 
@@ -128,80 +111,82 @@ describe( RCAP::CAP_1_2::Alert ) do
128
111
 
129
112
  describe( 'is not valid if it' ) do
130
113
  before( :each ) do
131
- @alert = RCAP::CAP_1_2::Alert.new( :identifier => 'Identifier',
132
- :sender => "cap@tempuri.org",
133
- :sent => DateTime.now,
134
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
135
- :msg_type => RCAP::CAP_1_2::Alert::MSG_TYPE_ALERT,
136
- :scope => RCAP::CAP_1_2::Alert::SCOPE_PUBLIC )
137
- @alert.should( be_valid )
138
- end
114
+ @alert = RCAP::CAP_1_2::Alert.new do |alert|
115
+ alert.identifier = 'Identifier'
116
+ alert.sender = "cap@tempuri.org"
117
+ alert.sent = DateTime.now
118
+ alert.status = RCAP::CAP_1_2::Alert::STATUS_TEST
119
+ alert.msg_type = RCAP::CAP_1_2::Alert::MSG_TYPE_ALERT
120
+ alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PUBLIC
121
+ @alert.should( be_valid )
122
+ end
139
123
 
140
- it( 'does not have a identifier' ) do
141
- @alert.identifier = nil
142
- @alert.should_not( be_valid )
143
- end
124
+ it( 'does not have a identifier' ) do
125
+ @alert.identifier = nil
126
+ @alert.should_not( be_valid )
127
+ end
144
128
 
145
- it( 'does not have a sender' ) do
146
- @alert.sender = nil
147
- @alert.should_not( be_valid )
148
- end
129
+ it( 'does not have a sender' ) do
130
+ @alert.sender = nil
131
+ @alert.should_not( be_valid )
132
+ end
149
133
 
150
- it( 'does not have a sent time (sent)' ) do
151
- @alert.sent = nil
152
- @alert.should_not( be_valid )
153
- end
134
+ it( 'does not have a sent time (sent)' ) do
135
+ @alert.sent = nil
136
+ @alert.should_not( be_valid )
137
+ end
154
138
 
155
- it( 'does not have a status' ) do
156
- @alert.status = nil
157
- @alert.should_not( be_valid )
158
- end
139
+ it( 'does not have a status' ) do
140
+ @alert.status = nil
141
+ @alert.should_not( be_valid )
142
+ end
159
143
 
160
- it( 'does not have a message type (msg_type)' ) do
161
- @alert.msg_type = nil
162
- @alert.should_not( be_valid )
163
- end
144
+ it( 'does not have a message type (msg_type)' ) do
145
+ @alert.msg_type = nil
146
+ @alert.should_not( be_valid )
147
+ end
164
148
 
165
- it( 'does not have a scope' ) do
166
- @alert.scope = nil
167
- @alert.should_not( be_valid )
168
- end
149
+ it( 'does not have a scope' ) do
150
+ @alert.scope = nil
151
+ @alert.should_not( be_valid )
152
+ end
169
153
 
170
154
 
171
- it( 'does not have a valid status' ) do
172
- @alert.status = 'incorrect value'
173
- @alert.should_not( be_valid )
174
- end
155
+ it( 'does not have a valid status' ) do
156
+ @alert.status = 'incorrect value'
157
+ @alert.should_not( be_valid )
158
+ end
175
159
 
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
160
+ it( 'does not have a valid message type msg_type' ) do
161
+ @alert.msg_type = 'incorrect value'
162
+ @alert.should_not( be_valid )
163
+ end
180
164
 
181
- it( 'does not have a valid scope' ) do
182
- @alert.scope = 'incorrect value'
183
- @alert.should_not( be_valid )
184
- end
165
+ it( 'does not have a valid scope' ) do
166
+ @alert.scope = 'incorrect value'
167
+ @alert.should_not( be_valid )
168
+ end
185
169
 
186
- it( 'does not have a restriction with a Restricted scope' ) do
187
- @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_RESTRICTED
188
- @alert.restriction = nil
189
- @alert.should_not( be_valid )
190
- end
170
+ it( 'does not have a restriction with a Restricted scope' ) do
171
+ @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_RESTRICTED
172
+ @alert.restriction = nil
173
+ @alert.should_not( be_valid )
174
+ end
191
175
 
192
- it( 'does not have any addresses with a Private scope' ) do
193
- @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PRIVATE
194
- @alert.addresses.clear
195
- @alert.should_not( be_valid )
196
- end
176
+ it( 'does not have any addresses with a Private scope' ) do
177
+ @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PRIVATE
178
+ @alert.addresses.clear
179
+ @alert.should_not( be_valid )
180
+ end
197
181
 
198
- context( 'has an info element and it' ) do
199
- it( 'is not valid' ) do
200
- @info = RCAP::CAP_1_2::Info.new( :event => 'Info Event',
201
- :categories => RCAP::CAP_1_2::Info::CATEGORY_GEO,
202
- :urgency => RCAP::CAP_1_2::Info::URGENCY_IMMEDIATE,
203
- :severity => RCAP::CAP_1_2::Info::SEVERITY_EXTREME,
204
- :certainty => RCAP::CAP_1_2::Info::CERTAINTY_OBSERVED )
182
+ it( 'has in invalid info attribute' ) do
183
+ @info = RCAP::CAP_1_2::Info.new do |info|
184
+ info.event = 'Info Event'
185
+ info.categories << RCAP::CAP_1_2::Info::CATEGORY_GEO
186
+ info.urgency = RCAP::CAP_1_2::Info::URGENCY_IMMEDIATE
187
+ info.severity = RCAP::CAP_1_2::Info::SEVERITY_EXTREME
188
+ info.certainty = RCAP::CAP_1_2::Info::CERTAINTY_OBSERVED
189
+ end
205
190
  @info.event = nil
206
191
  @alert.infos << @info
207
192
  @info.should_not( be_valid )
@@ -217,7 +202,9 @@ describe( RCAP::CAP_1_2::Alert ) do
217
202
 
218
203
  describe( '#add_info' ) do
219
204
  before( :each ) do
220
- @info = @alert.add_info( :urgency => 'urgent' )
205
+ @info = @alert.add_info do |info|
206
+ info.urgency = 'urgent'
207
+ end
221
208
  @info.urgency.should == 'urgent'
222
209
  end
223
210
 
@@ -1,9 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_2::Area ) do
4
+ before( :each ) do
5
+ @area_builder = lambda do |area|
6
+ area.area_desc = 'Area Description'
7
+ area.altitude = 100
8
+ area.ceiling = 200
9
+
10
+ area.add_circle do |circle|
11
+ circle.lattitude = 0
12
+ circle.longitude = 0
13
+ circle.radius = 100
14
+ end
15
+
16
+ area.add_geocode do |geocode|
17
+ geocode.name = 'name'
18
+ geocode.value = 'value'
19
+ end
20
+
21
+ area.add_polygon.add_point do |point|
22
+ point.lattitude = 1
23
+ point.longitude = 2
24
+ end
25
+ end
26
+ end
4
27
  context( 'on initialisation' ) do
5
28
  before( :each ) do
6
29
  @area = RCAP::CAP_1_2::Area.new
30
+ @original_area = RCAP::CAP_1_2::Area.new( &@area_builder )
7
31
  end
8
32
 
9
33
  # Atomic
@@ -44,14 +68,8 @@ describe( RCAP::CAP_1_2::Area ) do
44
68
 
45
69
  context( 'from XML' ) do
46
70
  before( :each ) do
47
- @original_area = RCAP::CAP_1_2::Area.new( :area_desc => 'Area Description',
48
- :altitude => 100,
49
- :ceiling => 200,
50
- :circles => RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
51
- :geocodes => RCAP::CAP_1_2::Geocode.new( :name => 'name', :value => 'value' ),
52
- :polygons => RCAP::CAP_1_2::Polygon.new( :points => RCAP::CAP_1_2::Point.new( :lattitude =>1, :longitude => 1 )))
53
-
54
- @alert = RCAP::CAP_1_2::Alert.new( :infos => RCAP::CAP_1_2::Info.new( :areas => @original_area ))
71
+ @alert = RCAP::CAP_1_2::Alert.new
72
+ @alert.add_info.add_area( &@area_builder )
55
73
  @xml_string = @alert.to_xml
56
74
  @xml_document = REXML::Document.new( @xml_string )
57
75
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
@@ -64,13 +82,6 @@ describe( RCAP::CAP_1_2::Area ) do
64
82
 
65
83
  context( 'from YAML Data' ) do
66
84
  before( :each ) do
67
- @original_area = RCAP::CAP_1_2::Area.new( :area_desc => 'Area Description',
68
- :altitude => 100,
69
- :ceiling => 200,
70
- :circles => RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
71
- :geocodes => RCAP::CAP_1_2::Geocode.new( :name => 'name', :value => 'value' ),
72
- :polygons => RCAP::CAP_1_2::Polygon.new( :points => RCAP::CAP_1_2::Point.new( :lattitude =>1, :longitude => 1 )))
73
-
74
85
  @area = RCAP::CAP_1_2::Area.from_yaml_data( YAML.load( @original_area.to_yaml ))
75
86
  end
76
87
 
@@ -79,13 +90,6 @@ describe( RCAP::CAP_1_2::Area ) do
79
90
 
80
91
  context( 'from a hash' ) do
81
92
  before( :each ) do
82
- @original_area = RCAP::CAP_1_2::Area.new( :area_desc => 'Area Description',
83
- :altitude => 100,
84
- :ceiling => 200,
85
- :circles => RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
86
- :geocodes => RCAP::CAP_1_2::Geocode.new( :name => 'name', :value => 'value' ),
87
- :polygons => RCAP::CAP_1_2::Polygon.new( :points => RCAP::CAP_1_2::Point.new( :lattitude =>1, :longitude => 1 )))
88
-
89
93
  @area = RCAP::CAP_1_2::Area.from_h( @original_area.to_h )
90
94
  end
91
95
 
@@ -95,13 +99,9 @@ describe( RCAP::CAP_1_2::Area ) do
95
99
 
96
100
  context( 'when exported' ) do
97
101
  before( :each ) do
98
- @area = RCAP::CAP_1_2::Area.new( :area_desc => 'Area Description',
99
- :altitude => 100,
100
- :ceiling => 200,
101
- :circles => RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
102
- :geocodes => RCAP::CAP_1_2::Geocode.new( :name => 'name', :value => 'value' ),
103
- :polygons => RCAP::CAP_1_2::Polygon.new( :points => RCAP::CAP_1_2::Point.new( :lattitude =>1, :longitude => 1 )))
102
+ @area = RCAP::CAP_1_2::Area.new( &@area_builder )
104
103
  end
104
+
105
105
  context( 'to a hash' ) do
106
106
  before( :each ) do
107
107
  @area_hash = @area.to_h
@@ -120,7 +120,7 @@ describe( RCAP::CAP_1_2::Area ) do
120
120
  end
121
121
 
122
122
  it( 'should export the circles correctly' ) do
123
- @area_hash[ RCAP::CAP_1_2::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
123
+ @area_hash[ RCAP::CAP_1_2::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_a }
124
124
  end
125
125
 
126
126
  it( 'should export the geocodes correctly' ) do
@@ -135,7 +135,9 @@ describe( RCAP::CAP_1_2::Area ) do
135
135
 
136
136
  context( 'is not valid if' ) do
137
137
  before( :each ) do
138
- @area = RCAP::CAP_1_2::Area.new( :area_desc => "Cape Town Metropole" )
138
+ @area = RCAP::CAP_1_2::Area.new do |area|
139
+ area.area_desc = "Cape Town Metropole"
140
+ end
139
141
  @area.should( be_valid )
140
142
  end
141
143
 
@@ -152,7 +154,11 @@ describe( RCAP::CAP_1_2::Area ) do
152
154
 
153
155
  context( 'it contains circles and it' ) do
154
156
  before( :each ) do
155
- @area.circles << RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
157
+ @area.add_circle do |circle|
158
+ circle.lattitude = 0
159
+ circle.longitude = 0
160
+ circle.radius = 1
161
+ end
156
162
  @area.should( be_valid )
157
163
  end
158
164
 
@@ -164,12 +170,14 @@ describe( RCAP::CAP_1_2::Area ) do
164
170
 
165
171
  context( 'it contains polygons and it' ) do
166
172
  before( :each ) do
167
- @polygon = RCAP::CAP_1_2::Polygon.new
168
- @polygon.points.push( RCAP::CAP_1_2::Point.new( :lattitude => 0, :longitude => 0 ),
169
- RCAP::CAP_1_2::Point.new( :lattitude => 0, :longitude => 1 ),
170
- RCAP::CAP_1_2::Point.new( :lattitude => 1, :longitude => 0 ),
171
- RCAP::CAP_1_2::Point.new( :lattitude => 0, :longitude => 0 ))
172
- @area.polygons << @polygon
173
+ @polygon = @area.add_polygon do |polygon|
174
+ [ 0, 1, 2, 0 ].each do |coordinate|
175
+ polygon.add_point do |point|
176
+ point.lattitude = coordinate
177
+ point.longitude = coordinate
178
+ end
179
+ end
180
+ end
173
181
  @area.should( be_valid )
174
182
  end
175
183
 
@@ -181,8 +189,11 @@ describe( RCAP::CAP_1_2::Area ) do
181
189
 
182
190
  context( 'it contains geocodes and it' ) do
183
191
  before( :each ) do
184
- @geocode = RCAP::CAP_1_2::Geocode.new( :name => 'foo', :value => 'bar' )
185
- @area.geocodes << @geocode
192
+ @geocode = @area.add_geocode do |geocode|
193
+ geocode.name = 'name'
194
+ geocode.value = 'value'
195
+ end
196
+
186
197
  @area.should( be_valid )
187
198
  end
188
199
 
@@ -214,7 +225,11 @@ describe( RCAP::CAP_1_2::Area ) do
214
225
 
215
226
  describe( '#add_circle' ) do
216
227
  before( :each ) do
217
- @circle = @area.add_circle( lattitude: 1, longitude: 1, radius: 1 )
228
+ @circle = @area.add_circle do |circle|
229
+ circle.lattitude = 1
230
+ circle.longitude = 1
231
+ circle.radius = 1
232
+ end
218
233
  end
219
234
 
220
235
  it( 'should return a CAP 1.1 Circle' ) do
@@ -231,7 +246,10 @@ describe( RCAP::CAP_1_2::Area ) do
231
246
 
232
247
  describe( '#add_geocode' ) do
233
248
  before( :each ) do
234
- @geocode = @area.add_geocode( name: 'Geocode', value: '123' )
249
+ @geocode = @area.add_geocode do |geocode|
250
+ geocode.name = 'Geocode'
251
+ geocode.value = '123'
252
+ end
235
253
  end
236
254
 
237
255
  it( 'should return a CAP 1.1 Geocode' ) do
@@ -1,16 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_2::Circle ) do
4
+ before( :each ) do
5
+ @circle_builder = lambda do |circle|
6
+ circle.lattitude = 0
7
+ circle.longitude = 0
8
+ circle.radius = 1
9
+ end
10
+ end
4
11
  describe( '#to_s' ) do
5
12
  it( 'should return a correct string' ) do
6
- @circle = RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
13
+ @circle = RCAP::CAP_1_2::Circle.new( &@circle_builder )
7
14
  @circle.to_s.should == '0,0 1'
8
15
  end
9
16
  end
10
17
 
11
18
  context( 'should not be valid if' ) do
12
19
  before( :each ) do
13
- @circle = RCAP::CAP_1_2::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
20
+ @circle = RCAP::CAP_1_2::Circle.new( &@circle_builder )
14
21
  @circle.should( be_valid )
15
22
  end
16
23
 
@@ -43,9 +50,9 @@ describe( RCAP::CAP_1_2::Circle ) do
43
50
  context( 'on initialisation' ) do
44
51
  context( 'from XML' ) do
45
52
  before( :each ) do
46
- @original_circle = RCAP::CAP_1_2::Circle.new( :radius => 10.5,
47
- :lattitude => 30, :longitude => 60 )
48
- @alert = RCAP::CAP_1_2::Alert.new( :infos => RCAP::CAP_1_2::Info.new( :areas => RCAP::CAP_1_2::Area.new( :circles => @original_circle )))
53
+ @original_circle = RCAP::CAP_1_2::Circle.new( &@circle_builder )
54
+ @alert = RCAP::CAP_1_2::Alert.new
55
+ @alert.add_info.add_area.add_circle( &@circle_builder )
49
56
  @xml_string = @alert.to_xml
50
57
  @xml_document = REXML::Document.new( @xml_string )
51
58
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
@@ -66,7 +73,7 @@ describe( RCAP::CAP_1_2::Circle ) do
66
73
 
67
74
  context( 'from a hash' ) do
68
75
  before( :each ) do
69
- @original_circle = RCAP::CAP_1_2::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
76
+ @original_circle = RCAP::CAP_1_2::Circle.new( &@circle_builder )
70
77
  @circle = RCAP::CAP_1_2::Circle.from_h( @original_circle.to_h )
71
78
  end
72
79
 
@@ -83,12 +90,12 @@ describe( RCAP::CAP_1_2::Circle ) do
83
90
 
84
91
  context( 'when exported' ) do
85
92
  before( :each ) do
86
- @circle = RCAP::CAP_1_2::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
93
+ @circle = RCAP::CAP_1_2::Circle.new( &@circle_builder )
87
94
  end
88
95
 
89
96
  context( 'to hash' ) do
90
97
  it( 'should be correct' ) do
91
- @circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
98
+ @circle.to_h.should == { 'radius' => 1, 'lattitude' => 0, 'longitude' => 0 }
92
99
  end
93
100
  end
94
101
  end