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
data/lib/rcap.rb CHANGED
@@ -9,15 +9,30 @@ require 'rexml/formatters/pretty'
9
9
  require 'open-uri'
10
10
  require 'base64'
11
11
  require 'digest/sha1'
12
+
12
13
  # Extensions
13
- require 'extensions/array'
14
- require 'extensions/string'
15
- require 'extensions/date_time'
16
- require 'extensions/time'
14
+ require 'rcap/extensions/array'
15
+ require 'rcap/extensions/string'
16
+ require 'rcap/extensions/date_time'
17
+ require 'rcap/extensions/time'
18
+ require 'rcap/extensions/date'
19
+
17
20
  # RCAP
18
21
  require 'rcap/version'
19
22
  require 'rcap/utilities'
20
23
  require 'rcap/validations'
24
+ # Base
25
+ require 'rcap/base/parameter'
26
+ require 'rcap/base/point'
27
+ require 'rcap/base/circle'
28
+ require 'rcap/base/event_code'
29
+ require 'rcap/base/geocode'
30
+ require 'rcap/base/polygon'
31
+ require 'rcap/base/area'
32
+ require 'rcap/base/resource'
33
+ require 'rcap/base/info'
34
+ require 'rcap/base/alert'
35
+ # 1.0
21
36
  require 'rcap/cap_1_0/alert'
22
37
  require 'rcap/cap_1_0/parameter'
23
38
  require 'rcap/cap_1_0/event_code'
@@ -28,6 +43,7 @@ require 'rcap/cap_1_0/circle'
28
43
  require 'rcap/cap_1_0/polygon'
29
44
  require 'rcap/cap_1_0/geocode'
30
45
  require 'rcap/cap_1_0/area'
46
+ # 1.1
31
47
  require 'rcap/cap_1_1/alert'
32
48
  require 'rcap/cap_1_1/parameter'
33
49
  require 'rcap/cap_1_1/event_code'
@@ -38,6 +54,7 @@ require 'rcap/cap_1_1/circle'
38
54
  require 'rcap/cap_1_1/polygon'
39
55
  require 'rcap/cap_1_1/geocode'
40
56
  require 'rcap/cap_1_1/area'
57
+ # 1.2
41
58
  require 'rcap/cap_1_2/alert'
42
59
  require 'rcap/cap_1_2/parameter'
43
60
  require 'rcap/cap_1_2/event_code'
data/spec/alert_spec.rb CHANGED
@@ -1,20 +1,32 @@
1
+ require 'spec_helper'
2
+
1
3
  describe( RCAP::Alert ) do
2
4
  describe( 'initialising' ) do
3
5
 
4
6
  context( 'a CAP 1.0 alert' ) do
5
7
  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 ])
8
+ @original_alert = RCAP::CAP_1_0::Alert.new do |alert|
9
+ alert.sender = 'Sender'
10
+ alert.sent = DateTime.now
11
+ alert.status = RCAP::CAP_1_0::Alert::STATUS_TEST
12
+ alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
13
+ alert.source = 'Source'
14
+ alert.restriction = 'No Restriction'
15
+ [ 'Address 1', 'Address 2'].each do |address|
16
+ alert.addresses << address
17
+ end
18
+ ['Code1', 'Code2'].each do |code|
19
+ alert.codes << code
20
+ end
21
+ alert.note = 'Note'
22
+ [ "1.0,1", "1.0,2" ].each do |reference|
23
+ alert.references << reference
24
+ end
25
+ [ 'Incident1', 'Incident2' ].each do |incident|
26
+ alert.incidents << incident
27
+ end
28
+ 2.times{ alert.add_info }
29
+ end
18
30
  end
19
31
 
20
32
  shared_examples_for( 'it has parsed a CAP 1.0 alert correctly' ) do
@@ -65,18 +77,28 @@ describe( RCAP::Alert ) do
65
77
 
