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
@@ -4,8 +4,12 @@ describe( RCAP::CAP_1_0::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_0::Geocode.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :areas => RCAP::CAP_1_0::Area.new( :geocodes => @original_geocode )))
7
+ @original_geocode = RCAP::CAP_1_0::Geocode.new do |geocode|
8
+ geocode.name = 'name'
9
+ geocode.value = 'value'
10
+ end
11
+ @alert = RCAP::CAP_1_0::Alert.new
12
+ @alert.add_info.add_area.geocodes << @original_geocode
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 )
@@ -17,7 +21,7 @@ describe( RCAP::CAP_1_0::Geocode ) do
17
21
  it( 'should parse into the correct class' ) do
18
22
  @geocode.class.should == RCAP::CAP_1_0::Geocode
19
23
  end
20
-
24
+
21
25
  it( 'should parse the name correctly' ) do
22
26
  @geocode.name.should == @original_geocode.name
23
27
  end
@@ -30,7 +34,10 @@ describe( RCAP::CAP_1_0::Geocode ) do
30
34
 
31
35
  context( 'when exported' ) do
32
36
  before( :each ) do
33
- @geocode = RCAP::CAP_1_0::Geocode.new( :name => 'name', :value => 'value' )
37
+ @geocode = RCAP::CAP_1_0::Geocode.new do |geocode|
38
+ geocode.name = 'name'
39
+ geocode.value = 'value'
40
+ end
34
41
  end
35
42
 
36
43
  context( 'to a hash' ) do
@@ -1,6 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe( RCAP::CAP_1_0::Info ) do
4
+ def create_info
5
+ RCAP::CAP_1_0::Info.new do |info|
6
+ [ RCAP::CAP_1_0::Info::CATEGORY_GEO, RCAP::CAP_1_0::Info::CATEGORY_FIRE ].each do |category|
7
+ info.categories << category
8
+ end
9
+ info.event = 'Event Description'
10
+ info.urgency = RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE
11
+ info.severity = RCAP::CAP_1_0::Info::SEVERITY_EXTREME
12
+ info.certainty = RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY
13
+ info.audience = 'Audience'
14
+ info.effective = DateTime.now
15
+ info.onset = DateTime.now + 1
16
+ info.expires = DateTime.now + 2
17
+ info.sender_name = 'Sender Name'
18
+ info.headline = 'Headline'
19
+ info.description = 'Description'
20
+ info.instruction = 'Instruction'
21
+ info.web = 'http://website'
22
+ info.contact = 'contact@address'
23
+
24
+ info.add_resource do |resource|
25
+ resource.resource_desc = 'Resource Description'
26
+ resource.uri = 'http://tempuri.org/resource'
27
+ end
28
+
29
+ [ [ 'name1', 'value1' ], [ 'name2', 'value2' ]].each do |name, value|
30
+ info.add_event_code do |event_code|
31
+ event_code.name = name
32
+ event_code.value = value
33
+ end
34
+ end
35
+
36
+ [ [ 'name1', 'value1' ], [ 'name2', 'value2' ]].each do |name, value|
37
+ info.add_parameter do |parameter|
38
+ parameter.name = name
39
+ parameter.value = value
40
+ end
41
+ end
42
+
43
+ [ 'Area1', 'Area2' ].each do |area_desc|
44
+ info.add_area do |area|
45
+ area.area_desc = area_desc
46
+ end
47
+ end
48
+ end
49
+ end
4
50
  context( 'on initialisation' ) do
5
51
  before( :each ) do
6
52
  @info = RCAP::CAP_1_0::Info.new
@@ -43,35 +89,16 @@ describe( RCAP::CAP_1_0::Info ) do
43
89
  it( 'should parse contact correctly' ){ @info.contact.should_not( be_nil ) ; @info.contact.should == @original_info.contact }
