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_1::Parameter ) do
4
- context( 'when initialised' ) do
5
- context( 'from XML' ) do
6
- before( :each ) do
3
+ describe(RCAP::CAP_1_1::Parameter) do
4
+ context('when initialised') do
5
+ context('from XML') do
6
+ before(:each) do
7
7
 
8
8
  @alert = RCAP::CAP_1_1::Alert.new do |alert|
9
9
  alert.add_info.add_parameter do |parameter|
@@ -13,36 +13,36 @@ describe( RCAP::CAP_1_1::Parameter ) do
13
13
  end
14
14
  @original_parameter = @alert.infos.first.parameters.first
15
15
  @xml_string = @alert.to_xml
16
- @xml_document = REXML::Document.new( @xml_string )
17
- @info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
18
- @parameter_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_1::Parameter::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
19
- @parameter = RCAP::CAP_1_1::Parameter.from_xml_element( @parameter_xml_element )
16
+ @xml_document = REXML::Document.new(@xml_string)
17
+ @info_xml_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
18
+ @parameter_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_1::Parameter::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
19
+ @parameter = RCAP::CAP_1_1::Parameter.from_xml_element(@parameter_xml_element)
20
20
  end
21
21
 
22
- it( 'should parse into the correct class' ) do
22
+ it('should parse into the correct class') do
23
23
  @parameter.class.should == RCAP::CAP_1_1::Parameter
24
24
  end
25
25
 
26
- it( 'should parse the name correctly' ) do
26
+ it('should parse the name correctly') do
27
27
  @parameter.name.should == @original_parameter.name
28
28
  end
29
29
 
30
- it( 'should parse the value correctly' ) do
30
+ it('should parse the value correctly') do
31
31
  @parameter.value.should == @original_parameter.value
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
- context( 'when exported' ) do
37
- before( :each ) do
36
+ context('when exported') do
37
+ before(:each) do
38
38
  @parameter = RCAP::CAP_1_1::Parameter.new do |parameter|
39
- parameter.name = 'name'
40
- parameter.value = 'value'
39
+ parameter.name = 'name'
40
+ parameter.value = 'value'
41
41
  end
42
42
  end
43
43
 
44
- context( 'to a hash' ) do
45
- it( 'should export correctly' ) do
44
+ context('to a hash') do
45
+ it('should export correctly') do
46
46
  @parameter.to_h.should == { 'name' => 'value' }
47
47
  end
48
48
  end
@@ -1,50 +1,50 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_1::Point ) do
4
- describe( 'is not valid if' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_1::Point) do
4
+ describe('is not valid if') do
5
+ before(:each) do
6
6
  @point = RCAP::CAP_1_1::Point.new do |point|
7
7
  point.lattitude = 0
8
8
  point.longitude = 0
9
9
  end
10
- @point.should( be_valid )
10
+ @point.should(be_valid)
11
11
  end
12
12
 
13
- it( 'does not have a longitude defined' ) do
13
+ it('does not have a longitude defined') do
14
14
  @point.longitude = nil
15
- @point.should_not( be_valid )
15
+ @point.should_not(be_valid)
16
16
  end
17
17
 
18
- it( 'does not have a valid longitude' ) do
18
+ it('does not have a valid longitude') do
19
19
  @point.longitude = RCAP::CAP_1_1::Point::MAX_LONGITUDE + 1
20
- @point.should_not( be_valid )
20
+ @point.should_not(be_valid)
21
21
  @point.longitude = RCAP::CAP_1_1::Point::MIN_LONGITUDE - 1
22
- @point.should_not( be_valid )
22
+ @point.should_not(be_valid)
23
23
  end
24
24
 
25
- it( 'does not have a lattitude defined' ) do
25
+ it('does not have a lattitude defined') do
26
26
  @point.lattitude = nil
27
- @point.should_not( be_valid )
27
+ @point.should_not(be_valid)
28
28
  end
29
29
 
30
- it( 'does not have a valid lattitude' ) do
30
+ it('does not have a valid lattitude') do
31
31
  @point.lattitude = RCAP::CAP_1_1::Point::MAX_LATTITUDE + 1
32
- @point.should_not( be_valid )
32
+ @point.should_not(be_valid)
33
33
  @point.lattitude = RCAP::CAP_1_1::Point::MIN_LATTITUDE - 1
34
- @point.should_not( be_valid )
34
+ @point.should_not(be_valid)
35
35
  end
36
36
  end
37
37
 
