rcap 2.4.1 → 2.7.3

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 (99) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +18 -0
  4. data/README.md +1 -0
  5. data/lib/rcap.rb +3 -1
  6. data/lib/rcap/alert.rb +30 -29
  7. data/lib/rcap/base/alert.rb +208 -205
  8. data/lib/rcap/base/area.rb +95 -91
  9. data/lib/rcap/base/circle.rb +45 -34
  10. data/lib/rcap/base/event_code.rb +2 -0
  11. data/lib/rcap/base/geocode.rb +2 -0
  12. data/lib/rcap/base/info.rb +273 -272
  13. data/lib/rcap/base/parameter.rb +29 -28
  14. data/lib/rcap/base/point.rb +26 -24
  15. data/lib/rcap/base/polygon.rb +43 -35
  16. data/lib/rcap/base/resource.rb +65 -65
  17. data/lib/rcap/cap_1_0/alert.rb +85 -86
  18. data/lib/rcap/cap_1_0/area.rb +2 -2
  19. data/lib/rcap/cap_1_0/circle.rb +2 -1
  20. data/lib/rcap/cap_1_0/event_code.rb +3 -1
  21. data/lib/rcap/cap_1_0/geocode.rb +3 -1
  22. data/lib/rcap/cap_1_0/info.rb +3 -3
  23. data/lib/rcap/cap_1_0/parameter.rb +13 -13
  24. data/lib/rcap/cap_1_0/point.rb +2 -1
  25. data/lib/rcap/cap_1_0/polygon.rb +3 -3
  26. data/lib/rcap/cap_1_0/resource.rb +2 -3
  27. data/lib/rcap/cap_1_1/alert.rb +6 -6
  28. data/lib/rcap/cap_1_1/area.rb +2 -2
  29. data/lib/rcap/cap_1_1/circle.rb +2 -1
  30. data/lib/rcap/cap_1_1/event_code.rb +3 -1
  31. data/lib/rcap/cap_1_1/geocode.rb +3 -1
  32. data/lib/rcap/cap_1_1/info.rb +125 -132
  33. data/lib/rcap/cap_1_1/parameter.rb +2 -3
  34. data/lib/rcap/cap_1_1/point.rb +2 -1
  35. data/lib/rcap/cap_1_1/polygon.rb +3 -3
  36. data/lib/rcap/cap_1_1/resource.rb +37 -38
  37. data/lib/rcap/cap_1_2/alert.rb +6 -6
  38. data/lib/rcap/cap_1_2/area.rb +2 -2
  39. data/lib/rcap/cap_1_2/circle.rb +2 -1
  40. data/lib/rcap/cap_1_2/event_code.rb +3 -1
  41. data/lib/rcap/cap_1_2/geocode.rb +3 -1
  42. data/lib/rcap/cap_1_2/info.rb +120 -123
  43. data/lib/rcap/cap_1_2/parameter.rb +2 -3
  44. data/lib/rcap/cap_1_2/point.rb +2 -1
  45. data/lib/rcap/cap_1_2/polygon.rb +4 -4
  46. data/lib/rcap/cap_1_2/resource.rb +38 -38
  47. data/lib/rcap/config.rb +5 -3
  48. data/lib/rcap/custom_validators.rb +75 -78
  49. data/lib/rcap/extensions/array.rb +3 -1
  50. data/lib/rcap/extensions/date.rb +3 -1
  51. data/lib/rcap/extensions/date_time.rb +5 -2
  52. data/lib/rcap/extensions/float.rb +2 -0
  53. data/lib/rcap/extensions/integer.rb +7 -0
  54. data/lib/rcap/extensions/nil_class.rb +2 -0
  55. data/lib/rcap/extensions/string.rb +6 -4
  56. data/lib/rcap/extensions/time.rb +5 -3
  57. data/lib/rcap/formatters/yaml.rb +5 -0
  58. data/lib/rcap/info.rb +6 -5
  59. data/lib/rcap/utilities.rb +27 -30
  60. data/lib/rcap/validation.rb +22 -21
  61. data/lib/rcap/version.rb +3 -1
  62. data/rcap.gemspec +5 -5
  63. data/spec/alert_spec.rb +141 -141
  64. data/spec/cap_1_0/alert_spec.rb +92 -94
  65. data/spec/cap_1_0/area_spec.rb +86 -86
  66. data/spec/cap_1_0/circle_spec.rb +48 -39
  67. data/spec/cap_1_0/event_code_spec.rb +15 -15
  68. data/spec/cap_1_0/geocode_spec.rb +16 -16
  69. data/spec/cap_1_0/info_spec.rb +175 -177
  70. data/spec/cap_1_0/parameter_spec.rb +27 -27
  71. data/spec/cap_1_0/point_spec.rb +18 -18
  72. data/spec/cap_1_0/polygon_spec.rb +43 -41
  73. data/spec/cap_1_0/resource_spec.rb +63 -64
  74. data/spec/cap_1_1/alert_spec.rb +107 -109
  75. data/spec/cap_1_1/area_spec.rb +90 -90
  76. data/spec/cap_1_1/circle_spec.rb +43 -34
  77. data/spec/cap_1_1/event_code_spec.rb +15 -16
  78. data/spec/cap_1_1/geocode_spec.rb +16 -16
  79. data/spec/cap_1_1/info_spec.rb +194 -196
  80. data/spec/cap_1_1/parameter_spec.rb +17 -17
  81. data/spec/cap_1_1/point_spec.rb +18 -18
  82. data/spec/cap_1_1/polygon_spec.rb +43 -41
  83. data/spec/cap_1_1/resource_spec.rb +106 -107
  84. data/spec/cap_1_2/alert_spec.rb +98 -99
  85. data/spec/cap_1_2/area_spec.rb +90 -90
  86. data/spec/cap_1_2/circle_spec.rb +52 -43
  87. data/spec/cap_1_2/event_code_spec.rb +19 -20
  88. data/spec/cap_1_2/geocode_spec.rb +20 -20
  89. data/spec/cap_1_2/info_spec.rb +196 -198
  90. data/spec/cap_1_2/parameter_spec.rb +19 -19
  91. data/spec/cap_1_2/point_spec.rb +21 -21
  92. data/spec/cap_1_2/polygon_spec.rb +55 -47
  93. data/spec/cap_1_2/resource_spec.rb +96 -97
  94. data/spec/extensions_spec.rb +29 -29
  95. data/spec/info_spec.rb +15 -15
  96. data/spec/spec_helper.rb +3 -3
  97. data/spec/validations_spec.rb +73 -73
  98. metadata +12 -11
  99. data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Parameter ) do