44
90
  it( 'should parse event_codes correctly' ){ @info.event_codes.should_not( be_nil ); @info.event_codes.should == @original_info.event_codes }
45
91
  it( 'should parse parameters correctly' ){ @info.parameters.should_not( be_nil ) ; @info.parameters.should == @original_info.parameters }
46
- it( 'should parse resources correctly' ){ @info.resources.should_not( be_nil ) ; @info.resources.should == @original_info.resources }
92
+ it( 'should parse resources correctly' ){ @info.resources.should_not( be_nil ) ; @info.resources.map( &:to_s ).should == @original_info.resources.map( &:to_s )}
47
93
  it( 'should parse areas correctly' ){ @info.areas.should_not( be_nil ) ; @info.areas.should == @original_info.areas }
48
94
  end
49
95
 
96
+
50
97
  context( 'from XML' ) do
51
98
  before( :each ) do
52
- @original_info = RCAP::CAP_1_0::Info.new( :categories => [ RCAP::CAP_1_0::Info::CATEGORY_GEO, RCAP::CAP_1_0::Info::CATEGORY_FIRE ],
53
- :event => 'Event Description',
54
- :urgency => RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE,
55
- :severity => RCAP::CAP_1_0::Info::SEVERITY_EXTREME,
56
- :certainty => RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY,
57
- :audience => 'Audience',
58
- :effective => DateTime.now,
59
- :onset => DateTime.now + 1,
60
- :expires => DateTime.now + 2,
61
- :sender_name => 'Sender Name',
62
- :headline => 'Headline',
63
- :description => 'Description',
64
- :instruction => 'Instruction',
65
- :web => 'http://website',
66
- :contact => 'contact@address',
67
- :event_codes => [ RCAP::CAP_1_0::EventCode.new( :name => 'name1', :value => 'value1' ),
68
- RCAP::CAP_1_0::EventCode.new( :name => 'name2', :value => 'value2' )],
69
- :parameters => [ RCAP::CAP_1_0::Parameter.new( :name => 'name1', :value => 'value1' ),
70
- RCAP::CAP_1_0::Parameter.new( :name => 'name2', :value => 'value2' )],
71
- :areas => [ RCAP::CAP_1_0::Area.new( :area_desc => 'Area1' ),
72
- RCAP::CAP_1_0::Area.new( :area_desc => 'Area2' )]
73
- )
74
- @alert = RCAP::CAP_1_0::Alert.new( :infos => @original_info )
99
+ @original_info = create_info
100
+ @alert = RCAP::CAP_1_0::Alert.new
101
+ @alert.infos << @original_info
75
102
  @xml_string = @alert.to_xml
76
103
  @xml_document = REXML::Document.new( @xml_string )
77
104
  @info = RCAP::CAP_1_0::Info.from_xml_element( RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS ))
@@ -82,28 +109,7 @@ describe( RCAP::CAP_1_0::Info ) do
82
109
 
83
110
  context( 'from a hash' ) do
84
111
  before( :each ) do
85
- @original_info = RCAP::CAP_1_0::Info.new( :categories => [ RCAP::CAP_1_0::Info::CATEGORY_GEO, RCAP::CAP_1_0::Info::CATEGORY_FIRE ],
86
- :event => 'Event Description',
87
- :urgency => RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE,
88
- :severity => RCAP::CAP_1_0::Info::SEVERITY_EXTREME,
89
- :certainty => RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY,
90
- :audience => 'Audience',
91
- :effective => DateTime.now,
92
- :onset => DateTime.now + 1,
93
- :expires => DateTime.now + 2,
94
- :sender_name => 'Sender Name',
95
- :headline => 'Headline',
96
- :description => 'Description',
97
- :instruction => 'Instruction',
98
- :web => 'http://website',
99
- :contact => 'contact@address',
100
- :event_codes => [ RCAP::CAP_1_0::EventCode.new( :name => 'name1', :value => 'value1' ),
101
- RCAP::CAP_1_0::EventCode.new( :name => 'name2', :value => 'value2' )],
102
- :parameters => [ RCAP::CAP_1_0::Parameter.new( :name => 'name1', :value => 'value1' ),
103
- RCAP::CAP_1_0::Parameter.new( :name => 'name2', :value => 'value2' )],
104
- :areas => [ RCAP::CAP_1_0::Area.new( :area_desc => 'Area1' ),
105
- RCAP::CAP_1_0::Area.new( :area_desc => 'Area2' )]
106
- )
112
+ @original_info = create_info
107
113
  @info = RCAP::CAP_1_0::Info.from_h( @original_info.to_h )