38
- context( 'when exported' ) do
39
- before( :each ) do
38
+ context('when exported') do
39
+ before(:each) do
40
40
  @point = RCAP::CAP_1_1::Point.new do |point|
41
41
  point.lattitude = 1
42
42
  point.longitude = 1
43
43
  end
44
44
  end
45
45
 
46
- context( 'to hash' ) do
47
- it( 'should export correctly' ) do
46
+ context('to hash') do
47
+ it('should export correctly') do
48
48
  @point.to_h.should == { RCAP::CAP_1_1::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_1::Point::LONGITUDE_KEY => 1 }
49
49
  end
50
50
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_1::Polygon ) do
4
- describe( 'is not valid if it' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_1::Polygon) do
4
+ describe('is not valid if it') do
5
+ before(:each) do
6
6
  @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
7
7
  3.times do
8
8
  polygon.add_point do |point|
@@ -10,24 +10,19 @@ describe( RCAP::CAP_1_1::Polygon ) do
10
10
  point.longitude = 0
11
11
  end
12
12
  end
13
- @polygon.should( be_valid )
14
- end
15
-
16
- it( 'does not have any points' ) do
17
- @polygon.points.clear
18
- @polygon.should_not( be_valid )
19
13
  end
14
+ @polygon.should(be_valid)
15
+ end
20
16
 
21
- it( 'does not have a valid collection of points' ) do
22
- @polygon.points.first.lattitude = nil
23
- @polygon.should_not( be_valid )
24
- end
17
+ it('does not have a valid collection of points') do
18
+ @polygon.points.first.lattitude = nil
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_1::Polygon.new do |polygon|
32
27
  3.times do |i|
33
28
  polygon.add_point do |point|
@@ -36,7 +31,7 @@ describe( RCAP::CAP_1_1::Polygon ) do
36
31
  end
37
32
  end
38
33
  end
39
- @empty_original_polygon = RCAP::CAP_1_1::Polygon.new()
34
+ @empty_original_polygon = RCAP::CAP_1_1::Polygon.new
40
35
  @alert = RCAP::CAP_1_1::Alert.new
41
36
  @alert.add_info.add_area do |area|
42
37
  area.add_polygon do |polygon|
@@ -50,29 +45,29 @@ describe( RCAP::CAP_1_1::Polygon ) do
50
45
  area.add_polygon
51
46
  end
52
47
  @xml_string = @alert.to_xml
53
- @xml_document = REXML::Document.new( @xml_string )
54
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
55
- @area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
56
- @polygon_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
57
- @polygon = RCAP::CAP_1_1::Polygon.from_xml_element( @polygon_element )
48
+ @xml_document = REXML::Document.new(@xml_string)
49
+ @info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
50
+ @area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
51
+ @polygon_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
52
+ @polygon = RCAP::CAP_1_1::Polygon.from_xml_element(@polygon_element)
58
53
  end
59
54
 
60
- it( 'should parse all the points' ) do
61
- @polygon.points.zip( @original_polygon.points ).each do |point, original_point|
55
+ it('should parse all the points') do
56
+ @polygon.points.zip(@original_polygon.points).each do |point, original_point|
62
57
  point.lattitude.should == original_point.lattitude
63
58
  point.longitude.should == original_point.longitude
64
59
  end
65
60
  end
66
61
 
67
62
  it 'should allow empty polygon xml elements' do
68
- empty_polygon_element = RCAP.xpath_match( @area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS )[1]
69
- empty_polygon = RCAP::CAP_1_1::Polygon.from_xml_element( empty_polygon_element )
63
+ empty_polygon_element = RCAP.xpath_match(@area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS)[1]
64
+ empty_polygon = RCAP::CAP_1_1::Polygon.from_xml_element(empty_polygon_element)
70
65
  empty_polygon.should == @empty_original_polygon
71
66
  end
72
67
  end
73
68
 
74
- context( 'from a hash' ) do
75
- before( :each ) do
69
+ context('from a hash') do
70
+ before(:each) do
76
71
  @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
77
72
  3.times do |i|
78
73
  polygon.add_point do |point|
@@ -83,15 +78,15 @@ describe( RCAP::CAP_1_1::Polygon ) do
83
78
  end
84
79
  end
85
80
 
86
- it( 'should load all the points' ) do
87
- @new_polygon = RCAP::CAP_1_1::Polygon.from_h( @polygon.to_h )
81
+ it('should load all the points') do
82
+ @new_polygon = RCAP::CAP_1_1::Polygon.from_h(@polygon.to_h)
88
83
  @new_polygon.points.should == @polygon.points