4
- context( 'when initialised' ) do
5
- context( 'from XML' ) do
6
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Parameter) do
4
+ context('when initialised') do
5
+ context('from XML') do
6
+ before(:each) do
7
7
  @original_parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
8
8
  parameter.name = 'name'
9
9
  parameter.value = 'value'
@@ -11,74 +11,74 @@ describe( RCAP::CAP_1_0::Parameter ) do
11
11
  @alert = RCAP::CAP_1_0::Alert.new
12
12
  @alert.add_info.parameters << @original_parameter
13
13
  @xml_string = @alert.to_xml
14
- @xml_document = REXML::Document.new( @xml_string )
15
- @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
16
- @parameter_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_0::Parameter::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
17
- @parameter = RCAP::CAP_1_0::Parameter.from_xml_element( @parameter_xml_element )
14
+ @xml_document = REXML::Document.new(@xml_string)
15
+ @info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
16
+ @parameter_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_0::Parameter::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
17
+ @parameter = RCAP::CAP_1_0::Parameter.from_xml_element(@parameter_xml_element)
18
18
  end
19
19
 
20
- it( 'should parse into the correct class' ) do
20
+ it('should parse into the correct class') do
21
21
  @parameter.class.should == RCAP::CAP_1_0::Parameter
22
22
  end
23
23
 
24
- it( 'should parse the name correctly' ) do
24
+ it('should parse the name correctly') do
25
25
  @parameter.name.should == @original_parameter.name
26
26
  end