108
114
  end
109
115
  it_should_behave_like( "it can parse into a CAP 1.0 Info object" )
@@ -112,11 +118,13 @@ describe( RCAP::CAP_1_0::Info ) do
112
118
 
113
119
  context( 'is not valid if it' ) do
114
120
  before( :each ) do
115
- @info = RCAP::CAP_1_0::Info.new( :event => 'Info Event',
116
- :categories => RCAP::CAP_1_0::Info::CATEGORY_GEO,
117
- :urgency => RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE,
118
- :severity => RCAP::CAP_1_0::Info::SEVERITY_EXTREME,
119
- :certainty => RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY )
121
+ @info = RCAP::CAP_1_0::Info.new do |info|
122
+ info.event = 'Info Event'
123
+ info.categories << RCAP::CAP_1_0::Info::CATEGORY_GEO
124
+ info.urgency = RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE
125
+ info.severity = RCAP::CAP_1_0::Info::SEVERITY_EXTREME
126
+ info.certainty = RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY
127
+ end
120
128
  @info.valid?
121
129
  puts @info.errors.full_messages
122
130
  @info.should( be_valid )
@@ -147,28 +155,7 @@ describe( RCAP::CAP_1_0::Info ) do
147
155
  describe( 'when exported' ) do
148
156
  context( 'to hash' ) do
149
157
  before( :each ) do
150
- @info = RCAP::CAP_1_0::Info.new( :categories => [ RCAP::CAP_1_0::Info::CATEGORY_GEO, RCAP::CAP_1_0::Info::CATEGORY_FIRE ],
151
- :event => 'Event Description',
152
- :urgency => RCAP::CAP_1_0::Info::URGENCY_IMMEDIATE,
153
- :severity => RCAP::CAP_1_0::Info::SEVERITY_EXTREME,
154
- :certainty => RCAP::CAP_1_0::Info::CERTAINTY_VERY_LIKELY,
155
- :audience => 'Audience',
156
- :effective => DateTime.now,
157
- :onset => DateTime.now + 1,
158
- :expires => DateTime.now + 2,
159
- :sender_name => 'Sender Name',
160
- :headline => 'Headline',
161
- :description => 'Description',
162
- :instruction => 'Instruction',
163
- :web => 'http://website',
164
- :contact => 'contact@address',
165
- :resources => [ RCAP::CAP_1_0::Resource.new( :resource_desc => 'Resource Description', :uri => 'http://tempuri.org/resource' )],
166
- :event_codes => [ RCAP::CAP_1_0::EventCode.new( :name => 'name1', :value => 'value1' ),
167
- RCAP::CAP_1_0::EventCode.new( :name => 'name2', :value => 'value2' )],
168
- :parameters => [ RCAP::CAP_1_0::Parameter.new( :name => 'name1', :value => 'value1' ),
169
- RCAP::CAP_1_0::Parameter.new( :name => 'name2', :value => 'value2' )],
170
- :areas => [ RCAP::CAP_1_0::Area.new( :area_desc => 'Area1' ),
171
- RCAP::CAP_1_0::Area.new( :area_desc => 'Area2' )])
158
+ @info = create_info
172
159
  @info_hash = @info.to_h
173
160
  end