89
84
  end
90
85
  end
91
86
  end
92
87
 
93
- context( 'when exported' ) do
94
- before( :each ) do
88
+ context('when exported') do
89
+ before(:each) do
95
90
  @polygon = RCAP::CAP_1_1::Polygon.new do |polygon|
96
91
  3.times do |i|
97
92
  polygon.add_point do |point|
@@ -102,33 +97,40 @@ describe( RCAP::CAP_1_1::Polygon ) do
102
97
  end
103
98
  end
104
99
 
105
- context( 'to a hash' ) do
106
- it( 'should export correctly' ) do
107
- @polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_a }}
100
+ context('to geojson') do
101
+ it('should be valid geojson') do
102
+ expected = '{"type":"Polygon","coordinates":[[[0,0],[1,1],[2,2]]]}'
103
+ expect(@polygon.to_geojson).to eq expected
104
+ end
105
+ end
106
+
107
+ context('to a hash') do
108
+ it('should export correctly') do
109
+ @polygon.to_h.should == { RCAP::CAP_1_1::Polygon::POINTS_KEY => @polygon.points.map { |point| point.to_a } }
108
110
  end
109
111
  end
110
112
  end
111
113
 
112
- describe( 'instance methods' ) do
113
- before( :each ) do
114
+ describe('instance methods') do
115
+ before(:each) do
114
116
  @polygon = RCAP::CAP_1_1::Polygon.new
115
117
  end
116
118
 
117
- describe( '#add_point' ) do
118
- before( :each ) do
119
+ describe('#add_point') do
120
+ before(:each) do
119
121
  @point = @polygon.add_point do |point|
120
122
  point.lattitude = 1
121
123
  point.longitude = 1
122
124
  end
123
125
  end
124
126
 
125
- it( 'should return a 1.1 Point' ) do
127
+ it('should return a 1.1 Point') do
126
128
  @point.class.should == RCAP::CAP_1_1::Point
127
129
  @point.lattitude.should == 1
128
130
  @point.longitude.should == 1
129
131
  end
130
132
 
131
- it( 'should add a Point to the points attribute' ) do
133
+ it('should add a Point to the points attribute') do
132
134
  @polygon.points.size.should == 1
133
135
  end
134
136
  end
@@ -1,237 +1,236 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_1::Resource ) do
4
- context( 'on initialisation' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_1::Resource) do
4
+ context('on initialisation') do
5
+ before(:each) do
6
6
  @resource = RCAP::CAP_1_1::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 deref_uri' ){ @resource.deref_uri.should( be_nil )}
13
- it( 'should have no digest' ){ @resource.digest.should( be_nil )}
14
- 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 deref_uri') { @resource.deref_uri.should(be_nil) }
13
+ it('should have no digest') { @resource.digest.should(be_nil) }
14
+ it('should have no resource_desc') { @resource.resource_desc.should(be_nil) }
15
15
 
16
- context( 'from XML' ) do
17
- before( :each ) do
16
+ context('from XML') do
17
+ before(:each) do
18
18
  @alert = RCAP::CAP_1_1::Alert.new
19
19
  @alert.add_info.add_resource do |resource|
20
- resource.resource_desc = "Image of incident"
21
- resource.uri = "http://capetown.gov.za/cap/resources/image.png"
20
+ resource.resource_desc = 'Image of incident'
21
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
22
22
  resource.mime_type = 'image/png'
23
- resource.deref_uri = "IMAGE DATA"
24
- resource.size = 20480
25
- resource.digest = "2048"
23
+ resource.deref_uri = 'IMAGE DATA'
24
+ resource.size = 20_480
25
+ resource.digest = '2048'
26
26
  end
27
27
  @original_resource = @alert.infos.first.resources.first
28
28
  @xml_string = @alert.to_xml
29
- @xml_document = REXML::Document.new( @xml_string )
30
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
31
- @resource_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_1::Resource::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
32
- @resource_element.should_not( be_nil )
33
- @resource = RCAP::CAP_1_1::Resource.from_xml_element( @resource_element )
29
+ @xml_document = REXML::Document.new(@xml_string)
30
+ @info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
31
+ @resource_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_1::Resource::XPATH, RCAP::CAP_1_1::Alert::XMLNS)
32
+ @resource_element.should_not(be_nil)
33
+ @resource = RCAP::CAP_1_1::Resource.from_xml_element(@resource_element)
34
34
  end
35
35
 
