rcap 0.4 → 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +104 -85
  5. data/Rakefile +35 -0
  6. data/lib/rcap.rb +21 -14
  7. data/lib/rcap/alert.rb +26 -325
  8. data/lib/rcap/cap_1_1/alert.rb +363 -0
  9. data/lib/rcap/cap_1_1/area.rb +180 -0
  10. data/lib/rcap/cap_1_1/circle.rb +81 -0
  11. data/lib/rcap/cap_1_1/event_code.rb +22 -0
  12. data/lib/rcap/cap_1_1/geocode.rb +22 -0
  13. data/lib/rcap/cap_1_1/info.rb +470 -0
  14. data/lib/rcap/cap_1_1/parameter.rb +68 -0
  15. data/lib/rcap/cap_1_1/point.rb +55 -0
  16. data/lib/rcap/cap_1_1/polygon.rb +89 -0
  17. data/lib/rcap/cap_1_1/resource.rb +145 -0
  18. data/lib/rcap/cap_1_2/alert.rb +363 -0
  19. data/lib/rcap/cap_1_2/area.rb +180 -0
  20. data/lib/rcap/cap_1_2/circle.rb +81 -0
  21. data/lib/rcap/cap_1_2/event_code.rb +22 -0
  22. data/lib/rcap/cap_1_2/geocode.rb +22 -0
  23. data/lib/rcap/cap_1_2/info.rb +472 -0
  24. data/lib/rcap/cap_1_2/parameter.rb +68 -0
  25. data/lib/rcap/cap_1_2/point.rb +55 -0
  26. data/lib/rcap/cap_1_2/polygon.rb +90 -0
  27. data/lib/rcap/cap_1_2/resource.rb +147 -0
  28. data/lib/rcap/utilities.rb +14 -9
  29. data/lib/rcap/validations.rb +39 -7
  30. data/lib/rcap/version.rb +3 -0
  31. data/rcap.gemspec +30 -0
  32. data/spec/alert_spec.rb +109 -172
  33. data/spec/cap_1_1/alert_spec.rb +222 -0
  34. data/spec/cap_1_1/area_spec.rb +247 -0
  35. data/spec/cap_1_1/circle_spec.rb +88 -0
  36. data/spec/{geocode_spec.rb → cap_1_1/geocode_spec.rb} +8 -8
  37. data/spec/{info_spec.rb → cap_1_1/info_spec.rb} +143 -75
  38. data/spec/{point_spec.rb → cap_1_1/point_spec.rb} +8 -8
  39. data/spec/cap_1_1/polygon_spec.rb +97 -0
  40. data/spec/{resource_spec.rb → cap_1_1/resource_spec.rb} +24 -24
  41. data/spec/cap_1_2/alert_spec.rb +233 -0
  42. data/spec/cap_1_2/area_spec.rb +248 -0
  43. data/spec/cap_1_2/circle_spec.rb +95 -0
  44. data/spec/cap_1_2/geocode_spec.rb +38 -0
  45. data/spec/cap_1_2/info_spec.rb +338 -0
  46. data/spec/cap_1_2/point_spec.rb +46 -0
  47. data/spec/cap_1_2/polygon_spec.rb +102 -0
  48. data/spec/cap_1_2/resource_spec.rb +161 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/validations_spec.rb +80 -7
  51. metadata +122 -37
  52. data/lib/rcap/area.rb +0 -156
  53. data/lib/rcap/circle.rb +0 -78
  54. data/lib/rcap/event_code.rb +0 -20
  55. data/lib/rcap/geocode.rb +0 -20
  56. data/lib/rcap/info.rb +0 -437
  57. data/lib/rcap/parameter.rb +0 -66
  58. data/lib/rcap/point.rb +0 -53
  59. data/lib/rcap/polygon.rb +0 -77
  60. data/lib/rcap/resource.rb +0 -143
  61. data/spec/area_spec.rb +0 -179
  62. data/spec/circle_spec.rb +0 -88
  63. data/spec/polygon_spec.rb +0 -68