174
161
 
@@ -261,7 +248,10 @@ describe( RCAP::CAP_1_0::Info ) do
261
248
 
262
249
  describe( '#add_event_code' ) do
263
250
  before( :each ) do
264
- @event_code = @info.add_event_code( name: 'Event Code', value: '1234' )
251
+ @event_code = @info.add_event_code do |event_code|
252
+ event_code.name = 'Event Code'
253
+ event_code.value = '1234'
254
+ end
265
255
  end
266
256
 
267
257
  it( 'should return a 1.0 EventCode' ) do
@@ -277,7 +267,10 @@ describe( RCAP::CAP_1_0::Info ) do
277
267
 
278
268
  describe( '#add_parameter' ) do
279
269
  before( :each ) do
280
- @parameter = @info.add_parameter( name: 'Parameter', value: '1234' )
270
+ @parameter = @info.add_parameter do |parameter|
271
+ parameter.name = 'Parameter'
272
+ parameter.value = '1234'
273
+ end
281
274
  end
282
275
 
283
276
  it( 'should return a 1.0 Parameter' ) do
@@ -293,7 +286,9 @@ describe( RCAP::CAP_1_0::Info ) do
293
286
 
294
287
  describe( '#add_resource' ) do
295
288
  before( :each ) do
296
- @resource = @info.add_resource( resource_desc: 'Resource' )
289
+ @resource = @info.add_resource do |resource|
290
+ resource.resource_desc = 'Resource'
291
+ end
297
292
  end
298
293
 
299
294
  it( 'should return a 1.0 Resource' ) do
@@ -308,7 +303,9 @@ describe( RCAP::CAP_1_0::Info ) do
308
303
 
309
304
  describe( '#add_area' ) do
310
305
  before( :each ) do
311
- @area = @info.add_area( area_desc: 'Area' )
306
+ @area = @info.add_area do |area|
307
+ area.area_desc = 'Area'
308
+ end
312
309
  end
313
310
 
314
311
  it( 'should return a 1.0 area' ) do
@@ -4,8 +4,12 @@ describe( RCAP::CAP_1_0::Parameter ) do
4
4
  context( 'when initialised' ) do
5
5
  context( 'from XML' ) do
6
6
  before( :each ) do
7
- @original_parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
8
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :parameters => @original_parameter ))
7
+ @original_parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
8
+ parameter.name = 'name'
9
+ parameter.value = 'value'
10
+ end
11
+ @alert = RCAP::CAP_1_0::Alert.new
12
+ @alert.add_info.parameters << @original_parameter
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::Parameter ) do
29
33
 
30
34
  context( 'when exported' ) do
31
35
  before( :each ) do
32
- @parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
36
+ @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
37
+ parameter.name = 'name'
38
+ parameter.value = 'value'
39
+ end
33
40
  end
34
41
 
35
42
  context( 'to a hash' ) do
@@ -51,7 +58,10 @@ describe( RCAP::CAP_1_0::Parameter ) do
51
58
 
52
59
  describe( '.to_xml_element' ) do
53
60
  before( :each ) do
54
- @parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
61
+ @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
62
+ parameter.name = 'name'
63
+ parameter.value = 'value'
64
+ end
55
65
  end
56
66
 
57
67
  it( 'should generate an XML element correctly' ) do
@@ -61,7 +71,10 @@ describe( RCAP::CAP_1_0::Parameter ) do
61
71
 
62
72
  describe( '.from_xml_element' ) do
63
73
  before( :each ) do
64
- @parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
74
+ @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
75
+ parameter.name = 'name'
76
+ parameter.value = 'value'
77
+ end
65
78
  end
66
79
 
67
80
  it( 'should initialise correctly' ) do
@@ -3,7 +3,11 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_0::Point ) do
4
4
  describe( 'is not valid if' ) do
5
5
  before( :each ) do