36
- it( 'should parse resource_desc correctly' ) do
36
+ it('should parse resource_desc correctly') do
37
37
  @resource.resource_desc.should == @original_resource.resource_desc
38
38
  end
39
39
 
40
- it( 'should parse uri correctly' ) do
40
+ it('should parse uri correctly') do
41
41
  @resource.uri.should == @original_resource.uri
42
42
  end
43
43
 
44
- it( 'should parse mime_type correctly' ) do
44
+ it('should parse mime_type correctly') do
45
45
  @resource.mime_type.should == @original_resource.mime_type
46
46
  end
47
47
 
48
- it( 'should parse deref_uri correctly' ) do
48
+ it('should parse deref_uri correctly') do
49
49
  @resource.deref_uri.should == @original_resource.deref_uri
50
50
  end
51
51
 
52
- it( 'should parse size correctly' ) do
52
+ it('should parse size correctly') do
53
53
  @resource.size.should == @original_resource.size
54
54
  end
55
55
 
56
- it( 'should parse digest correctly' ) do
56
+ it('should parse digest correctly') do
57
57
  @resource.digest.should == @original_resource.digest
58
58
  end
59
59
  end
60
60
 
61
-
62
- context( 'from a hash' ) do
63
- before( :each ) do
61
+ context('from a hash') do
62
+ before(:each) do
64
63
  @original_resource = RCAP::CAP_1_1::Resource.new do |resource|
65
- resource.resource_desc = "Image of incident"
66
- resource.uri = "http://capetown.gov.za/cap/resources/image.png"
64
+ resource.resource_desc = 'Image of incident'
65
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
67
66
  resource.mime_type = 'image/png'
68
- resource.deref_uri = "IMAGE DATA"
69
- resource.size = 20480
70
- resource.digest = "2048"
67
+ resource.deref_uri = 'IMAGE DATA'
68
+ resource.size = 20_480
69
+ resource.digest = '2048'
71
70
  end
72
71
 
73
- @resource = RCAP::CAP_1_1::Resource.from_h( @original_resource.to_h )
72
+ @resource = RCAP::CAP_1_1::Resource.from_h(@original_resource.to_h)
74
73
  end
75
74
 
76
- it( 'should parse resource_desc correctly' ) do
75
+ it('should parse resource_desc correctly') do
77
76
  @resource.resource_desc.should == @original_resource.resource_desc
78
77
  end
79
78
 
80
- it( 'should parse uri correctly' ) do
79
+ it('should parse uri correctly') do
81
80
  @resource.uri.should == @original_resource.uri
82
81
  end
83
82
 
84
- it( 'should parse mime_type correctly' ) do
83
+ it('should parse mime_type correctly') do
85
84
  @resource.mime_type.should == @original_resource.mime_type
86
85
  end
87
86
 
88
- it( 'should parse deref_uri correctly' ) do
87
+ it('should parse deref_uri correctly') do
89
88
  @resource.deref_uri.should == @original_resource.deref_uri
90
89
  end
91
90
 
92
- it( 'should parse size correctly' ) do
91
+ it('should parse size correctly') do
93
92
  @resource.size.should == @original_resource.size
94
93
  end
95
94
 
96
- it( 'should parse digest correctly' ) do
95
+ it('should parse digest correctly') do
97
96
  @resource.digest.should == @original_resource.digest
98
97
  end
99
98
  end
100
99
 
101
- context( 'from YAML' ) do
102
- before( :each ) do
100
+ context('from YAML') do
101
+ before(:each) do
103
102
  @original_resource = RCAP::CAP_1_1::Resource.new do |resource|
104
- resource.resource_desc = "Image of incident"
105
- resource.uri = "http://capetown.gov.za/cap/resources/image.png"
103
+ resource.resource_desc = 'Image of incident'
104
+ resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
106
105
  resource.mime_type = 'image/png'
107
- resource.deref_uri = "IMAGE DATA"
108
- resource.size = 20480
109
- resource.digest = "2048"
106
+ resource.deref_uri = 'IMAGE DATA'
107
+ resource.size = 20_480
108
+ resource.digest = '2048'
110
109
  end
111
- @resource = RCAP::CAP_1_1::Resource.from_yaml_data( YAML.load( @original_resource.to_yaml ))
110
+ @resource = RCAP::CAP_1_1::Resource.from_yaml_data(YAML.load(@original_resource.to_yaml))
112
111
  end
113
112
 
114
- it( 'should parse resource_desc correctly' ) do
113
+ it('should parse resource_desc correctly') do
115
114
  @resource.resource_desc.should == @original_resource.resource_desc
