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
@@ -1,6 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_1::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_1::Alert::STATUS_TEST
9
+ alert.scope = RCAP::CAP_1_1::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
+ end
24
+ alert.add_info
25
+ alert.add_info
26
+ end
27
+ end
28
+
4
29
  context( 'on initialisation' ) do
5
30
  before( :each ) do
6
31
  @alert = RCAP::CAP_1_1::Alert.new
@@ -42,18 +67,7 @@ describe( RCAP::CAP_1_1::Alert ) do
42
67
 
43
68
  context( 'from XML' ) do
44
69
  before( :each ) do
45
- @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
46
- :sent => DateTime.now,
47
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
48
- :scope => RCAP::CAP_1_1::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_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
55
- :incidents => [ 'Incident1', 'Incident2' ],
56
- :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
70
+ @original_alert = RCAP::CAP_1_1::Alert.new( &@alert_builder )
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,7 @@ describe( RCAP::CAP_1_1::Alert ) do
66
80
 
67
81
  context( 'from YAML' ) do
68
82
  before( :each ) do
69
- @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
70
- :sent => DateTime.now,
71
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
72
- :scope => RCAP::CAP_1_1::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_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
79
- :incidents => [ 'Incident1', 'Incident2' ],
80
- :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
83
+ @original_alert = RCAP::CAP_1_1::Alert.new( &@alert_builder )
81
84
  @yaml_string = @original_alert.to_yaml
82
85
  @alert = RCAP::CAP_1_1::Alert.from_yaml( @yaml_string )
83
86
  end
@@ -87,18 +90,7 @@ describe( RCAP::CAP_1_1::Alert ) do
87
90
 
88
91
  context( 'from a hash' ) do
89
92
  before( :each ) do
90
- @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
91
- :sent => DateTime.now,
92
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
93
- :scope => RCAP::CAP_1_1::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_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
100
- :incidents => [ 'Incident1', 'Incident2' ],
101
- :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
93
+ @original_alert = RCAP::CAP_1_1::Alert.new( &@alert_builder )
102
94
  @alert = RCAP::CAP_1_1::Alert.from_h( @original_alert.to_h )
103
95
  end
104
96
 
@@ -107,18 +99,7 @@ describe( RCAP::CAP_1_1::Alert ) do
107
99
 
108
100
  context( 'from JSON' ) do
109
101
  before( :each ) do
110
- @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
111
- :sent => DateTime.now,
112
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
113
- :scope => RCAP::CAP_1_1::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_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
120
- :incidents => [ 'Incident1', 'Incident2' ],
121
- :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
102
+ @original_alert = RCAP::CAP_1_1::Alert.new( &@alert_builder )
122
103
  @alert = RCAP::CAP_1_1::Alert.from_json( @original_alert.to_json )
123
104
  end
124
105
 
@@ -128,12 +109,14 @@ describe( RCAP::CAP_1_1::Alert ) do
128
109
 
129
110
  describe( 'is not valid if it' ) do
130
111
  before( :each ) do
131
- @alert = RCAP::CAP_1_1::Alert.new( :identifier => 'Identifier',
132
- :sender => "cap@tempuri.org",
133
- :sent => DateTime.now,
134
- :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
135
- :msg_type => RCAP::CAP_1_1::Alert::MSG_TYPE_ALERT,
136
- :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC )
112
+ @alert = RCAP::CAP_1_1::Alert.new do |alert|
113
+ alert.identifier = 'Identifier'
114
+ alert.sender = "cap@tempuri.org"
115
+ alert.sent = DateTime.now
116
+ alert.status = RCAP::CAP_1_1::Alert::STATUS_TEST
117
+ alert.msg_type = RCAP::CAP_1_1::Alert::MSG_TYPE_ALERT
118
+ alert.scope = RCAP::CAP_1_1::Alert::SCOPE_PUBLIC
119
+ end
137
120
  @alert.should( be_valid )
138
121
  end
139
122
 
@@ -186,11 +169,13 @@ describe( RCAP::CAP_1_1::Alert ) do
186
169
 
187
170
  context( 'has an info element and it' ) do
188
171
  it( 'is not valid' ) do
189
- @info = RCAP::CAP_1_1::Info.new( :event => 'Info Event',
190
- :categories => RCAP::CAP_1_1::Info::CATEGORY_GEO,
191
- :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
192
- :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
193
- :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED )
172
+ @info = @alert.add_info do |info|
173
+ info.event = 'Info Event'
174
+ info.categories << RCAP::CAP_1_1::Info::CATEGORY_GEO
175
+ info.urgency = RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE
176
+ info.severity = RCAP::CAP_1_1::Info::SEVERITY_EXTREME
177
+ info.certainty = RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED
178
+ end
194
179
  @info.event = nil