27
27
 
28
- it( 'should parse the value correctly' ) do
28
+ it('should parse the value correctly') do
29
29
  @parameter.value.should == @original_parameter.value
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
- context( 'when exported' ) do
35
- before( :each ) do
34
+ context('when exported') do
35
+ before(:each) do
36
36
  @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
37
37
  parameter.name = 'name'
38
38
  parameter.value = 'value'
39
39
  end
40
40
  end
41
41
 
42
- context( 'to a hash' ) do
43
- it( 'should export correctly' ) do
42
+ context('to a hash') do
43
+ it('should export correctly') do
44
44
  @parameter.to_h.should == { 'name' => 'value' }
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
- describe( '.parse_parameter' ) do
50
- it( 'should parse valid content correctly' ) do
51
- RCAP::CAP_1_0::Parameter.parse_parameter( "name=value" ).should == { :name => 'name', :value => 'value' }
49
+ describe('.parse_parameter') do
50
+ it('should parse valid content correctly') do
51
+ RCAP::CAP_1_0::Parameter.parse_parameter('name=value').should == { name: 'name', value: 'value' }
52
52
  end
53
53
 
54
- it( 'should parse invalid content correctly' ) do
55
- RCAP::CAP_1_0::Parameter.parse_parameter( 'name' ).should == nil
54
+ it('should parse invalid content correctly') do
55
+ RCAP::CAP_1_0::Parameter.parse_parameter('name').should.nil?
56
56
  end
57
57
  end
58
58
 
59
- describe( '.to_xml_element' ) do
60
- before( :each ) do
59
+ describe('.to_xml_element') do
60
+ before(:each) do
61
61
  @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
62
62
  parameter.name = 'name'
63
63
  parameter.value = 'value'
64
64
  end
65
65
  end
66
66
 
67
- it( 'should generate an XML element correctly' ) do
67
+ it('should generate an XML element correctly') do
68
68
  @parameter.to_xml_element.text.should == 'name=value'
69
69
  end
70
70
  end
71
71
 
72
- describe( '.from_xml_element' ) do
73
- before( :each ) do
72
+ describe('.from_xml_element') do
73
+ before(:each) do
74
74
  @parameter = RCAP::CAP_1_0::Parameter.new do |parameter|
75
75
  parameter.name = 'name'
76
76
  parameter.value = 'value'
77
77
  end
78
78
  end
79
79
 
80
- it( 'should initialise correctly' ) do
81
- parameter = RCAP::CAP_1_0::Parameter.from_xml_element( @parameter.to_xml_element )
80
+ it('should initialise correctly') do
81
+ parameter = RCAP::CAP_1_0::Parameter.from_xml_element(@parameter.to_xml_element)
82
82
  parameter.name.should == @parameter.name
83
83
  parameter.value.should == @parameter.value
84
84
  end
@@ -1,51 +1,51 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Point ) do
4
- describe( 'is not valid if' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Point) do
4
+ describe('is not valid if') do
5
+ before(:each) do
6
6
  @point = RCAP::CAP_1_0::Point.new do |point|
7
7
  point.lattitude = 0
8
8
  point.longitude = 0
9
9
  end
10
10
 
11
- @point.should( be_valid )
11
+ @point.should(be_valid)
12
12
  end
13
13
 
14
- it( 'does not have a longitude defined' ) do
14
+ it('does not have a longitude defined') do
15
15
  @point.longitude = nil
16
- @point.should_not( be_valid )
16
+ @point.should_not(be_valid)
17
17
  end
18
18
 
19
- it( 'does not have a valid longitude' ) do
19
+ it('does not have a valid longitude') do
20
20
  @point.longitude = RCAP::CAP_1_0::Point::MAX_LONGITUDE + 1
21
- @point.should_not( be_valid )
21
+ @point.should_not(be_valid)
22
22
  @point.longitude = RCAP::CAP_1_0::Point::MIN_LONGITUDE - 1
23
- @point.should_not( be_valid )
23
+ @point.should_not(be_valid)
24
24
  end
25
25
 