66
78
  context( 'a CAP 1.1 alert' ) do
67
79
  before( :each ) do
68
- @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
69
- :sent => DateTime.now,
70
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
71
- :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
72
- :source => 'Source',
73
- :restriction => 'No Restriction',
74
- :addresses => [ 'Address 1', 'Address 2'],
75
- :code => ['Code1', 'Code2'],
76
- :note => 'Note',
77
- :references => [ "1,1,1", "1,1,2" ],
78
- :incidents => [ 'Incident1', 'Incident2' ],
79
- :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
80
+ @original_alert = RCAP::CAP_1_1::Alert.new do |alert|
81
+ alert.sender = 'Sender'
82
+ alert.sent = DateTime.now
83
+ alert.status = RCAP::CAP_1_1::Alert::STATUS_TEST
84
+ alert.scope = RCAP::CAP_1_1::Alert::SCOPE_PUBLIC
85
+ alert.source = 'Source'
86
+ alert.restriction = 'No Restriction'
87
+ [ 'Address 1', 'Address 2'].each do |address|
88
+ alert.addresses << address
89
+ end
90
+ ['Code1', 'Code2'].each do |code|
91
+ alert.codes << code
92
+ end
93
+ alert.note = 'Note'
94
+ [ "1,1,1", "1,1,2" ].each do |reference|
95
+ alert.references << reference
96
+ end
97
+ [ 'Incident1', 'Incident2' ].each do |incident|
98
+ alert.incidents << incident
99
+ end
100
+ 2.times{ alert.add_info }
101
+ end
80
102
  end
81
103
 
82
104
  shared_examples_for( 'it has parsed a CAP 1.1 alert correctly' ) do
@@ -127,18 +149,28 @@ describe( RCAP::Alert ) do
127
149
 
128
150
  context( 'a CAP 1.2 alert' ) do
129
151
  before( :each ) do
130
- @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
131
- :sent => DateTime.now,
132
- :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
133
- :scope => RCAP::CAP_1_2::Alert::SCOPE_PUBLIC,
134
- :source => 'Source',
135
- :restriction => 'No Restriction',
136
- :addresses => [ 'Address 1', 'Address 2'],
137
- :codes => [ 'Code1', 'Code2'],
138
- :note => 'Note',
139
- :references => [ "1,1,1", "1,1,2" ],
140
- :incidents => [ 'Incident1', 'Incident2' ],
141
- :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
152
+ @original_alert = RCAP::CAP_1_2::Alert.new do |alert|
153
+ alert.sender = 'Sender'
154
+ alert.sent = DateTime.now
155
+ alert.status = RCAP::CAP_1_2::Alert::STATUS_TEST
156
+ alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PUBLIC
157
+ alert.source = 'Source'
158
+ alert.restriction = 'No Restriction'
159
+ [ 'Address 1', 'Address 2'].each do |address|
160
+ alert.addresses << address
161
+ end
162
+ ['Code1', 'Code2'].each do |code|
163
+ alert.codes << code
164
+ end
165
+ alert.note = 'Note'
166
+ [ "1,1,1", "1,1,2" ].each do |reference|
167
+ alert.references << reference
168
+ end
169
+ [ 'Incident1', 'Incident2' ].each do |incident|
170
+ alert.incidents << incident
171
+ end
172
+ 2.times{ alert.add_info }
173
+ end
142
174
  end
143
175
 
144
176
  shared_examples_for( 'it has parsed a CAP 1.2 alert correctly' ) do
@@ -189,7 +221,7 @@ describe( RCAP::Alert ) do
189
221
  end
190
222
 
191
223
  describe( 'external file' ) do
192
- def load_file( file_name )
224
+ def load_file( file_name )
193
225
  File.open( File.join( File.dirname( __FILE__ ), 'assets', file_name )){|f| f.read }
194
226
  end
195
227
 