195
180
  @alert.infos << @info
196
181
  @info.should_not( be_valid )
@@ -206,7 +191,9 @@ describe( RCAP::CAP_1_1::Alert ) do
206
191
 
207
192
  describe( '#add_info' ) do
208
193
  before( :each ) do
209
- @info = @alert.add_info( :urgency => 'urgent' )
194
+ @info = @alert.add_info do |info|
195
+ info.urgency = 'urgent'
196
+ end
210
197
  @info.urgency.should == 'urgent'
211
198
  end
212
199
 
@@ -1,9 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_1::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
+
27
+ end
28
+
4
29
  context( 'on initialisation' ) do
5
30
  before( :each ) do
6
31
  @area = RCAP::CAP_1_1::Area.new
32
+
33
+ @original_area = RCAP::CAP_1_1::Area.new( &@area_builder )
7
34
  end
8
35
 
9
36
  # Atomic
@@ -44,14 +71,9 @@ describe( RCAP::CAP_1_1::Area ) do
44
71
 
45
72
  context( 'from XML' ) do
46
73
  before( :each ) do
47
- @original_area = RCAP::CAP_1_1::Area.new( :area_desc => 'Area Description',
48
- :altitude => 100,
49
- :ceiling => 200,
50
- :circles => RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
51
- :geocodes => RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' ),
52
- :polygons => RCAP::CAP_1_1::Polygon.new( :points => RCAP::CAP_1_1::Point.new( :lattitude =>1, :longitude => 1 )))
53
-
54
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :areas => @original_area ))
74
+
75
+ @alert = RCAP::CAP_1_1::Alert.new
76
+ @alert.add_info.add_area( &@area_builder )
55
77
  @xml_string = @alert.to_xml
56
78
  @xml_document = REXML::Document.new( @xml_string )
57
79
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -64,13 +86,6 @@ describe( RCAP::CAP_1_1::Area ) do
64
86
 
65
87
  context( 'from YAML Data' ) do
66
88
  before( :each ) do
67
- @original_area = RCAP::CAP_1_1::Area.new( :area_desc => 'Area Description',
68
- :altitude => 100,
69
- :ceiling => 200,
70
- :circles => RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
71
- :geocodes => RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' ),
72
- :polygons => RCAP::CAP_1_1::Polygon.new( :points => RCAP::CAP_1_1::Point.new( :lattitude =>1, :longitude => 1 )))
73
-
74
89
  @area = RCAP::CAP_1_1::Area.from_yaml_data( YAML.load( @original_area.to_yaml ))
75
90
  end
76
91
 
@@ -79,13 +94,6 @@ describe( RCAP::CAP_1_1::Area ) do
79
94
 
80
95
  context( 'from a hash' ) do
81
96
  before( :each ) do
82
- @original_area = RCAP::CAP_1_1::Area.new( :area_desc => 'Area Description',
83
- :altitude => 100,
84
- :ceiling => 200,
85
- :circles => RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
86
- :geocodes => RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' ),
87
- :polygons => RCAP::CAP_1_1::Polygon.new( :points => RCAP::CAP_1_1::Point.new( :lattitude =>1, :longitude => 1 )))
88
-
89
97
  @area = RCAP::CAP_1_1::Area.from_h( @original_area.to_h )
90
98
  end
91
99
 
@@ -95,13 +103,9 @@ describe( RCAP::CAP_1_1::Area ) do
95
103
 
96
104
  context( 'when exported' ) do
97
105
  before( :each ) do
98
- @area = RCAP::CAP_1_1::Area.new( :area_desc => 'Area Description',
99
- :altitude => 100,
100
- :ceiling => 200,
101
- :circles => RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
102
- :geocodes => RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' ),
103
- :polygons => RCAP::CAP_1_1::Polygon.new( :points => RCAP::CAP_1_1::Point.new( :lattitude =>1, :longitude => 1 )))
106
+ @area = RCAP::CAP_1_1::Area.new( &@area_builder )
104
107
  end
108
+
105
109
  context( 'to a hash' ) do
106
110
  before( :each ) do
107
111
  @area_hash = @area.to_h
@@ -120,7 +124,7 @@ describe( RCAP::CAP_1_1::Area ) do
120
124
  end
121
125
 
122
126
  it( 'should export the circles correctly' ) do