26
- it( 'does not have a lattitude defined' ) do
26
+ it('does not have a lattitude defined') do
27
27
  @point.lattitude = nil
28
- @point.should_not( be_valid )
28
+ @point.should_not(be_valid)
29
29
  end
30
30
 
31
- it( 'does not have a valid lattitude' ) do
31
+ it('does not have a valid lattitude') do
32
32
  @point.lattitude = RCAP::CAP_1_0::Point::MAX_LATTITUDE + 1
33
- @point.should_not( be_valid )
33
+ @point.should_not(be_valid)
34
34
  @point.lattitude = RCAP::CAP_1_0::Point::MIN_LATTITUDE - 1
35
- @point.should_not( be_valid )
35
+ @point.should_not(be_valid)
36
36
  end
37
37
  end
38
38
 
39
- context( 'when exported' ) do
40
- before( :each ) do
39
+ context('when exported') do
40
+ before(:each) do
41
41
  @point = RCAP::CAP_1_0::Point.new do |p|
42
42
  p.lattitude = 1
43
43
  p.longitude = 1
44
44
  end
45
45
  end
46
46
 
47
- context( 'to hash' ) do
48
- it( 'should export correctly' ) do
47
+ context('to hash') do
48
+ it('should export correctly') do
49
49
  @point.to_h.should == { RCAP::CAP_1_0::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_0::Point::LONGITUDE_KEY => 1 }
50
50
  end
51
51
  end
@@ -1,33 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Polygon ) do
4
- describe( 'is not valid if it' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Polygon) do
4
+ describe('is not valid if it') do
5
+ before(:each) do
6
6
  @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
7
- [1,2,1].each do |i|
7
+ [1, 2, 1].each do |i|
8
8
  polygon.add_point do |point|
9
9
  point.lattitude = i
10
10
  point.longitude = i
11
11
  end
12
12
  end
13
13
  end
14
- @polygon.should( be_valid )
14
+ @polygon.should(be_valid)
15
15
  end
16
16
 
17
- it( 'does not have any points' ) do
18
- @polygon.points.clear
19
- @polygon.should_not( be_valid )
20
- end
21
-
22
- it( 'does not have a valid collection of points' ) do
17
+ it('does not have a valid collection of points') do
23
18
  @polygon.points.first.lattitude = nil
24
- @polygon.should_not( be_valid )
19
+ @polygon.should_not(be_valid)
25
20
  end
26
21
  end
27
22
 
28
- context( 'on initialization' ) do
29
- context( 'from XML' ) do
30
- before( :each ) do
23
+ context('on initialization') do
24
+ context('from XML') do
25
+ before(:each) do
31
26
  @original_polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
32
27
  3.times do |i|
33
28
  polygon.add_point do |point|
@@ -36,11 +31,11 @@ describe( RCAP::CAP_1_0::Polygon ) do
36
31
  end
37
32
  end
38
33
  end
39
- @empty_original_polygon = RCAP::CAP_1_0::Polygon.new()
34
+ @empty_original_polygon = RCAP::CAP_1_0::Polygon.new
40
35
  @alert = RCAP::CAP_1_0::Alert.new
41
36
  @alert.add_info do |info|
42
37
  info.add_area do |area|
43
- [ @original_polygon, @empty_original_polygon ].each do |original_polygon|
38
+ [@original_polygon, @empty_original_polygon].each do |original_polygon|
44
39
  area.add_polygon do |polygon|
45
40
  original_polygon.points.each do |original_point|
46
41
  polygon.add_point do |point|
@@ -54,29 +49,29 @@ describe( RCAP::CAP_1_0::Polygon ) do
54
49
  end
55
50
 
56
51
  @xml_string = @alert.to_xml
57
- @xml_document = REXML::Document.new( @xml_string )
58
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
59
- @area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
60
- @polygon_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
61
- @polygon = RCAP::CAP_1_0::Polygon.from_xml_element( @polygon_element )
52
+ @xml_document = REXML::Document.new(@xml_string)
53
+ @info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
54
+ @area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
55
+ @polygon_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
56
+ @polygon = RCAP::CAP_1_0::Polygon.from_xml_element(@polygon_element)
62
57
  end
