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,45 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Circle ) do
4
- describe( 'should not be valid if' ) do
5
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Circle) do
4
+ describe('should not be valid if') do
5
+ before(:each) do
6
6
  @circle = RCAP::CAP_1_0::Circle.new do |circle|
7
7
  circle.lattitude = 0
8
8
  circle.longitude = 0
9
9
  circle.radius = 1
10
10
  end
11
- @circle.should( be_valid )
11
+ @circle.should(be_valid)
12
12
  end
13
13
 
14
- it( 'does not have a lattitude defined' ) do
14
+ it('does not have a lattitude defined') do
15
15
  @circle.lattitude = nil
16
- @circle.should_not( be_valid )
16
+ @circle.should_not(be_valid)
17
17
  end
18
18
 
19
- it( 'does not have a longitude defined' ) do
19
+ it('does not have a longitude defined') do
20
20
  @circle.longitude = nil
21
- @circle.should_not( be_valid )
21
+ @circle.should_not(be_valid)
22
22
  end
23
23
 
24
- it( 'does not have a radius defined' ) do
24
+ it('does not have a radius defined') do
25
25
  @circle.radius = nil
26
- @circle.should_not( be_valid )
26
+ @circle.should_not(be_valid)
27
27
  end
28
28
 
29
- it( 'does not have a numeric radius' ) do
30
- @circle.radius = "not a number"
31
- @circle.should_not( be_valid )
29
+ it('does not have a numeric radius') do
30
+ @circle.radius = 'not a number'
31
+ @circle.should_not(be_valid)
32
32
  end
33
33
 
34
- it( 'does not have a positive radius' ) do
34
+ it('does not have a positive radius') do
35
35
  @circle.radius = -1
36
- @circle.should_not( be_valid )
36
+ @circle.should_not(be_valid)
37
37
  end
38
38
  end
39
39
 
40
- context( 'on initialisation' ) do
41
- context( 'from XML' ) do
42
- before( :each ) do
40
+ context('on initialisation') do
41
+ context('from XML') do
42
+ before(:each) do
43
43
  @original_circle = RCAP::CAP_1_0::Circle.new do |circle|
44
44
  circle.radius = 10.5
45
45
  circle.lattitude = 30
@@ -52,46 +52,46 @@ describe( RCAP::CAP_1_0::Circle ) do
52
52
  circle.longitude = 60
53
53
  end
54
54
  @xml_string = @alert.to_xml