6
- @point = RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 0 )
6
+ @point = RCAP::CAP_1_0::Point.new do |point|
7
+ point.lattitude = 0
8
+ point.longitude = 0
9
+ end
10
+
7
11
  @point.should( be_valid )
8
12
  end
9
13
 
@@ -34,7 +38,10 @@ describe( RCAP::CAP_1_0::Point ) do
34
38
 
35
39
  context( 'when exported' ) do
36
40
  before( :each ) do
37
- @point = RCAP::CAP_1_0::Point.new( :lattitude => 1, :longitude => 1 )
41
+ @point = RCAP::CAP_1_0::Point.new do |p|
42
+ p.lattitude = 1
43
+ p.longitude = 1
44
+ end
38
45
  end
39
46
 
40
47
  context( 'to hash' ) do
@@ -3,9 +3,13 @@ require 'spec_helper'
3
3
  describe( RCAP::CAP_1_0::Polygon ) do
4
4
  describe( 'is not valid if it' ) do
5
5
  before( :each ) do
6
- @polygon = RCAP::CAP_1_0::Polygon.new
7
- 3.times do
8
- @polygon.points << RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 0 )
6
+ @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
7
+ [1,2,1].each do |i|
8
+ polygon.add_point do |point|
9
+ point.lattitude = i
10
+ point.longitude = i
11
+ end
12
+ end
9
13
  end
10
14
  @polygon.should( be_valid )
11
15
  end
@@ -24,9 +28,31 @@ describe( RCAP::CAP_1_0::Polygon ) do
24
28
  context( 'on initialization' ) do
25
29
  context( 'from XML' ) do
26
30
  before( :each ) do
27
- @original_polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
31
+ @original_polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
32
+ 3.times do |i|
33
+ polygon.add_point do |point|
34
+ point.lattitude = i
35
+ point.longitude = i
36
+ end
37
+ end
38
+ end
28
39
  @empty_original_polygon = RCAP::CAP_1_0::Polygon.new()
29
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :areas => RCAP::CAP_1_0::Area.new( :polygons => [@original_polygon, @empty_original_polygon] )))
40
+ @alert = RCAP::CAP_1_0::Alert.new
41
+ @alert.add_info do |info|
42
+ info.add_area do |area|
43
+ [ @original_polygon, @empty_original_polygon ].each do |original_polygon|
44
+ area.add_polygon do |polygon|
45
+ original_polygon.points.each do |original_point|
46
+ polygon.add_point do |point|
47
+ point.lattitude = original_point.lattitude
48
+ point.longitude = original_point.longitude
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
30
56
  @xml_string = @alert.to_xml
31
57
  @xml_document = REXML::Document.new( @xml_string )
32
58
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
@@ -51,7 +77,14 @@ describe( RCAP::CAP_1_0::Polygon ) do
51
77
 
52
78
  context( 'from a hash' ) do
53
79
  before( :each ) do
54
- @polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
80
+ @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
81
+ 3.times do |i|
82
+ polygon.add_point do |point|
83
+ point.lattitude = i
84
+ point.longitude = i
85
+ end
86
+ end
87
+ end
55
88
  end
56
89
 
57
90
  it( 'should load all the points' ) do
@@ -63,12 +96,19 @@ describe( RCAP::CAP_1_0::Polygon ) do
63
96
 
64
97
  context( 'when exported' ) do
65
98
  before( :each ) do
66
- @polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
99
+ @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
100
+ 3.times do |i|
101
+ polygon.add_point do |point|
102
+ point.lattitude = i
103
+ point.longitude = i
104
+ end
105
+ end
106
+ end
67
107
  end
68
108
 
69
109
  context( 'to a hash' ) do
70
110
  it( 'should export correctly' ) do
71
- @polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
111
+ @polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_a }}
72
112
  end
73
113
  end
74
114
  end
@@ -80,7 +120,10 @@ describe( RCAP::CAP_1_0::Polygon ) do
80
120
 