63
58
 
64
- it( 'should parse all the points' ) do
65
- @polygon.points.zip( @original_polygon.points ).each do |point, original_point|
59
+ it('should parse all the points') do
60
+ @polygon.points.zip(@original_polygon.points).each do |point, original_point|
66
61
  point.lattitude.should == original_point.lattitude
67
62
  point.longitude.should == original_point.longitude
68
63
  end
69
64
  end
70
65
 
71
66
  it 'should allow empty polygon xml elements' do
72
- empty_polygon_element = RCAP.xpath_match( @area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS )[1]
73
- empty_polygon = RCAP::CAP_1_0::Polygon.from_xml_element( empty_polygon_element )
67
+ empty_polygon_element = RCAP.xpath_match(@area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS)[1]
68
+ empty_polygon = RCAP::CAP_1_0::Polygon.from_xml_element(empty_polygon_element)
74
69
  empty_polygon.should == @empty_original_polygon
75
70
  end
76
71
  end
77
72
 
78
- context( 'from a hash' ) do
79
- before( :each ) do
73
+ context('from a hash') do
74
+ before(:each) do
80
75
  @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
81
76
  3.times do |i|
82
77
  polygon.add_point do |point|
@@ -87,15 +82,15 @@ describe( RCAP::CAP_1_0::Polygon ) do
87
82
  end
88
83
  end
89
84
 
90
- it( 'should load all the points' ) do
91
- @new_polygon = RCAP::CAP_1_0::Polygon.from_h( @polygon.to_h )
85
+ it('should load all the points') do
86
+ @new_polygon = RCAP::CAP_1_0::Polygon.from_h(@polygon.to_h)
92
87
  @new_polygon.points.should == @polygon.points
93
88
  end
94
89
  end
95
90
  end
96
91
 
97
- context( 'when exported' ) do
98
- before( :each ) do
92
+ context('when exported') do
93
+ before(:each) do
99
94
  @polygon = RCAP::CAP_1_0::Polygon.new do |polygon|
100
95
  3.times do |i|
101
96
  polygon.add_point do |point|
@@ -106,33 +101,40 @@ describe( RCAP::CAP_1_0::Polygon ) do
106
101
  end
107
102
  end
108
103
 
109
- context( 'to a hash' ) do
110
- it( 'should export correctly' ) do
111
- @polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_a }}
104
+ context('to geojson') do
105
+ it('should be valid geojson') do
106
+ expected = '{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2]]]}'
107
+ expect(@polygon.to_geojson).to eq expected
108
+ end
109
+ end
110
+
111
+ context('to a hash') do
112
+ it('should export correctly') do
113
+ @polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
112
114
  end
113
115
  end
114
116
  end
115
117
 
116
- describe( 'instance methods' ) do
117
- before( :each ) do
118
+ describe('instance methods') do
119
+ before(:each) do
118
120
  @polygon = RCAP::CAP_1_0::Polygon.new
119
121
  end
120
122
 
121
- describe( '#add_point' ) do
122
- before( :each ) do
123
+ describe('#add_point') do
124
+ before(:each) do
123
125
  @point = @polygon.add_point do |polygon|
124
126
  polygon.lattitude = 1
125
127
  polygon.longitude = 1
126
128
  end
127
129
  end
128
130
 
129
- it( 'should return a 1.0 Point' ) do
131
+ it('should return a 1.0 Point') do
130
132
  @point.class.should == RCAP::CAP_1_0::Point
131
133
  @point.lattitude.should == 1
132
134
  @point.longitude.should == 1
133
135
  end
134
136
 
135
- it( 'should add a Point to the points attribute' ) do
137
+ it('should add a Point to the points attribute') do
136
138
  @polygon.points.size.should == 1
137
139
  end
138
140
  end
@@ -1,152 +1,151 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Resource ) do
4
- context( 'on initialisation' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Resource) do
4
+ context('on initialisation') do
5
+ before(:each) do
6
6
  @resource = RCAP::CAP_1_0::Resource.new
7
7
  end