@@ -4,6 +4,32 @@ describe( RCAP::CAP_1_0::Alert ) do
4
4
  context( 'on initialisation' ) do
5
5
  before( :each ) do
6
6
  @alert = RCAP::CAP_1_0::Alert.new
7
+
8
+ @original_alert = RCAP::CAP_1_0::Alert.new do |alert|
9
+ alert.sender = 'Sender'
10
+ alert.sent = DateTime.now
11
+ alert.status = RCAP::CAP_1_0::Alert::STATUS_TEST
12
+ alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
13
+ alert.source = 'Source'
14
+ alert.restriction = 'No Restriction'
15
+ [ 'Address 1', 'Address 2'].each do |address|
16
+ alert.addresses << address
17
+ end
18
+ [ 'Code1', 'Code2' ].each do |code|
19
+ alert.codes << code
20
+ end
21
+ alert.note = 'Note'
22
+ [ 'Sender1','Sender2' ].each do |sender|
23
+ a = RCAP::CAP_1_0::Alert.new do |a|
24
+ a.sender = sender
25
+ end
26
+ alert.references << a.to_reference
27
+ end
28
+ [ 'Incident1', 'Incident2' ].each do |incident|
29
+ alert.incidents << incident
30
+ end
31
+ 2.times{ alert.add_info }
32
+ end
7
33
  end
8
34
 
9
35
  it( 'should have a identifier' ){ @alert.identifier.should_not( be_nil )}
@@ -42,18 +68,6 @@ describe( RCAP::CAP_1_0::Alert ) do
42
68
 
43
69
  context( 'from XML' ) do
44
70
  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
71
  @xml_string = @original_alert.to_xml
58
72
  @xml_document = REXML::Document.new( @xml_string )
59
73
  @alert_element = @xml_document.root
@@ -66,18 +80,6 @@ describe( RCAP::CAP_1_0::Alert ) do
66
80
 
67
81
  context( 'from YAML' ) do
68
82
  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
83
  @yaml_string = @original_alert.to_yaml
82
84
  @alert = RCAP::CAP_1_0::Alert.from_yaml( @yaml_string )
83
85
  end
@@ -87,18 +89,6 @@ describe( RCAP::CAP_1_0::Alert ) do
87
89
 
88
90
  context( 'from a hash' ) do
89
91
  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
92
  @alert = RCAP::CAP_1_0::Alert.from_h( @original_alert.to_h )
103
93
  end
104
94
 
@@ -107,18 +97,6 @@ describe( RCAP::CAP_1_0::Alert ) do
107
97
 
108
98
  context( 'from JSON' ) do
109
99
  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
100
  @alert = RCAP::CAP_1_0::Alert.from_json( @original_alert.to_json )
123
101
  end
124
102
 
@@ -128,12 +106,14 @@ describe( RCAP::CAP_1_0::Alert ) do
128
106
 
129
107
  describe( 'is not valid if it' ) do
130
108
  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 )
109
+ @alert = RCAP::CAP_1_0::Alert.new do |alert|
110
+ alert.identifier = 'Identifier'
111
+ alert.sender = "cap@tempuri.org"
112
+ alert.sent = DateTime.now
113
+ alert.status = RCAP::CAP_1_0::Alert::STATUS_TEST
114
+ alert.msg_type = RCAP::CAP_1_0::Alert::MSG_TYPE_ALERT
115
+ alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
116
+ end
137
117
  @alert.should( be_valid )
138
118
  end
139
119
 
@@ -186,13 +166,15 @@ describe( RCAP::CAP_1_0::Alert ) do
186
166
 
187
167
  context( 'has an info element and it' ) do
188
168
  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 )
169
+ @info = @alert.add_info do |info|
170
+ info.event = 'Info Event'
171
+ info.urgency = RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE
172
+ info.severity = RCAP::CAP_1_0::Info::SEVERITY_EXTREME
173
+ info.certainty = RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY
174
+ end
175
+ @info.categories << RCAP::CAP_1_0::Info::CATEGORY_GEO
194
176
  @info.event = nil