data/spec/circle_spec.rb DELETED
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe( RCAP::Circle ) do
4
- describe( 'should not be valid if' ) do
5
- before( :each ) do
6
- @circle = RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 1 )
7
- @circle.should( be_valid )
8
- end
9
-
10
- it( 'does not have a lattitude defined' ) do
11
- @circle.lattitude = nil
12
- @circle.should_not( be_valid )
13
- end
14
-
15
- it( 'does not have a longitude defined' ) do
16
- @circle.longitude = nil
17
- @circle.should_not( be_valid )
18
- end
19
-
20
- it( 'does not have a radius defined' ) do
21
- @circle.radius = nil
22
- @circle.should_not( be_valid )
23
- end
24
-
25
- it( 'does not have a numeric radius' ) do
26
- @circle.radius = "not a number"
27
- @circle.should_not( be_valid )
28
- end
29
-
30
- it( 'does not have a positive radius' ) do
31
- @circle.radius = -1
32
- @circle.should_not( be_valid )
33
- end
34
- end
35
-
36
- context( 'on initialisation' ) do
37
- context( 'from XML' ) do
38
- before( :each ) do
39
- @original_circle = RCAP::Circle.new( :radius => 10.5,
40
- :lattitude => 30, :longitude => 60 )
41
- @alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :circles => @original_circle )))
42
- @xml_string = @alert.to_xml
43
- @xml_document = REXML::Document.new( @xml_string )
44
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
45
- @area_element = RCAP.xpath_first( @info_element, RCAP::Area::XPATH )
46
- @circle_element = RCAP.xpath_first( @area_element, RCAP::Circle::XPATH )
47
- @circle = RCAP::Circle.from_xml_element( @circle_element )
48
- end
49
-
50
- it( 'should parse the radius correctly' ) do
51
- @circle.radius.should == @original_circle.radius
52
- end
53
-
54
- it( 'should parse the lattitude and longitude correctly' ) do
55
- @circle.lattitude.should == @original_circle.lattitude
56
- @circle.longitude.should == @original_circle.longitude
57
- end
58
- end
59
-
60
- context( 'from a hash' ) do
61
- before( :each ) do
62
- @original_circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
63
- @circle = RCAP::Circle.from_h( @original_circle.to_h )
64
- end
65
-
66
- it( 'should set the radius correctly' ) do
67
- @circle.radius.should == @original_circle.radius
68
- end
69
-
70
- it( 'should parse the lattitude and longitude correctly' ) do
71
- @circle.lattitude.should == @original_circle.lattitude
72
- @circle.longitude.should == @original_circle.longitude
73
- end
74
- end
75
- end
76
-
77
- context( 'when exported' ) do
78
- before( :each ) do
79
- @circle = RCAP::Circle.new( :radius => 10.5, :lattitude => 30, :longitude => 60 )
80
- end
81
-
82
- context( 'to hash' ) do
83
- it( 'should be correct' ) do
84
- @circle.to_h.should == { 'radius' => 10.5, 'lattitude' => 30, 'longitude' => 60 }
85
- end
86
- end
87
- end
88
- end
data/spec/polygon_spec.rb DELETED
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe( RCAP::Polygon ) do
4
- describe( 'is not valid if it' ) do
5
- before( :each ) do
6
- @polygon = RCAP::Polygon.new
7
- 3.times do
8
- @polygon.points << RCAP::Point.new( :lattitude => 0, :longitude => 0 )
9
- end
10
- @polygon.should( be_valid )
11
- end
12
-
13
- it( 'does not have any points' ) do
14
- @polygon.points.clear
15
- @polygon.should_not( be_valid )
16
- end
17
-
18
- it( 'does not have a valid collection of points' ) do
19
- @polygon.points.first.lattitude = nil
20
- @polygon.should_not( be_valid )
21
- end
22
- end
23
-
24
- context( 'on initialization' ) do
25
- context( 'from XML' ) do
26
- before( :each ) do
27
- @original_polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
28
- @alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => RCAP::Area.new( :polygons => @original_polygon )))
29
- @xml_string = @alert.to_xml
30
- @xml_document = REXML::Document.new( @xml_string )
31
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
32
- @area_element = RCAP.xpath_first( @info_element, RCAP::Area::XPATH )
33
- @polygon_element = RCAP.xpath_first( @area_element, RCAP::Polygon::XPATH )
34
- @polygon = RCAP::Polygon.from_xml_element( @polygon_element )
35
- end
36
-
37
- it( 'should parse all the points' ) do
38
- @polygon.points.zip( @original_polygon.points ).each do |point, original_point|
39
- point.lattitude.should == original_point.lattitude
40
- point.longitude.should == original_point.longitude
41
- end
42
- end
43
- end
44
-
45
- context( 'from a hash' ) do
46
- before( :each ) do
47
- @polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
48
- end
49
-
50
- it( 'should load all the points' ) do
51
- @new_polygon = RCAP::Polygon.from_h( @polygon.to_h )
52
- @new_polygon.points.should == @polygon.points
53
- end
54
- end
55
- end
56
-
57
- context( 'when exported' ) do
58
- before( :each ) do
59
- @polygon = RCAP::Polygon.new( :points => Array.new(3){|i| RCAP::Point.new( :lattitude => i, :longitude => i )})
60
- end
61
-
62
- context( 'to a hash' ) do
63
- it( 'should export correctly' ) do
64
- @polygon.to_h.should == { RCAP::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
65
- end
66
- end
67
- end
68
- end