8
8
 
9
- it( 'should have no mime_type' ){ @resource.mime_type.should( be_nil )}
10
- it( 'should have no size' ){ @resource.size.should( be_nil )}
11
- it( 'should have no uri' ){ @resource.uri.should( be_nil )}
12
- it( 'should have no digest' ){ @resource.digest.should( be_nil )}
13
- it( 'should have no resource_desc' ){ @resource.resource_desc.should( be_nil )}
9
+ it('should have no mime_type') { @resource.mime_type.should(be_nil) }
10
+ it('should have no size') { @resource.size.should(be_nil) }
11
+ it('should have no uri') { @resource.uri.should(be_nil) }
12
+ it('should have no digest') { @resource.digest.should(be_nil) }
13
+ it('should have no resource_desc') { @resource.resource_desc.should(be_nil) }
14
14
 
15
- context( 'from XML' ) do
16
- before( :each ) do
15
+ context('from XML') do
16
+ before(:each) do
17
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"
18
+ resource.resource_desc = 'Image of incident'
19
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
20
20
  resource.mime_type = 'image/png'
21
- resource.size = 20480
22
- resource.digest = "2048"
21
+ resource.size = 20_480
22
+ resource.digest = '2048'
23
23
  end
24
24
 
25
25
  @alert = RCAP::CAP_1_0::Alert.new
26
26
  @alert.add_info.resources << @original_resource
27
27
  @xml_string = @alert.to_xml
28
- @xml_document = REXML::Document.new( @xml_string )
29
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
30
- @resource_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_0::Resource::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
31
- @resource_element.should_not( be_nil )
32
- @resource = RCAP::CAP_1_0::Resource.from_xml_element( @resource_element )
28
+ @xml_document = REXML::Document.new(@xml_string)
29
+ @info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
30
+ @resource_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_0::Resource::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
31
+ @resource_element.should_not(be_nil)
32
+ @resource = RCAP::CAP_1_0::Resource.from_xml_element(@resource_element)
33
33
  end
34
34
 
35
- it( 'should parse resource_desc correctly' ) do
35
+ it('should parse resource_desc correctly') do
36
36
  @resource.resource_desc.should == @original_resource.resource_desc
37
37
  end
38
38
 
39
- it( 'should parse uri correctly' ) do
39
+ it('should parse uri correctly') do
40
40
  @resource.uri.should == @original_resource.uri
41
41
  end
42
42
 
43
- it( 'should parse mime_type correctly' ) do
43
+ it('should parse mime_type correctly') do
44
44
  @resource.mime_type.should == @original_resource.mime_type
45
45
  end
46
46
 
47
- it( 'should parse size correctly' ) do
47
+ it('should parse size correctly') do
48
48
  @resource.size.should == @original_resource.size
49
49
  end
50
50
 
51
- it( 'should parse digest correctly' ) do
51
+ it('should parse digest correctly') do
52
52
  @resource.digest.should == @original_resource.digest
53
53
  end
54
54
  end
55
55
 
56
-
57
- context( 'from a hash' ) do
58
- before( :each ) do
56
+ context('from a hash') do
57
+ before(:each) do
59
58
  @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"
59
+ resource.resource_desc = 'Image of incident'
60
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
62
61
  resource.mime_type = 'image/png'
63
- resource.size = 20480
64
- resource.digest = "2048"
62
+ resource.size = 20_480
63
+ resource.digest = '2048'
65
64
  end
66
65
 
67
- @resource = RCAP::CAP_1_0::Resource.from_h( @original_resource.to_h )
66
+ @resource = RCAP::CAP_1_0::Resource.from_h(@original_resource.to_h)
68
67
  end
69
68
 
70
- it( 'should parse resource_desc correctly' ) do
69
+ it('should parse resource_desc correctly') do
71
70
  @resource.resource_desc.should == @original_resource.resource_desc
72
71
  end
73
72
 
74
- it( 'should parse uri correctly' ) do
73
+ it('should parse uri correctly') do
75
74
  @resource.uri.should == @original_resource.uri
76
75
  end
77
76
 