195
- @alert.infos << @info
177
+
196
178
  @info.should_not( be_valid )
197
179
  @alert.should_not( be_valid )
198
180
  end
@@ -206,7 +188,10 @@ describe( RCAP::CAP_1_0::Alert ) do
206
188
 
207
189
  describe( '#add_info' ) do
208
190
  before( :each ) do
209
- @info = @alert.add_info( :urgency => 'urgent' )
191
+ @info = @alert.add_info do |info|
192
+ info.urgency = 'urgent'
193
+ end
194
+
210
195
  @info.urgency.should == 'urgent'
211
196
  end
212
197
 
@@ -4,6 +4,28 @@ describe( RCAP::CAP_1_0::Area ) do
4
4
  context( 'on initialisation' ) do
5
5
  before( :each ) do
6
6
  @area = RCAP::CAP_1_0::Area.new
7
+
8
+ @original_area = RCAP::CAP_1_0::Area.new do |area|
9
+ area.area_desc = 'Area Description'
10
+ area.altitude = 100
11
+ area.ceiling = 200
12
+
13
+ area.add_circle do |circle|
14
+ circle.lattitude = 0
15
+ circle.longitude = 0
16
+ circle.radius = 100
17
+ end
18
+
19
+ area.add_geocode do |geocode|
20
+ geocode.name = 'name'
21
+ geocode.value = 'value'
22
+ end
23
+
24
+ area.add_polygon.add_point do |point|
25
+ point.lattitude = 1
26
+ point.longitude = 2
27
+ end
28
+ end
7
29
  end
8
30
 
9
31
  # Atomic
@@ -44,14 +66,9 @@ describe( RCAP::CAP_1_0::Area ) do
44
66
 
45
67
  context( 'from XML' ) do
46
68
  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 ))
69
+
70
+ @alert = RCAP::CAP_1_0::Alert.new
71
+ @alert.add_info.areas << @original_area
55
72
  @xml_string = @alert.to_xml
56
73
  @xml_document = REXML::Document.new( @xml_string )
57
74
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
@@ -64,12 +81,6 @@ describe( RCAP::CAP_1_0::Area ) do
64
81
 
65
82
  context( 'from YAML Data' ) do
66
83
  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
84
 
74
85
  @area = RCAP::CAP_1_0::Area.from_yaml_data( YAML.load( @original_area.to_yaml ))
75
86
  end
@@ -79,12 +90,6 @@ describe( RCAP::CAP_1_0::Area ) do
79
90
 
80
91
  context( 'from a hash' ) do
81
92
  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
93
 
89
94
  @area = RCAP::CAP_1_0::Area.from_h( @original_area.to_h )
90
95
  end
@@ -95,13 +100,29 @@ describe( RCAP::CAP_1_0::Area ) do
95
100
 
96
101
  context( 'when exported' ) do
97
102
  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 )))
103
+ @area = RCAP::CAP_1_0::Area.new do |area|
104
+ area.area_desc = 'Area Description'
105
+ area.altitude = 100
106
+ area.ceiling = 200
107
+
108
+ area.add_circle do |circle|
109
+ circle.lattitude = 0
110
+ circle.longitude = 0
111
+ circle.radius = 100
112
+ end
113
+
114
+ area.add_geocode do |geocode|
115
+ geocode.name = 'name'
116
+ geocode.value = 'value'
117
+ end
118
+
119
+ area.add_polygon.add_point do |point|
120
+ point.lattitude = 1
121
+ point.longitude = 1
122
+ end
123
+ end
104
124
  end
125
+
105
126
  context( 'to a hash' ) do
106
127
  before( :each ) do
107
128
  @area_hash = @area.to_h
@@ -120,7 +141,7 @@ describe( RCAP::CAP_1_0::Area ) do
120
141
  end