116
115
  end
117
116
 
118
- it( 'should parse uri correctly' ) do
117
+ it('should parse uri correctly') do
119
118
  @resource.uri.should == @original_resource.uri
120
119
  end
121
120
 
122
- it( 'should parse mime_type correctly' ) do
121
+ it('should parse mime_type correctly') do
123
122
  @resource.mime_type.should == @original_resource.mime_type
124
123
  end
125
124
 
126
- it( 'should parse deref_uri correctly' ) do
125
+ it('should parse deref_uri correctly') do
127
126
  @resource.deref_uri.should == @original_resource.deref_uri
128
127
  end
129
128
 
130
- it( 'should parse size correctly' ) do
129
+ it('should parse size correctly') do
131
130
  @resource.size.should == @original_resource.size
132
131
  end
133
132
 
134
- it( 'should parse digest correctly' ) do
133
+ it('should parse digest correctly') do
135
134
  @resource.digest.should == @original_resource.digest
136
135
  end
137
136
  end
138
137
  end
139
138
 
140
- context( 'when exported' ) do
141
- before( :each ) do
139
+ context('when exported') do
140
+ before(:each) do
142
141
  @resource = RCAP::CAP_1_1::Resource.new
143
- @resource.resource_desc = "Image of incident"
144
- @resource.uri = "http://capetown.gov.za/cap/resources/image.png"
142
+ @resource.resource_desc = 'Image of incident'
143
+ @resource.uri = 'http://capetown.gov.za/cap/resources/image.png'
145
144
  @resource.mime_type = 'image/png'
146
- @resource.deref_uri = "IMAGE DATA"
147
- @resource.size = 20480
148
- @resource.digest = "2048"
145
+ @resource.deref_uri = 'IMAGE DATA'
146
+ @resource.size = 20_480
147
+ @resource.digest = '2048'
149
148
  end
150
149
 
151
- context( 'to a hash' ) do
152
- before( :each ) do
150
+ context('to a hash') do
151
+ before(:each) do
153
152
  @resource_hash = @resource.to_h
154
153
  end
155
154
 