78
- it( 'should parse mime_type correctly' ) do
77
+ it('should parse mime_type correctly') do
79
78
  @resource.mime_type.should == @original_resource.mime_type
80
79
  end
81
80
 
82
- it( 'should parse size correctly' ) do
81
+ it('should parse size correctly') do
83
82
  @resource.size.should == @original_resource.size
84
83
  end
85
84
 
86
- it( 'should parse digest correctly' ) do
85
+ it('should parse digest correctly') do
87
86
  @resource.digest.should == @original_resource.digest
88
87
  end
89
88
  end
90
89
 
91
90
  end
92
91
 
93
- context( 'when exported' ) do
94
- before( :each ) do
92
+ context('when exported') do
93
+ before(:each) do
95
94
  @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"
95
+ resource.resource_desc = 'Image of incident'
96
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
98
97
  resource.mime_type = 'image/png'
99
- resource.size = 20480
100
- resource.digest = "2048"
98
+ resource.size = 20_480
99
+ resource.digest = '2048'
101
100
  end
102
101
  end
103
102
 
104
- context( 'to a hash' ) do
105
- before( :each ) do
103
+ context('to a hash') do
104
+ before(:each) do
106
105
  @resource_hash = @resource.to_h
107
106
  end
108
107
 
109
- it( 'should set the resource description' ) do
110
- @resource_hash[ RCAP::CAP_1_0::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
108
+ it('should set the resource description') do
109
+ @resource_hash[ RCAP::CAP_1_0::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
111
110
  end
112
111
 
113
- it( 'should set the mime type' ) do
114
- @resource_hash[ RCAP::CAP_1_0::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
112
+ it('should set the mime type') do
113
+ @resource_hash[ RCAP::CAP_1_0::Resource::MIME_TYPE_KEY].should == @resource.mime_type
115
114
  end
116
115
 
117
- it( 'should set the size' ) do
118
- @resource_hash[ RCAP::CAP_1_0::Resource::SIZE_KEY ].should == @resource.size
116
+ it('should set the size') do
117
+ @resource_hash[ RCAP::CAP_1_0::Resource::SIZE_KEY].should == @resource.size
119
118
  end
120
119
 
121
- it( 'should set the URI' ) do
122
- @resource_hash[ RCAP::CAP_1_0::Resource::URI_KEY ].should == @resource.uri
120
+ it('should set the URI') do
121
+ @resource_hash[ RCAP::CAP_1_0::Resource::URI_KEY].should == @resource.uri
123
122
  end
124
123
 
125
- it( 'should set the digest' ) do
126
- @resource_hash[ RCAP::CAP_1_0::Resource::DIGEST_KEY ].should == @resource.digest
124
+ it('should set the digest') do
125
+ @resource_hash[ RCAP::CAP_1_0::Resource::DIGEST_KEY].should == @resource.digest
127
126
  end
128
127
  end
129
128
 
130
- context( 'to xml' ) do
131
- it( 'should be successful' ) do
132
- lambda{ @resource_xml = @resource.to_xml }.should_not( raise_exception )
129
+ context('to xml') do
130
+ it('should be successful') do
131
+ lambda { @resource_xml = @resource.to_xml }.should_not(raise_exception)
133
132
  end
134
133
  end
135
134
  end
136
135
 
137
- context( 'which is valid' ) do
138
- before( :each ) do
136
+ context('which is valid') do
137
+ before(:each) do
139
138
  @resource = RCAP::CAP_1_0::Resource.new do |resource|
140
139
  resource.resource_desc = 'Resource Description'
141
140
  end
142
141
 
143
- @resource.should( be_valid )
142
+ @resource.should(be_valid)
144
143
  end
145
144
 
146
- describe( 'should not be valid if it' ) do
147
- it( 'does not have a resource description (resource_desc)' ) do
145
+ describe('should not be valid if it') do
146
+ it('does not have a resource description (resource_desc)') do
148
147
  @resource.resource_desc = nil
149
- @resource.should_not( be_valid )
148
+ @resource.should_not(be_valid)
150
149
  end
151
150
  end
152
151
  end