121
142
 
122
143
  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 }
144
+ @area_hash[ RCAP::CAP_1_0::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_a }
124
145
  end
125
146
 
126
147
  it( 'should export the geocodes correctly' ) do
@@ -135,7 +156,9 @@ describe( RCAP::CAP_1_0::Area ) do
135
156
 
136
157
  context( 'is not valid if' ) do
137
158
  before( :each ) do
138
- @area = RCAP::CAP_1_0::Area.new( :area_desc => "Cape Town Metropole" )
159
+ @area = RCAP::CAP_1_0::Area.new do |area|
160
+ area.area_desc = "Cape Town Metropole"
161
+ end
139
162
  @area.should( be_valid )
140
163
  end
141
164
 
@@ -152,7 +175,11 @@ describe( RCAP::CAP_1_0::Area ) do
152
175
 
153
176
  context( 'it contains circles and it' ) do
154
177
  before( :each ) do
155
- @area.circles << RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
178
+ @area.add_circle do |circle|
179
+ circle.lattitude = 0
180
+ circle.longitude = 0
181
+ circle.radius = 1
182
+ end
156
183
  @area.should( be_valid )
157
184
  end
158
185
 
@@ -165,9 +192,13 @@ describe( RCAP::CAP_1_0::Area ) do
165
192
  context( 'it contains polygons and it' ) do
166
193
  before( :each ) do
167
194
  @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 => 0, :longitude => 0 ))
195
+ [[ 0, 0], [ 0, 1 ], [ 0, 0 ]].each do |lattitude, longitude|
196
+ @polygon.add_point do |point|
197
+ point.lattitude = lattitude
198
+ point.longitude = longitude
199
+ end
200
+ end
201
+
171
202
  @area.polygons << @polygon
172
203
  @area.should( be_valid )
173
204
  end
@@ -180,13 +211,15 @@ describe( RCAP::CAP_1_0::Area ) do
180
211
 
181
212
  context( 'it contains geocodes and it' ) do
182
213
  before( :each ) do
183
- @geocode = RCAP::CAP_1_0::Geocode.new( :name => 'foo', :value => 'bar' )
184
- @area.geocodes << @geocode
214
+ @area.add_geocode do |geocode|
215
+ geocode.name = 'foo'
216
+ geocode.value = 'bar'
217
+ end
185
218
  @area.should( be_valid )
186
219
  end
187
220
 
188
221
  it( 'has an invalid geocode' ) do
189
- @geocode.value = nil
222
+ @area.geocodes.first.value = nil
190
223
  @area.should_not( be_valid )
191
224
  end
192
225
  end
@@ -213,7 +246,11 @@ describe( RCAP::CAP_1_0::Area ) do
213
246
 
214
247
  describe( '#add_circle' ) do
215
248
  before( :each ) do
216
- @circle = @area.add_circle( lattitude: 1, longitude: 1, radius: 1 )
249
+ @circle = @area.add_circle do |circle|
250
+ circle.lattitude = 1
251
+ circle.longitude = 1
252
+ circle.radius = 1
253
+ end
217
254
  end
218
255
 
219
256
  it( 'should return a CAP 1.0 Circle' ) do
@@ -230,7 +267,10 @@ describe( RCAP::CAP_1_0::Area ) do
230
267
 
231
268
  describe( '#add_geocode' ) do
232
269
  before( :each ) do
233
- @geocode = @area.add_geocode( name: 'Geocode', value: '123' )
270
+ @geocode = @area.add_geocode do |geocode|
271
+ geocode.name = 'Geocode'
272
+ geocode.value = '123'
273
+ end
234
274
  end
235
275
 
236
276
  it( 'should return a CAP 1.0 Geocode' ) do
@@ -3,7 +3,11 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_0::Circle ) do
4
4
  describe( 'should not be valid if' ) do
5
5
  before( :each ) do