123
- @area_hash[ RCAP::CAP_1_1::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
127
+ @area_hash[ RCAP::CAP_1_1::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_a }
124
128
  end
125
129
 
126
130
  it( 'should export the geocodes correctly' ) do
@@ -135,7 +139,10 @@ describe( RCAP::CAP_1_1::Area ) do
135
139
 
136
140
  context( 'is not valid if' ) do
137
141
  before( :each ) do
138
- @area = RCAP::CAP_1_1::Area.new( :area_desc => "Cape Town Metropole" )
142
+ @area = RCAP::CAP_1_1::Area.new do |area|
143
+ area.area_desc = "Cape Town Metropole"
144
+ end
145
+
139
146
  @area.should( be_valid )
140
147
  end
141
148
 
@@ -152,7 +159,11 @@ describe( RCAP::CAP_1_1::Area ) do
152
159
 
153
160
  context( 'it contains circles and it' ) do
154
161
  before( :each ) do
155
- @area.circles << RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
162
+ @area.add_circle do |circle|
163
+ circle.lattitude = 0
164
+ circle.longitude = 0
165
+ circle.radius = 1
166
+ end
156
167
  @area.should( be_valid )
157
168
  end
158
169
 
@@ -164,29 +175,34 @@ describe( RCAP::CAP_1_1::Area ) do
164
175
 
165
176
  context( 'it contains polygons and it' ) do
166
177
  before( :each ) do
167
- @polygon = RCAP::CAP_1_1::Polygon.new
168
- @polygon.points.push( RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 ),
169
- RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 1 ),
170
- RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 ))
171
- @area.polygons << @polygon
172
- @area.should( be_valid )
178
+ @area.add_polygon do |polygon|
179
+ [[ 0, 0 ], [ 0, 1 ], [ 0, 0 ]].each do |lattitude, longitude|
180
+ polygon.add_point do |point|
181
+ point.lattitude = lattitude
182
+ point.longitude = longitude
183
+ end
184
+ end
185
+ @area.should( be_valid )
186
+ end
173
187
  end
174
188
 
175
189
  it( 'has an invalid polygon' ) do
176
- @polygon.points.first.lattitude = nil
190
+ @area.polygons.first.points.first.lattitude = nil
177
191
  @area.should_not( be_valid )
178
192
  end
179
193
  end
180
194
 
181
195
  context( 'it contains geocodes and it' ) do
182
196
  before( :each ) do
183
- @geocode = RCAP::CAP_1_1::Geocode.new( :name => 'foo', :value => 'bar' )
184
- @area.geocodes << @geocode
197
+ @area.add_geocode do |geocode|
198
+ geocode.name = 'foo'
199
+ geocode.value = 'bar'
200
+ end
185
201
  @area.should( be_valid )
186
202
  end
187
203
 
188
204
  it( 'has an invalid geocode' ) do
189
- @geocode.value = nil
205
+ @area.geocodes.first.value = nil
190
206
  @area.should_not( be_valid )
191
207
  end
192
208
  end
@@ -213,7 +229,11 @@ describe( RCAP::CAP_1_1::Area ) do
213
229
 
214
230
  describe( '#add_circle' ) do
215
231
  before( :each ) do
216
- @circle = @area.add_circle( lattitude: 1, longitude: 1, radius: 1 )
232
+ @circle = @area.add_circle do |circle|
233
+ circle.lattitude = 1
234
+ circle.longitude = 1
235
+ circle.radius = 1
236
+ end
217
237
  end
218
238
 
219
239
  it( 'should return a CAP 1.1 Circle' ) do
@@ -230,7 +250,10 @@ describe( RCAP::CAP_1_1::Area ) do
230
250
 
231
251
  describe( '#add_geocode' ) do
232
252
  before( :each ) do
233
- @geocode = @area.add_geocode( name: 'Geocode', value: '123' )
253
+ @geocode = @area.add_geocode do |geocode|
254
+ geocode.name = 'Geocode'
255
+ geocode.value = '123'
256
+ end
234
257
  end
235
258
 
236
259
  it( 'should return a CAP 1.1 Geocode' ) do
@@ -3,7 +3,12 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_1::Circle ) do
4
4
  describe( 'should not be valid if' ) do
5
5
  before( :each ) do
6
- @circle = RCAP::CAP_1_1::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
6
+ @circle = RCAP::CAP_1_1::Circle.new do |circle|
7
+ circle.lattitude = 0
8
+ circle.longitude = 0
9
+ circle.radius = 0
10
+ end
11
+
7
12
  @circle.should( be_valid )
8
13
  end
9
14
 
@@ -36,9 +41,19 @@ describe( RCAP::CAP_1_1::Circle ) do
36
41
  context( 'on initialisation' ) do