55
- @xml_document = REXML::Document.new( @xml_string )
56
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
57
- @area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
58
- @circle_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_0::Circle::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
59
- @circle = RCAP::CAP_1_0::Circle.from_xml_element( @circle_element )
55
+ @xml_document = REXML::Document.new(@xml_string)
56
+ @info_element = RCAP.xpath_first(@xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
57
+ @area_element = RCAP.xpath_first(@info_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
58
+ @circle_element = RCAP.xpath_first(@area_element, RCAP::CAP_1_0::Circle::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
59
+ @circle = RCAP::CAP_1_0::Circle.from_xml_element(@circle_element)
60
60
  end
61
61
 
62
- it( 'should parse the radius correctly' ) do
62
+ it('should parse the radius correctly') do
63
63
  @circle.radius.should == @original_circle.radius
64
64
  end
65
65
 
66
- it( 'should parse the lattitude and longitude correctly' ) do
66
+ it('should parse the lattitude and longitude correctly') do
67
67
  @circle.lattitude.should == @original_circle.lattitude
68
68
  @circle.longitude.should == @original_circle.longitude
69
69
  end
70
70
  end
71
71
 
72
- context( 'from a hash' ) do
73
- before( :each ) do
74
- @original_circle = RCAP::CAP_1_0::Circle.new do |circle|
75
- circle.radius = 10.5
76
- circle.lattitude = 30
77
- circle.longitude = 60
78
- end
79
- @circle = RCAP::CAP_1_0::Circle.from_h( @original_circle.to_h )
72
+ context('from a hash') do
73
+ before(:each) do
74
+ @original_circle = RCAP::CAP_1_0::Circle.new do |circle|
75
+ circle.radius = 10.5
76
+ circle.lattitude = 30
77
+ circle.longitude = 60
78
+ end
79
+ @circle = RCAP::CAP_1_0::Circle.from_h(@original_circle.to_h)
80
80
  end
81
81
 
82
- it( 'should set the radius correctly' ) do
82
+ it('should set the radius correctly') do
83
83
  @circle.radius.should == @original_circle.radius
84
84
  end
85
85
 
86
- it( 'should parse the lattitude and longitude correctly' ) do
86
+ it('should parse the lattitude and longitude correctly') do
87
87
  @circle.lattitude.should == @original_circle.lattitude
88
88
  @circle.longitude.should == @original_circle.longitude
89
89
  end
90
90
  end
91
91
  end
92
92
 
93
- context( 'when exported' ) do
94
- before( :each ) do
93
+ context('when exported') do
94
+ before(:each) do
95
95
  @circle = RCAP::CAP_1_0::Circle.new do |circle|
96
96
  circle.radius = 10.5
97
97
  circle.lattitude = 30
@@ -99,8 +99,17 @@ describe( RCAP::CAP_1_0::Circle ) do
99
99
  end
100
100
  end
101
101
 
102
- context( 'to hash' ) do
103
- it( 'should be correct' ) do
102
+ context('to geojson') do
103
+ it('should be valid geojson') do
104
+ @circle.longitude = 5.6
105
+ expected = '{"type":"Feature","geometry":{"type":"Point",' \
106
+ '"coordinates":[5.6,30]},"properties":{"radius":10.5}}'
107
+ expect(@circle.to_geojson).to eq expected
108
+ end
109
+ end
110
+
111
+ context('to hash') do
112
+ it('should be correct') do
104
113
  @circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
105
114
  end
106
115
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::EventCode ) do
4
- context( 'when initialised' ) do
5
- context( 'from XML' ) do
6
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::EventCode) do
4
+ context('when initialised') do
5
+ context('from XML') do
6
+ before(:each) do
7
7
  @original_event_code = RCAP::CAP_1_0::EventCode.new do |event_code|
8
8
  event_code.name = 'name'
9
9
  event_code.value = 'value'
@@ -11,36 +11,36 @@ describe( RCAP::CAP_1_0::EventCode ) do
11
11
  @alert = RCAP::CAP_1_0::Alert.new
12
12
  @alert.add_info.event_codes << @original_event_code
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
- @event_code_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_0::EventCode::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
17
- @event_code = RCAP::CAP_1_0::EventCode.from_xml_element( @event_code_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
+ @event_code_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_0::EventCode::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
17
+ @event_code = RCAP::CAP_1_0::EventCode.from_xml_element(@event_code_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
  @event_code.class.should == RCAP::CAP_1_0::EventCode
22
22
  end
23
23
 
24
- it( 'should parse the name correctly' ) do
24
+ it('should parse the name correctly') do
25
25
  @event_code.name.should == @original_event_code.name
26
26
  end
27
27
 
28
- it( 'should parse the value correctly' ) do
28
+ it('should parse the value correctly') do
29
29
  @event_code.value.should == @original_event_code.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
  @event_code = RCAP::CAP_1_0::EventCode.new do |event_code|
37
37
  event_code.name = 'name'
38
38
  event_code.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
  @event_code.to_h.should == { 'name' => 'value' }
45
45
  end
46
46
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::CAP_1_0::Geocode ) do
4
- context( 'when initialised' ) do
5
- context( 'from XML' ) do
6
- before( :each ) do
3
+ describe(RCAP::CAP_1_0::Geocode) do
4
+ context('when initialised') do
5
+ context('from XML') do
6
+ before(:each) do
7
7
  @original_geocode = RCAP::CAP_1_0::Geocode.new do |geocode|
8
8
  geocode.name = 'name'
9
9
  geocode.value = 'value'
@@ -11,37 +11,37 @@ describe( RCAP::CAP_1_0::Geocode ) do
11
11
  @alert = RCAP::CAP_1_0::Alert.new
12
12
  @alert.add_info.add_area.geocodes << @original_geocode
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
- @area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
17
- @geocode_xml_element = RCAP.xpath_first( @area_xml_element, RCAP::CAP_1_0::Geocode::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
18
- @geocode = RCAP::CAP_1_0::Geocode.from_xml_element( @geocode_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
+ @area_xml_element = RCAP.xpath_first(@info_xml_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
17
+ @geocode_xml_element = RCAP.xpath_first(@area_xml_element, RCAP::CAP_1_0::Geocode::XPATH, RCAP::CAP_1_0::Alert::XMLNS)
18
+ @geocode = RCAP::CAP_1_0::Geocode.from_xml_element(@geocode_xml_element)
19
19
  end
20
20
 
21
- it( 'should parse into the correct class' ) do
21
+ it('should parse into the correct class') do
22
22
  @geocode.class.should == RCAP::CAP_1_0::Geocode
23
23
  end
24
24
 
25
- it( 'should parse the name correctly' ) do
25
+ it('should parse the name correctly') do
26
26
  @geocode.name.should == @original_geocode.name
27
27
  end
28
28
 
29
- it( 'should parse the value correctly' ) do
29
+ it('should parse the value correctly') do
30
30
  @geocode.value.should == @original_geocode.value
31
31
  end
32
32
  end
33
33
  end
34
34
 
35
- context( 'when exported' ) do
36
- before( :each ) do
35
+ context('when exported') do
36
+ before(:each) do
37
37
  @geocode = RCAP::CAP_1_0::Geocode.new do |geocode|
38
38
  geocode.name = 'name'
39
39
  geocode.value = 'value'
40
40
  end
41
41
  end
42
42
 
43
- context( 'to a hash' ) do
44
- it( 'should export correctly' ) do
43
+ context('to a hash') do
44
+ it('should export correctly') do
45
45
  @geocode.to_h.should == { 'name' => 'value' }
46
46
  end
47
47
  end
@@ -1,123 +1,122 @@
1
1
  require 'spec_helper'
2
2
 
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
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
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
29
+ [%w(name1 value1), %w(name2 value2)].each do |name, value|
30
+ info.add_event_code do |event_code|
31
+ event_code.name = name
32
+ event_code.value = value
34
33
  end
34
+ end
35
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
36
+ [%w(name1 value1), %w(name2 value2)].each do |name, value|
37
+ info.add_parameter do |parameter|
38
+ parameter.name = name
39
+ parameter.value = value
41
40
  end
41
+ end
42
42
 
43
- [ 'Area1', 'Area2' ].each do |area_desc|
44
- info.add_area do |area|
45
- area.area_desc = area_desc
46
- end
43
+ %w(Area1 Area2).each do |area_desc|
44
+ info.add_area do |area|
45
+ area.area_desc = area_desc
47
46
  end
48
47
  end
49
48
  end
50
- context( 'on initialisation' ) do
51
- before( :each ) do
49
+ end
50
+ context('on initialisation') do
51
+ before(:each) do
52
52
  @info = RCAP::CAP_1_0::Info.new
53
53
  end
54
54
 
55
- it( 'should have a default language of en-US' ) { @info.language.should == 'en-US' }
56
- it( 'should have no categories' ) { @info.categories.should( be_empty )}
57
- it( 'should have no event' ) { @info.event.should( be_nil )}
58
- it( 'should have no urgency' ) { @info.urgency.should( be_nil )}
59
- it( 'should have no severity' ) { @info.severity.should( be_nil )}
60
- it( 'should have no certainty' ) { @info.certainty.should( be_nil )}
61
- it( 'should have no audience' ) { @info.audience.should( be_nil )}
62
- it( 'should have no event_codes' ) { @info.event_codes.should( be_empty )}
63
- it( 'should have no effective datetime' ) { @info.effective.should( be_nil )}
64
- it( 'should have no onset datetime' ) { @info.onset.should( be_nil )}
65
- it( 'should have no expires datetime' ) { @info.expires.should( be_nil )}
66
- it( 'should have no sender name ' ) { @info.sender_name.should( be_nil )}
67
- it( 'should have no headline' ) { @info.headline.should( be_nil )}
68
- it( 'should have no description' ) { @info.description.should( be_nil )}
69
- it( 'should have no instruction' ) { @info.instruction.should( be_nil )}
70
- it( 'should have no web' ) { @info.web.should( be_nil )}
71
- it( 'should have no contact' ) { @info.contact.should( be_nil )}
72
- it( 'should have no parameters' ) { @info.parameters.should( be_empty )}
73
-
74
- shared_examples_for( 'it can parse into a CAP 1.0 Info object' ) do
75
- it( 'should parse categories correctly' ){ @info.categories.should_not( be_nil ) ; @info.categories.should == @original_info.categories }
76
- it( 'should parse event correctly' ){ @info.event.should_not( be_nil ) ; @info.event.should == @original_info.event }
77
- it( 'should parse urgency correctly' ){ @info.urgency.should_not( be_nil ) ; @info.urgency.should == @original_info.urgency }
78
- it( 'should parse severity correctly' ){ @info.severity.should_not( be_nil ) ; @info.severity.should == @original_info.severity }
79
- it( 'should parse certainty correctly' ){ @info.certainty.should_not( be_nil ) ; @info.certainty.should == @original_info.certainty }
80
- it( 'should parse audience correctly' ){ @info.audience.should_not( be_nil ) ; @info.audience.should == @original_info.audience }
81
- it( 'should parse effective correctly' ){ @info.effective.should_not( be_nil ) ; @info.effective.should( be_within(Rational( 1, 86400 )).of( @original_info.effective ))}
82
- it( 'should parse onset correctly' ){ @info.onset.should_not( be_nil ) ; @info.onset.should( be_within( Rational( 1, 86400 )).of( @original_info.onset ))}
83
- it( 'should parse expires correctly' ){ @info.expires.should_not( be_nil ) ; @info.expires.should( be_within( Rational( 1, 86400 )).of( @original_info.expires ))}
84
- it( 'should parse sender_name correctly' ){ @info.sender_name.should_not( be_nil ); @info.sender_name.should == @original_info.sender_name }
85
- it( 'should parse headline correctly' ){ @info.headline.should_not( be_nil ) ; @info.headline.should == @original_info.headline }
86
- it( 'should parse description correctly' ){ @info.description.should_not( be_nil ); @info.description.should == @original_info.description }
87
- it( 'should parse instruction correctly' ){ @info.instruction.should_not( be_nil ); @info.instruction.should == @original_info.instruction }
88
- it( 'should parse web correctly' ){ @info.web.should_not( be_nil ) ; @info.web.should == @original_info.web }
89
- it( 'should parse contact correctly' ){ @info.contact.should_not( be_nil ) ; @info.contact.should == @original_info.contact }
90
- it( 'should parse event_codes correctly' ){ @info.event_codes.should_not( be_nil ); @info.event_codes.should == @original_info.event_codes }
91
- it( 'should parse parameters correctly' ){ @info.parameters.should_not( be_nil ) ; @info.parameters.should == @original_info.parameters }
92
- it( 'should parse resources correctly' ){ @info.resources.should_not( be_nil ) ; @info.resources.map( &:to_s ).should == @original_info.resources.map( &:to_s )}
93
- it( 'should parse areas correctly' ){ @info.areas.should_not( be_nil ) ; @info.areas.should == @original_info.areas }
55
+ it('should have a default language of en-US') { @info.language.should == 'en-US' }
56
+ it('should have no categories') { @info.categories.should(be_empty) }
57
+ it('should have no event') { @info.event.should(be_nil) }
58
+ it('should have no urgency') { @info.urgency.should(be_nil) }
59
+ it('should have no severity') { @info.severity.should(be_nil) }
60
+ it('should have no certainty') { @info.certainty.should(be_nil) }
61
+ it('should have no audience') { @info.audience.should(be_nil) }
62
+ it('should have no event_codes') { @info.event_codes.should(be_empty) }
63
+ it('should have no effective datetime') { @info.effective.should(be_nil) }
64
+ it('should have no onset datetime') { @info.onset.should(be_nil) }
65
+ it('should have no expires datetime') { @info.expires.should(be_nil) }
66
+ it('should have no sender name ') { @info.sender_name.should(be_nil) }
67
+ it('should have no headline') { @info.headline.should(be_nil) }
68
+ it('should have no description') { @info.description.should(be_nil) }
69
+ it('should have no instruction') { @info.instruction.should(be_nil) }
70
+ it('should have no web') { @info.web.should(be_nil) }
71
+ it('should have no contact') { @info.contact.should(be_nil) }
72
+ it('should have no parameters') { @info.parameters.should(be_empty) }
73
+
74
+ shared_examples_for('it can parse into a CAP 1.0 Info object') do
75
+ it('should parse categories correctly') { @info.categories.should_not(be_nil); @info.categories.should == @original_info.categories }
76
+ it('should parse event correctly') { @info.event.should_not(be_nil); @info.event.should == @original_info.event }
77
+ it('should parse urgency correctly') { @info.urgency.should_not(be_nil); @info.urgency.should == @original_info.urgency }
78
+ it('should parse severity correctly') { @info.severity.should_not(be_nil); @info.severity.should == @original_info.severity }
79
+ it('should parse certainty correctly') { @info.certainty.should_not(be_nil); @info.certainty.should == @original_info.certainty }
80
+ it('should parse audience correctly') { @info.audience.should_not(be_nil); @info.audience.should == @original_info.audience }
81
+ it('should parse effective correctly') { @info.effective.should_not(be_nil); @info.effective.should(be_within(Rational(1, 86_400)).of(@original_info.effective)) }
82
+ it('should parse onset correctly') { @info.onset.should_not(be_nil); @info.onset.should(be_within(Rational(1, 86_400)).of(@original_info.onset)) }
83
+ it('should parse expires correctly') { @info.expires.should_not(be_nil); @info.expires.should(be_within(Rational(1, 86_400)).of(@original_info.expires)) }
84
+ it('should parse sender_name correctly') { @info.sender_name.should_not(be_nil); @info.sender_name.should == @original_info.sender_name }
85
+ it('should parse headline correctly') { @info.headline.should_not(be_nil); @info.headline.should == @original_info.headline }
86
+ it('should parse description correctly') { @info.description.should_not(be_nil); @info.description.should == @original_info.description }
87
+ it('should parse instruction correctly') { @info.instruction.should_not(be_nil); @info.instruction.should == @original_info.instruction }
88
+ it('should parse web correctly') { @info.web.should_not(be_nil); @info.web.should == @original_info.web }
89
+ it('should parse contact correctly') { @info.contact.should_not(be_nil); @info.contact.should == @original_info.contact }
90
+ it('should parse event_codes correctly') { @info.event_codes.should_not(be_nil); @info.event_codes.should == @original_info.event_codes }
91
+ it('should parse parameters correctly') { @info.parameters.should_not(be_nil); @info.parameters.should == @original_info.parameters }
92
+ it('should parse resources correctly') { @info.resources.should_not(be_nil); @info.resources.map(&:to_s).should == @original_info.resources.map(&:to_s) }
93
+ it('should parse areas correctly') { @info.areas.should_not(be_nil); @info.areas.should == @original_info.areas }
94
94
  end
95
95
 
96
-
97
- context( 'from XML' ) do
98
- before( :each ) do
96
+ context('from XML') do
97
+ before(:each) do
99
98
  @original_info = create_info
100
99
  @alert = RCAP::CAP_1_0::Alert.new
101
100
  @alert.infos << @original_info
102
101
  @xml_string = @alert.to_xml
103
- @xml_document = REXML::Document.new( @xml_string )
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 ))
102
+ @xml_document = REXML::Document.new(@xml_string)
103
+ @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))
105
104
  end
106
105
 
107
- it_should_behave_like( "it can parse into a CAP 1.0 Info object" )
106
+ it_should_behave_like('it can parse into a CAP 1.0 Info object')
108
107
  end
109
108
 
110
- context( 'from a hash' ) do
111
- before( :each ) do
109
+ context('from a hash') do
110
+ before(:each) do
112
111
  @original_info = create_info
113
- @info = RCAP::CAP_1_0::Info.from_h( @original_info.to_h )
112
+ @info = RCAP::CAP_1_0::Info.from_h(@original_info.to_h)
114
113
  end
115
- it_should_behave_like( "it can parse into a CAP 1.0 Info object" )
114
+ it_should_behave_like('it can parse into a CAP 1.0 Info object')
116
115
  end
117
116
  end
118
117
 
119
- context( 'is not valid if it' ) do
120
- before( :each ) do
118
+ context('is not valid if it') do
119
+ before(:each) do
121
120
  @info = RCAP::CAP_1_0::Info.new do |info|
122
121
  info.event = 'Info Event'
123
122
  info.categories << RCAP::CAP_1_0::Info::CATEGORY_GEO
@@ -127,193 +126,192 @@ describe( RCAP::CAP_1_0::Info ) do
127
126
  end
128
127
  @info.valid?
129
128
  puts @info.errors.full_messages
130
- @info.should( be_valid )
129
+ @info.should(be_valid)
131
130
  end
132
131
 
133
- it( 'does not have an event' ) do
132
+ it('does not have an event') do
134
133
  @info.event = nil
135
- @info.should_not( be_valid )
134
+ @info.should_not(be_valid)
136
135
  end
137
136
 
138
- it( 'does not have an urgency' ) do
137
+ it('does not have an urgency') do
139
138
  @info.urgency = nil
140
- @info.should_not( be_valid )
139
+ @info.should_not(be_valid)
141
140
  end
142
141
 
143
- it( 'does not have an severity' ) do
142
+ it('does not have an severity') do
144
143
  @info.severity = nil
145
- @info.should_not( be_valid )
144
+ @info.should_not(be_valid)
146
145
  end
147
146
 
148
- it( 'does not have an certainty' ) do
147
+ it('does not have an certainty') do
149
148
  @info.certainty = nil
150
- @info.should_not( be_valid )
149
+ @info.should_not(be_valid)
151
150
  end
152
151
  end
153
152
 
154
-
155
- describe( 'when exported' ) do
156
- context( 'to hash' ) do
157
- before( :each ) do
153
+ describe('when exported') do
154
+ context('to hash') do
155
+ before(:each) do
158
156
  @info = create_info
159
157
  @info_hash = @info.to_h
160
158
  end
161
159
 
162
- it( 'should export the language correctly' ) do
163
- @info_hash[ RCAP::CAP_1_0::Info::LANGUAGE_KEY ].should == @info.language
160
+ it('should export the language correctly') do
161
+ @info_hash[ RCAP::CAP_1_0::Info::LANGUAGE_KEY].should == @info.language
164
162
  end
165
163
 
166
- it( 'should export the categories' ) do
167
- @info_hash[ RCAP::CAP_1_0::Info::CATEGORIES_KEY ].should == @info.categories
164
+ it('should export the categories') do
165
+ @info_hash[ RCAP::CAP_1_0::Info::CATEGORIES_KEY].should == @info.categories
168
166
  end
169
167
 
170
- it( 'should export the event' ) do
171
- @info_hash[ RCAP::CAP_1_0::Info::EVENT_KEY ].should == @info.event
168
+ it('should export the event') do
169
+ @info_hash[ RCAP::CAP_1_0::Info::EVENT_KEY].should == @info.event
172
170
  end
173
171
 
174
- it( 'should export the urgency' ) do
175
- @info_hash[ RCAP::CAP_1_0::Info:: URGENCY_KEY ].should == @info.urgency
172
+ it('should export the urgency') do
173
+ @info_hash[ RCAP::CAP_1_0::Info:: URGENCY_KEY].should == @info.urgency
176
174
  end
177
175
 
178
- it( 'should export the severity' ) do
179
- @info_hash[ RCAP::CAP_1_0::Info:: SEVERITY_KEY ].should == @info.severity
176
+ it('should export the severity') do
177
+ @info_hash[ RCAP::CAP_1_0::Info:: SEVERITY_KEY].should == @info.severity
180
178
  end
181
179
 
182
- it( 'should export the certainty' ) do
183
- @info_hash[ RCAP::CAP_1_0::Info:: CERTAINTY_KEY ].should == @info.certainty
180
+ it('should export the certainty') do
181
+ @info_hash[ RCAP::CAP_1_0::Info:: CERTAINTY_KEY].should == @info.certainty
184
182
  end
185
183
 
186
- it( 'should export the audience' ) do
187
- @info_hash[ RCAP::CAP_1_0::Info:: AUDIENCE_KEY ].should == @info.audience
184
+ it('should export the audience') do
185
+ @info_hash[ RCAP::CAP_1_0::Info:: AUDIENCE_KEY].should == @info.audience
188
186
  end
189
187
 
190
- it( 'should export the effective date' ) do
191
- @info_hash[ RCAP::CAP_1_0::Info::EFFECTIVE_KEY ].should == @info.effective.to_s_for_cap
188
+ it('should export the effective date') do
189
+ @info_hash[ RCAP::CAP_1_0::Info::EFFECTIVE_KEY].should == @info.effective.to_s_for_cap
192
190
  end
193
191
 
194
- it( 'should export the onset date' ) do
195
- @info_hash[ RCAP::CAP_1_0::Info::ONSET_KEY ].should == @info.onset.to_s_for_cap
192
+ it('should export the onset date') do
193
+ @info_hash[ RCAP::CAP_1_0::Info::ONSET_KEY].should == @info.onset.to_s_for_cap
196
194
  end
197
195
 
198
- it( 'should export the expires date' ) do
199
- @info_hash[ RCAP::CAP_1_0::Info::EXPIRES_KEY ].should == @info.expires.to_s_for_cap
196
+ it('should export the expires date') do
197
+ @info_hash[ RCAP::CAP_1_0::Info::EXPIRES_KEY].should == @info.expires.to_s_for_cap
200
198
  end
201
199
 
202
- it( 'should export the sender name' ) do
203
- @info_hash[ RCAP::CAP_1_0::Info::SENDER_NAME_KEY ].should == @info.sender_name
204
- end
200
+ it('should export the sender name') do
201
+ @info_hash[ RCAP::CAP_1_0::Info::SENDER_NAME_KEY].should == @info.sender_name
202
+ end
205
203
 
206
- it( 'should export the headline' ) do
207
- @info_hash[ RCAP::CAP_1_0::Info::HEADLINE_KEY ].should == @info.headline
208
- end
204
+ it('should export the headline') do
205
+ @info_hash[ RCAP::CAP_1_0::Info::HEADLINE_KEY].should == @info.headline
206
+ end
209
207
 
210
- it( 'should export the description' ) do
211
- @info_hash[ RCAP::CAP_1_0::Info::DESCRIPTION_KEY ].should == @info.description
212
- end
208
+ it('should export the description') do
209
+ @info_hash[ RCAP::CAP_1_0::Info::DESCRIPTION_KEY].should == @info.description
210
+ end
213
211
 
214
- it( 'should export the instruction' ) do
215
- @info_hash[ RCAP::CAP_1_0::Info::INSTRUCTION_KEY ].should == @info.instruction
216
- end
212
+ it('should export the instruction') do
213
+ @info_hash[ RCAP::CAP_1_0::Info::INSTRUCTION_KEY].should == @info.instruction
214
+ end
217
215
 
218
- it( 'should export the web address ' ) do
219
- @info_hash[ RCAP::CAP_1_0::Info::WEB_KEY ].should == @info.web
220
- end
216
+ it('should export the web address ') do
217
+ @info_hash[ RCAP::CAP_1_0::Info::WEB_KEY].should == @info.web
218
+ end
221
219
 
222
- it( 'should export the contact' ) do
223
- @info_hash[ RCAP::CAP_1_0::Info::CONTACT_KEY ].should == @info.contact
224
- end
220
+ it('should export the contact') do
221
+ @info_hash[ RCAP::CAP_1_0::Info::CONTACT_KEY].should == @info.contact
222
+ end
225
223
 
226
- it( 'should export the event codes' ) do
227
- @info_hash[ RCAP::CAP_1_0::Info::EVENT_CODES_KEY ].should == @info.event_codes.map{ |event_code| event_code.to_h }
228
- end
224
+ it('should export the event codes') do
225
+ @info_hash[ RCAP::CAP_1_0::Info::EVENT_CODES_KEY].should == @info.event_codes.map { |event_code| event_code.to_h }
226
+ end
229
227
 
230
- it( 'should export the parameters ' ) do
231
- @info_hash[ RCAP::CAP_1_0::Info::PARAMETERS_KEY ].should == @info.parameters.map{ |parameter| parameter.to_h }
232
- end
228
+ it('should export the parameters ') do
229
+ @info_hash[ RCAP::CAP_1_0::Info::PARAMETERS_KEY].should == @info.parameters.map { |parameter| parameter.to_h }
230
+ end
233
231
 
234
- it( 'should export the resources ' ) do
235
- @info_hash[ RCAP::CAP_1_0::Info::RESOURCES_KEY ].should == @info.resources.map{ |resource| resource.to_h }
236
- end
232
+ it('should export the resources ') do
233
+ @info_hash[ RCAP::CAP_1_0::Info::RESOURCES_KEY].should == @info.resources.map { |resource| resource.to_h }
234
+ end
237
235
 
238
- it( 'should export the areas' ) do
239
- @info_hash[ RCAP::CAP_1_0::Info::AREAS_KEY ].should == @info.areas.map{ |area| area.to_h }
240
- end
236
+ it('should export the areas') do
237
+ @info_hash[ RCAP::CAP_1_0::Info::AREAS_KEY].should == @info.areas.map { |area| area.to_h }
238
+ end
241
239
  end
242
240
  end
243
241
 
244
- describe( 'instance methods' ) do
245
- before( :each ) do
242
+ describe('instance methods') do
243
+ before(:each) do
246
244
  @info = RCAP::CAP_1_0::Info.new
247
245
  end
248
246
 
249
- describe( '#add_event_code' ) do
250
- before( :each ) do
247
+ describe('#add_event_code') do
248
+ before(:each) do
251
249
  @event_code = @info.add_event_code do |event_code|
252
- event_code.name = 'Event Code'
253
- event_code.value = '1234'
250
+ event_code.name = 'Event Code'
251
+ event_code.value = '1234'
254
252
  end
255
253
  end
256
254
 
257
- it( 'should return a 1.0 EventCode' ) do
255
+ it('should return a 1.0 EventCode') do
258
256
  @event_code.class.should == RCAP::CAP_1_0::EventCode
259
257
  @event_code.name.should == 'Event Code'
260
258
  @event_code.value.should == '1234'
261
259
  end
262
260
 
263
- it( 'should add an EventCode to the event_codes attribute' ) do
261
+ it('should add an EventCode to the event_codes attribute') do
264
262
  @info.event_codes.size.should == 1
265
263
  end
266
264
  end
267
265
 
268
- describe( '#add_parameter' ) do
269
- before( :each ) do
266
+ describe('#add_parameter') do
267
+ before(:each) do
270
268
  @parameter = @info.add_parameter do |parameter|
271
- parameter.name = 'Parameter'
272
- parameter.value = '1234'
269
+ parameter.name = 'Parameter'
270
+ parameter.value = '1234'
273
271
  end
274
272
  end
275
273
 
276
- it( 'should return a 1.0 Parameter' ) do
274
+ it('should return a 1.0 Parameter') do
277
275
  @parameter.class.should == RCAP::CAP_1_0::Parameter
278
276
  @parameter.name.should == 'Parameter'
279
277
  @parameter.value.should == '1234'
280
278
  end
281
279
 
282
- it( 'should add a Parameter to the parameters attribute' ) do
280
+ it('should add a Parameter to the parameters attribute') do
283
281
  @info.parameters.size.should == 1
284
282
  end
285
283
  end
286
284
 
287
- describe( '#add_resource' ) do
288
- before( :each ) do
285
+ describe('#add_resource') do
286
+ before(:each) do
289
287
  @resource = @info.add_resource do |resource|
290
288
  resource.resource_desc = 'Resource'
291
289
  end
292
290
  end
293
291
 
294
- it( 'should return a 1.0 Resource' ) do
292
+ it('should return a 1.0 Resource') do
295
293
  @resource.class.should == RCAP::CAP_1_0::Resource
296
294
  @resource.resource_desc.should == 'Resource'
297
295
  end
298
296
 
299
- it( 'should add a Resource to the resources attribute' ) do
297
+ it('should add a Resource to the resources attribute') do
300
298
  @info.resources.size.should == 1
301
299
  end
302
300
  end
303
301
 
304
- describe( '#add_area' ) do
305
- before( :each ) do
302
+ describe('#add_area') do
303
+ before(:each) do
306
304
  @area = @info.add_area do |area|
307
305
  area.area_desc = 'Area'
308
306
  end
309
307
  end
310
308
 
311
- it( 'should return a 1.0 area' ) do
309
+ it('should return a 1.0 area') do
312
310
  @area.class.should == RCAP::CAP_1_0::Area
313
311
  @area.area_desc.should == 'Area'
314
312
  end
315
313
 
316
- it( 'should add a Area to the areas attribute' ) do
314
+ it('should add a Area to the areas attribute') do
317
315
  @info.areas.size.should == 1
318
316
  end
319
317
  end