6
- @circle = RCAP::CAP_1_0::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
6
+ @circle = RCAP::CAP_1_0::Circle.new do |circle|
7
+ circle.lattitude = 0
8
+ circle.longitude = 0
9
+ circle.radius = 1
10
+ end
7
11
  @circle.should( be_valid )
8
12
  end
9
13
 
@@ -36,9 +40,17 @@ describe( RCAP::CAP_1_0::Circle ) do
36
40
  context( 'on initialisation' ) do
37
41
  context( 'from XML' ) do
38
42
  before( :each ) do
39
- @original_circle = RCAP::CAP_1_0::Circle.new( :radius => 10.5,
40
- :lattitude => 30, :longitude => 60 )
41
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :areas => RCAP::CAP_1_0::Area.new( :circles => @original_circle )))
43
+ @original_circle = RCAP::CAP_1_0::Circle.new do |circle|
44
+ circle.radius = 10.5
45
+ circle.lattitude = 30
46
+ circle.longitude = 60
47
+ end
48
+ @alert = RCAP::CAP_1_0::Alert.new
49
+ @alert.add_info.add_area.add_circle do |circle|
50
+ circle.radius = 10.5
51
+ circle.lattitude = 30
52
+ circle.longitude = 60
53
+ end
42
54
  @xml_string = @alert.to_xml
43
55
  @xml_document = REXML::Document.new( @xml_string )
44
56
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
@@ -59,7 +71,11 @@ describe( RCAP::CAP_1_0::Circle ) do
59
71
 
60
72
  context( 'from a hash' ) do
61
73
  before( :each ) do
62
- @original_circle = RCAP::CAP_1_0::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
74
+ @original_circle = RCAP::CAP_1_0::Circle.new do |circle|
75
+ circle.radius = 10.5
76
+ circle.lattitude = 30
77
+ circle.longitude = 60
78
+ end
63
79
  @circle = RCAP::CAP_1_0::Circle.from_h( @original_circle.to_h )
64
80
  end
65
81
 
@@ -76,7 +92,11 @@ describe( RCAP::CAP_1_0::Circle ) do
76
92
 
77
93
  context( 'when exported' ) do
78
94
  before( :each ) do
79
- @circle = RCAP::CAP_1_0::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
95
+ @circle = RCAP::CAP_1_0::Circle.new do |circle|
96
+ circle.radius = 10.5
97
+ circle.lattitude = 30
98
+ circle.longitude = 60
99
+ end
80
100
  end
81
101
 
82
102
  context( 'to hash' ) do
@@ -4,8 +4,12 @@ describe( RCAP::CAP_1_0::EventCode ) do
4
4
  context( 'when initialised' ) do
5
5
  context( 'from XML' ) do
6
6
  before( :each ) do
7
- @original_event_code = RCAP::CAP_1_0::EventCode.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :event_codes => @original_event_code ))
7
+ @original_event_code = RCAP::CAP_1_0::EventCode.new do |event_code|
8
+ event_code.name = 'name'
9
+ event_code.value = 'value'
10
+ end
11
+ @alert = RCAP::CAP_1_0::Alert.new
12
+ @alert.add_info.event_codes << @original_event_code
9
13
  @xml_string = @alert.to_xml
10
14
  @xml_document = REXML::Document.new( @xml_string )
11
15
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
@@ -29,7 +33,10 @@ describe( RCAP::CAP_1_0::EventCode ) do
29
33
 
30
34
  context( 'when exported' ) do
31
35
  before( :each ) do
32
- @event_code = RCAP::CAP_1_0::EventCode.new( :name => 'name', :value => 'value' )
36
+ @event_code = RCAP::CAP_1_0::EventCode.new do |event_code|
37
+ event_code.name = 'name'
38
+ event_code.value = 'value'
39
+ end
33
40
  end
34
41
 
35
42
  context( 'to a hash' ) do