81
121
  describe( '#add_point' ) do
82
122
  before( :each ) do
83
- @point = @polygon.add_point( lattitude: 1, longitude: 1 )
123
+ @point = @polygon.add_point do |polygon|
124
+ polygon.lattitude = 1
125
+ polygon.longitude = 1
126
+ end
84
127
  end
85
128
 
86
129
  it( 'should return a 1.0 Point' ) do
@@ -14,14 +14,16 @@ describe( RCAP::CAP_1_0::Resource ) do
14
14
 
15
15
  context( 'from XML' ) do
16
16
  before( :each ) do
17
- @original_resource = RCAP::CAP_1_0::Resource.new
18
- @original_resource.resource_desc = "Image of incident"
19
- @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
20
- @original_resource.mime_type = 'image/png'
21
- @original_resource.size = 20480
22
- @original_resource.digest = "2048"
23
-
24
- @alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :resources => @original_resource ))
17
+ @original_resource = RCAP::CAP_1_0::Resource.new do |resource|
18
+ resource.resource_desc = "Image of incident"
19
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
20
+ resource.mime_type = 'image/png'
21
+ resource.size = 20480
22
+ resource.digest = "2048"
23
+ end
24
+
25
+ @alert = RCAP::CAP_1_0::Alert.new
26
+ @alert.add_info.resources << @original_resource
25
27
  @xml_string = @alert.to_xml
26
28
  @xml_document = REXML::Document.new( @xml_string )
27
29
  @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
@@ -54,12 +56,13 @@ describe( RCAP::CAP_1_0::Resource ) do
54
56
 
55
57
  context( 'from a hash' ) do
56
58
  before( :each ) do
57
- @original_resource = RCAP::CAP_1_0::Resource.new
58
- @original_resource.resource_desc = "Image of incident"
59
- @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
60
- @original_resource.mime_type = 'image/png'
61
- @original_resource.size = 20480
62
- @original_resource.digest = "2048"
59
+ @original_resource = RCAP::CAP_1_0::Resource.new do |resource|
60
+ resource.resource_desc = "Image of incident"
61
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
62
+ resource.mime_type = 'image/png'
63
+ resource.size = 20480
64
+ resource.digest = "2048"
65
+ end
63
66
 
64
67
  @resource = RCAP::CAP_1_0::Resource.from_h( @original_resource.to_h )
65
68
  end
@@ -89,12 +92,13 @@ describe( RCAP::CAP_1_0::Resource ) do
89
92
 
90
93
  context( 'when exported' ) do
91
94
  before( :each ) do
92
- @resource = RCAP::CAP_1_0::Resource.new
93
- @resource.resource_desc = "Image of incident"
94
- @resource.uri = "http://capetown.gov.za/cap/resources/image.png"
95
- @resource.mime_type = 'image/png'
96
- @resource.size = 20480
97
- @resource.digest = "2048"
95
+ @resource = RCAP::CAP_1_0::Resource.new do |resource|
96
+ resource.resource_desc = "Image of incident"
97
+ resource.uri = "http://capetown.gov.za/cap/resources/image.png"
98
+ resource.mime_type = 'image/png'
99
+ resource.size = 20480
100
+ resource.digest = "2048"
101
+ end
98
102
  end
99
103
 
100
104
  context( 'to a hash' ) do
@@ -132,7 +136,10 @@ describe( RCAP::CAP_1_0::Resource ) do
132
136
 
133
137
  context( 'which is valid' ) do
134
138
  before( :each ) do
135
- @resource = RCAP::CAP_1_0::Resource.new( :resource_desc => 'Resource Description' )
139
+ @resource = RCAP::CAP_1_0::Resource.new do |resource|
140
+ resource.resource_desc = 'Resource Description'
141
+ end
142
+
136
143
  @resource.should( be_valid )
137
144
  end
138
145