156
- it( 'should set the resource description' ) do
157
- @resource_hash[ RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
155
+ it('should set the resource description') do
156
+ @resource_hash[ RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY].should == @resource.resource_desc
158
157
  end
159
158
 
160
- it( 'should set the mime type' ) do
161
- @resource_hash[ RCAP::CAP_1_1::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
159
+ it('should set the mime type') do
160
+ @resource_hash[ RCAP::CAP_1_1::Resource::MIME_TYPE_KEY].should == @resource.mime_type
162
161
  end
163
162
 
164
- it( 'should set the size' ) do
165
- @resource_hash[ RCAP::CAP_1_1::Resource::SIZE_KEY ].should == @resource.size
163
+ it('should set the size') do
164
+ @resource_hash[ RCAP::CAP_1_1::Resource::SIZE_KEY].should == @resource.size
166
165
  end
167
166
 
168
- it( 'should set the URI' ) do
169
- @resource_hash[ RCAP::CAP_1_1::Resource::URI_KEY ].should == @resource.uri
167
+ it('should set the URI') do
168
+ @resource_hash[ RCAP::CAP_1_1::Resource::URI_KEY].should == @resource.uri
170
169
  end
171
170
 
172
- it( 'should set the dereferenced URI' ) do
173
- @resource_hash[ RCAP::CAP_1_1::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
171
+ it('should set the dereferenced URI') do
172
+ @resource_hash[ RCAP::CAP_1_1::Resource::DEREF_URI_KEY].should == @resource.deref_uri
174
173
  end
175
174
 
176
- it( 'should set the digest' ) do
177
- @resource_hash[ RCAP::CAP_1_1::Resource::DIGEST_KEY ].should == @resource.digest
175
+ it('should set the digest') do
176
+ @resource_hash[ RCAP::CAP_1_1::Resource::DIGEST_KEY].should == @resource.digest
178
177
  end
179
178
  end
180
179
 
181
- context( 'to xml' ) do
182
- it( 'should be successful' ) do
183
- lambda{ @resource_xml = @resource.to_xml }.should_not( raise_exception )
180
+ context('to xml') do
181
+ it('should be successful') do
182
+ lambda { @resource_xml = @resource.to_xml }.should_not(raise_exception)
184
183
  end
185
184
  end
186
185
  end
187
186
 
188
- context( 'which is valid' ) do
189
- before( :each ) do
187
+ context('which is valid') do
188
+ before(:each) do
190
189
  @resource = RCAP::CAP_1_1::Resource.new do |resource|
191
190
  resource.resource_desc = 'Resource Description'
192
191
  end
193
- @resource.should( be_valid )
192
+ @resource.should(be_valid)
194
193
  end
195
194
 
196
- describe( 'should not be valid if it' ) do
197
- it( 'does not have a resource description (resource_desc)' ) do
195
+ describe('should not be valid if it') do
196
+ it('does not have a resource description (resource_desc)') do
198
197
  @resource.resource_desc = nil
199
- @resource.should_not( be_valid )
198
+ @resource.should_not(be_valid)
200
199
  end
201
200
  end
202
201
  end
203
202
 
204
- context( 'with a non-rereferenced URI' ) do
205
- before( :each ) do
203
+ context('with a non-rereferenced URI') do
204
+ before(:each) do
206
205
  @resource = RCAP::CAP_1_1::Resource.new do |resource|
207
206
  resource.resource_desc = 'Resource Description'
208
207
  resource.mime_type = 'text/csv'
209
208
  resource.uri = 'http://tempuri.org/resource.csv'
210
209
  end
211
210
  @content = "1,2\n3,4"
212
- @encoded_content = Base64.encode64( @content )
213
- stub_request( :get, @resource.uri ).to_return( :status => 200, :body => @content )
211
+ @encoded_content = Base64.encode64(@content)
212
+ expect(URI).to receive(:parse) { StringIO.new(@content) }
214
213
  end
215
214
 
216
- describe( '#dereference_uri!' ) do
217
- it( 'should fetch the content and store it in deref_uri as Base64 encoded content' ) do
218
- lambda{ @resource.dereference_uri! }.should( change( @resource, :deref_uri ).to( @encoded_content ))
215
+ describe('#dereference_uri!') do
216
+ it('should fetch the content and store it in deref_uri as Base64 encoded content') do
217
+ lambda { @resource.dereference_uri! }.should(change(@resource, :deref_uri).to(@encoded_content))
219
218
  end
220
219
 
221
- it( 'should generate the correct SHA1 hash' ) do
222
- lambda{ @resource.dereference_uri! }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
220
+ it('should generate the correct SHA1 hash') do
221
+ lambda { @resource.dereference_uri! }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
223
222
  end
224
223
 
225
- it( 'should set the size in bytes' ) do
226
- lambda{ @resource.dereference_uri! }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
224
+ it('should set the size in bytes') do
225
+ lambda { @resource.dereference_uri! }.should(change(@resource, :size).to(@encoded_content.bytesize))
227
226
  end
228
227
  end
229
228
  end
230
229
 
231
- context( 'with a dereferenced URI' ) do
232
- before( :each ) do
230
+ context('with a dereferenced URI') do
231
+ before(:each) do
233
232
  @content = "1,2\n3,4"
234
- @encoded_content = Base64.encode64( @content )
233
+ @encoded_content = Base64.encode64(@content)
235
234
  @resource = RCAP::CAP_1_1::Resource.new do |resource|
236
235
  resource.resource_desc = 'Resource Description'
237
236
  resource.mime_type = 'text/csv'
@@ -240,18 +239,18 @@ describe( RCAP::CAP_1_1::Resource ) do
240
239
  end
241
240
  end
242
241
 
243
- describe( '#calculate_hash_and_size' ) do
244
- it( 'should generate the correct SHA1 hash' ) do
245
- lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :digest ).to( Digest::SHA1.hexdigest( @encoded_content )))
242
+ describe('#calculate_hash_and_size') do
243
+ it('should generate the correct SHA1 hash') do
244
+ lambda { @resource.calculate_hash_and_size }.should(change(@resource, :digest).to(Digest::SHA1.hexdigest(@encoded_content)))
246
245
  end
247
246
 
248
- it( 'should set the size in bytes' ) do
249
- lambda{ @resource.calculate_hash_and_size }.should( change( @resource, :size ).to( @encoded_content.bytesize ))
247
+ it('should set the size in bytes') do
248
+ lambda { @resource.calculate_hash_and_size }.should(change(@resource, :size).to(@encoded_content.bytesize))
250
249
  end
251
250
  end
252
251
 
253
- describe( '#decoded_deref_uri' ) do
254
- it( 'should return the original content' ) do
252
+ describe('#decoded_deref_uri') do
253
+ it('should return the original content') do
255
254
  @resource.decoded_deref_uri.should == @content
256
255
  end
257
256
  end