37
42
  context( 'from XML' ) do
38
43
  before( :each ) do
39
- @original_circle = RCAP::CAP_1_1::Circle.new( :radius => 10.5,
40
- :lattitude => 30, :longitude => 60 )
41
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :areas => RCAP::CAP_1_1::Area.new( :circles => @original_circle )))
44
+ @original_circle = RCAP::CAP_1_1::Circle.new do |circle|
45
+ circle.lattitude = 30
46
+ circle.longitude = 60
47
+ circle.radius = 10.5
48
+ end
49
+
50
+ @alert = RCAP::CAP_1_1::Alert.new
51
+ @alert.add_info.add_area.add_circle do |circle|
52
+ circle.lattitude = 30
53
+ circle.longitude = 60
54
+ circle.radius = 10.5
55
+ end
56
+
42
57
  @xml_string = @alert.to_xml
43
58
  @xml_document = REXML::Document.new( @xml_string )
44
59
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -59,7 +74,11 @@ describe( RCAP::CAP_1_1::Circle ) do
59
74
 
60
75
  context( 'from a hash' ) do
61
76
  before( :each ) do
62
- @original_circle = RCAP::CAP_1_1::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
77
+ @original_circle = RCAP::CAP_1_1::Circle.new do |circle|
78
+ circle.lattitude = 30
79
+ circle.longitude = 60
80
+ circle.radius = 10.5
81
+ end
63
82
  @circle = RCAP::CAP_1_1::Circle.from_h( @original_circle.to_h )
64
83
  end
65
84
 
@@ -76,7 +95,11 @@ describe( RCAP::CAP_1_1::Circle ) do
76
95
 
77
96
  context( 'when exported' ) do
78
97
  before( :each ) do
79
- @circle = RCAP::CAP_1_1::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
98
+ @circle = RCAP::CAP_1_1::Circle.new do |circle|
99
+ circle.lattitude = 30
100
+ circle.longitude = 60
101
+ circle.radius = 10.5
102
+ end
80
103
  end
81
104
 
82
105
  context( 'to hash' ) do
@@ -4,8 +4,13 @@ describe( RCAP::CAP_1_1::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_1::EventCode.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :event_codes => @original_event_code ))
7
+ @alert = RCAP::CAP_1_1::Alert.new do |alert|
8
+ alert.add_info.add_event_code do |event_code|
9
+ event_code.name = 'name'
10
+ event_code.value = 'value'
11
+ end
12
+ end
13
+ @original_event_code = @alert.infos.first.event_codes.first
9
14
  @xml_string = @alert.to_xml
10
15
  @xml_document = REXML::Document.new( @xml_string )
11
16
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -29,7 +34,10 @@ describe( RCAP::CAP_1_1::EventCode ) do
29
34
 
30
35
  context( 'when exported' ) do
31
36
  before( :each ) do
32
- @event_code = RCAP::CAP_1_1::EventCode.new( :name => 'name', :value => 'value' )
37
+ @event_code = RCAP::CAP_1_1::EventCode.new do |event_code|
38
+ event_code.name = 'name'
39
+ event_code.value = 'value'
40
+ end
33
41
  end
34
42
 
35
43
  context( 'to a hash' ) do
@@ -4,8 +4,13 @@ describe( RCAP::CAP_1_1::Geocode ) do
4
4
  context( 'when initialised' ) do
5
5
  context( 'from XML' ) do
6
6
  before( :each ) do
7
- @original_geocode = RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :areas => RCAP::CAP_1_1::Area.new( :geocodes => @original_geocode )))
7
+ @alert = RCAP::CAP_1_1::Alert.new do |alert|
8
+ alert.add_info.add_area.add_geocode do |geocode|
9
+ geocode.name = 'name'
10
+ geocode.value = 'value'
11
+ end
12
+ end
13
+ @original_geocode = @alert.infos.first.areas.first.geocodes.first
9
14
  @xml_string = @alert.to_xml
10
15
  @xml_document = REXML::Document.new( @xml_string )
11
16
  @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
@@ -30,7 +35,10 @@ describe( RCAP::CAP_1_1::Geocode ) do
30
35
 
31
36
  context( 'when exported' ) do
32
37
  before( :each ) do
33
- @geocode = RCAP::CAP_1_1::Geocode.new( :name => 'name', :value => 'value' )
38
+ @geocode = RCAP::CAP_1_1::Geocode.new do |geocode|
39
+ geocode.name = 'name'
40
+ geocode.value = 'value'
41
+ end
34
42
  end
35
43
 
36
44
  context( 'to a hash' ) do