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.
- data/.gitignore +7 -0
- data/CHANGELOG.rdoc +6 -0
- data/Gemfile +4 -0
- data/README.rdoc +104 -85
- data/Rakefile +35 -0
- data/lib/rcap.rb +21 -14
- data/lib/rcap/alert.rb +26 -325
- data/lib/rcap/cap_1_1/alert.rb +363 -0
- data/lib/rcap/cap_1_1/area.rb +180 -0
- data/lib/rcap/cap_1_1/circle.rb +81 -0
- data/lib/rcap/cap_1_1/event_code.rb +22 -0
- data/lib/rcap/cap_1_1/geocode.rb +22 -0
- data/lib/rcap/cap_1_1/info.rb +470 -0
- data/lib/rcap/cap_1_1/parameter.rb +68 -0
- data/lib/rcap/cap_1_1/point.rb +55 -0
- data/lib/rcap/cap_1_1/polygon.rb +89 -0
- data/lib/rcap/cap_1_1/resource.rb +145 -0
- data/lib/rcap/cap_1_2/alert.rb +363 -0
- data/lib/rcap/cap_1_2/area.rb +180 -0
- data/lib/rcap/cap_1_2/circle.rb +81 -0
- data/lib/rcap/cap_1_2/event_code.rb +22 -0
- data/lib/rcap/cap_1_2/geocode.rb +22 -0
- data/lib/rcap/cap_1_2/info.rb +472 -0
- data/lib/rcap/cap_1_2/parameter.rb +68 -0
- data/lib/rcap/cap_1_2/point.rb +55 -0
- data/lib/rcap/cap_1_2/polygon.rb +90 -0
- data/lib/rcap/cap_1_2/resource.rb +147 -0
- data/lib/rcap/utilities.rb +14 -9
- data/lib/rcap/validations.rb +39 -7
- data/lib/rcap/version.rb +3 -0
- data/rcap.gemspec +30 -0
- data/spec/alert_spec.rb +109 -172
- data/spec/cap_1_1/alert_spec.rb +222 -0
- data/spec/cap_1_1/area_spec.rb +247 -0
- data/spec/cap_1_1/circle_spec.rb +88 -0
- data/spec/{geocode_spec.rb → cap_1_1/geocode_spec.rb} +8 -8
- data/spec/{info_spec.rb → cap_1_1/info_spec.rb} +143 -75
- data/spec/{point_spec.rb → cap_1_1/point_spec.rb} +8 -8
- data/spec/cap_1_1/polygon_spec.rb +97 -0
- data/spec/{resource_spec.rb → cap_1_1/resource_spec.rb} +24 -24
- data/spec/cap_1_2/alert_spec.rb +233 -0
- data/spec/cap_1_2/area_spec.rb +248 -0
- data/spec/cap_1_2/circle_spec.rb +95 -0
- data/spec/cap_1_2/geocode_spec.rb +38 -0
- data/spec/cap_1_2/info_spec.rb +338 -0
- data/spec/cap_1_2/point_spec.rb +46 -0
- data/spec/cap_1_2/polygon_spec.rb +102 -0
- data/spec/cap_1_2/resource_spec.rb +161 -0
- data/spec/spec.opts +2 -0
- data/spec/validations_spec.rb +80 -7
- metadata +122 -37
- data/lib/rcap/area.rb +0 -156
- data/lib/rcap/circle.rb +0 -78
- data/lib/rcap/event_code.rb +0 -20
- data/lib/rcap/geocode.rb +0 -20
- data/lib/rcap/info.rb +0 -437
- data/lib/rcap/parameter.rb +0 -66
- data/lib/rcap/point.rb +0 -53
- data/lib/rcap/polygon.rb +0 -77
- data/lib/rcap/resource.rb +0 -143
- data/spec/area_spec.rb +0 -179
- data/spec/circle_spec.rb +0 -88
- data/spec/polygon_spec.rb +0 -68
data/lib/rcap/parameter.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module RCAP
|
2
|
-
# A Parameter object is valid if
|
3
|
-
# * it has a name
|
4
|
-
# * it has a value
|
5
|
-
class Parameter
|
6
|
-
include Validation
|
7
|
-
|
8
|
-
validates_presence_of( :name, :value )
|
9
|
-
|
10
|
-
attr_accessor( :name, :value )
|
11
|
-
|
12
|
-
XML_ELEMENT_NAME = "parameter" # :nodoc:
|
13
|
-
NAME_ELEMENT_NAME = "valueName" # :nodoc:
|
14
|
-
VALUE_ELEMENT_NAME = "value" # :nodoc:
|
15
|
-
|
16
|
-
XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
|
17
|
-
NAME_XPATH = "cap:#{ NAME_ELEMENT_NAME }" # :nodoc:
|
18
|
-
VALUE_XPATH = "cap:#{ VALUE_ELEMENT_NAME }" # :nodoc:
|
19
|
-
|
20
|
-
def initialize( attributes = {} )
|
21
|
-
@name = attributes[ :name ]
|
22
|
-
@value = attributes[ :value ]
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_xml_element # :nodoc:
|
26
|
-
xml_element = REXML::Element.new( XML_ELEMENT_NAME )
|
27
|
-
xml_element.add_element( NAME_ELEMENT_NAME ).add_text( self.name )
|
28
|
-
xml_element.add_element( VALUE_ELEMENT_NAME ).add_text( self.value )
|
29
|
-
xml_element
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_xml # :nodoc:
|
33
|
-
self.to_xml_element.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
def inspect # :nodoc:
|
37
|
-
"#{ self.name }: #{ self.value }"
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a string representation of the parameter of the form
|
41
|
-
# name: value
|
42
|
-
def to_s
|
43
|
-
self.inspect
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.from_xml_element( parameter_xml_element ) # :nodoc:
|
47
|
-
Parameter.new( :name => RCAP.xpath_text( parameter_xml_element, NAME_XPATH ),
|
48
|
-
:value => RCAP.xpath_text( parameter_xml_element, VALUE_XPATH ))
|
49
|
-
end
|
50
|
-
|
51
|
-
# Two parameters are equivalent if they have the same name and value.
|
52
|
-
def ==( other )
|
53
|
-
[ self.name, self.value ] == [ other.name, other.value ]
|
54
|
-
end
|
55
|
-
|
56
|
-
def to_h # :nodoc:
|
57
|
-
RCAP.attribute_values_to_hash(
|
58
|
-
[ @name, @value ])
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.from_h( hash ) # :nodoc:
|
62
|
-
key = hash.keys.first
|
63
|
-
self.new( :name => key, :value => hash[ key ])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/rcap/point.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module RCAP
|
2
|
-
# A Point object is valid if
|
3
|
-
# * it has a lattitude within the minimum and maximum lattitude values
|
4
|
-
# * it has a longitude within the minimum and maximum longitude values
|
5
|
-
class Point
|
6
|
-
include Validation
|
7
|
-
|
8
|
-
MAX_LONGITUDE = 180
|
9
|
-
MIN_LONGITUDE = -180
|
10
|
-
MAX_LATTITUDE = 90
|
11
|
-
MIN_LATTITUDE= -90
|
12
|
-
|
13
|
-
attr_accessor( :lattitude )
|
14
|
-
attr_accessor( :longitude )
|
15
|
-
|
16
|
-
validates_numericality_of( :lattitude, :longitude )
|
17
|
-
validates_inclusion_of( :lattitude, :in => MIN_LATTITUDE..MAX_LATTITUDE )
|
18
|
-
validates_inclusion_of( :longitude, :in => MIN_LONGITUDE..MAX_LONGITUDE)
|
19
|
-
|
20
|
-
def initialize( attributes = {} )
|
21
|
-
@lattitude = attributes[ :lattitude ]
|
22
|
-
@longitude = attributes[ :longitude ]
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns a string representation of the point of the form
|
26
|
-
# lattitude,longitude
|
27
|
-
def to_s
|
28
|
-
"#{ self.lattitude },#{ self.longitude }"
|
29
|
-
end
|
30
|
-
|
31
|
-
def inspect # :nodoc:
|
32
|
-
'('+self.to_s+')'
|
33
|
-
end
|
34
|
-
|
35
|
-
# Two points are equivalent if they have the same lattitude and longitude
|
36
|
-
def ==( other )
|
37
|
-
[ self.lattitude, self.longitude ] == [ other.lattitude, other.longitude ]
|
38
|
-
end
|
39
|
-
|
40
|
-
LATTITUDE_KEY = 'lattitude_hash' # :nodoc:
|
41
|
-
LONGITUDE_KEY = 'longitude_hash' # :nodoc:
|
42
|
-
|
43
|
-
def to_h # :nodoc:
|
44
|
-
RCAP.attribute_values_to_hash(
|
45
|
-
[ LATTITUDE_KEY, self.lattitude ],
|
46
|
-
[ LONGITUDE_KEY, self.longitude ])
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.from_h( point_hash ) # :nodoc:
|
50
|
-
self.new( :lattitude => point_hash[ LATTITUDE_KEY ], :longitude => point_hash[ LONGITUDE_KEY ])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/rcap/polygon.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
module RCAP
|
2
|
-
# A Polygon object is valid if
|
3
|
-
# * it has a minimum of three points
|
4
|
-
# * each Point object in the points collection is valid
|
5
|
-
class Polygon
|
6
|
-
include Validation
|
7
|
-
|
8
|
-
# Collection of Point objects.
|
9
|
-
attr_reader( :points )
|
10
|
-
|
11
|
-
validates_length_of( :points, :minimum => 3 )
|
12
|
-
validates_collection_of( :points )
|
13
|
-
|
14
|
-
XML_ELEMENT_NAME = 'polygon' # :nodoc:
|
15
|
-
XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
|
16
|
-
|
17
|
-
def initialize( attributes = {})
|
18
|
-
@points = Array( attributes[ :points ])
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns a string representation of the polygon of the form
|
22
|
-
# points[0] points[1] points[2] ... points[n-1] points[0]
|
23
|
-
# where each point is formatted with RCAP::Point#to_s
|
24
|
-
def to_s
|
25
|
-
(@points + [ @points.first ]).join( ' ' )
|
26
|
-
end
|
27
|
-
|
28
|
-
def inspect # :nodoc:
|
29
|
-
"(#{ @points.map{|point| point.inspect}.join(', ')})"
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_xml_element # :nodoc:
|
33
|
-
xml_element = REXML::Element.new( XML_ELEMENT_NAME )
|
34
|
-
xml_element.add_text( self.to_s )
|
35
|
-
xml_element
|
36
|
-
end
|
37
|
-
|
38
|
-
# Two polygons are equivalent if their collection of points is equivalent.
|
39
|
-
def ==( other )
|
40
|
-
self.points == other.points
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.parse_polygon_string( polygon_string ) # :nodoc:
|
44
|
-
polygon_string.split( ' ' ).map{ |coordinate_string| coordinate_string.split( ',' ).map{|coordinate| coordinate.to_f }}
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.from_xml_element( polygon_xml_element ) # :nodoc:
|
48
|
-
coordinates = self.parse_polygon_string( polygon_xml_element.text )
|
49
|
-
points = coordinates.map{ |lattitude, longitude| RCAP::Point.new( :lattitude => lattitude, :longitude => longitude )}[0..-2]
|
50
|
-
polygon = self.new( :points => points )
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def to_yaml( options = {} ) # :nodoc:
|
55
|
-
yaml_points = self.points.map{ |point| [ point.lattitude, point.longitude ]}
|
56
|
-
def yaml_points.to_yaml_style; :inline; end
|
57
|
-
|
58
|
-
yaml_points.to_yaml( options )
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.from_yaml_data( polygon_yaml_data ) # :nodoc:
|
62
|
-
self.new(
|
63
|
-
:points => Array( polygon_yaml_data ).map{ |lattitude, longitude| Point.new( :lattitude => lattitude, :longitude => longitude )}
|
64
|
-
)
|
65
|
-
end
|
66
|
-
|
67
|
-
POINTS_KEY = 'points' # :nodoc:
|
68
|
-
|
69
|
-
def to_h # :nodoc:
|
70
|
-
{ POINTS_KEY => self.points.map{ |point| point.to_h }}
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.from_h( polygon_hash ) # :nodoc:
|
74
|
-
self.new( :points => polygon_hash[ POINTS_KEY ].map{ |point_hash| Point.from_h( point_hash )})
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/lib/rcap/resource.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
module RCAP
|
2
|
-
# A Resourse object is valid if
|
3
|
-
# * it has a resource description
|
4
|
-
class Resource
|
5
|
-
include Validation
|
6
|
-
|
7
|
-
# Resource Description
|
8
|
-
attr_accessor( :resource_desc )
|
9
|
-
attr_accessor( :mime_type )
|
10
|
-
# Expressed in bytes
|
11
|
-
attr_accessor( :size )
|
12
|
-
# Resource location
|
13
|
-
attr_accessor( :uri )
|
14
|
-
# Dereferenced URI - contents of URI Base64 encoded
|
15
|
-
attr_accessor( :deref_uri )
|
16
|
-
# SHA-1 hash of contents of resource
|
17
|
-
attr_accessor( :digest )
|
18
|
-
|
19
|
-
validates_presence_of( :resource_desc )
|
20
|
-
|
21
|
-
XML_ELEMENT_NAME = 'resource' # :nodoc:
|
22
|
-
MIME_TYPE_ELEMENT_NAME = 'mimeType' # :nodoc:
|
23
|
-
SIZE_ELEMENT_NAME = 'size' # :nodoc:
|
24
|
-
URI_ELEMENT_NAME = 'uri' # :nodoc:
|
25
|
-
DEREF_URI_ELEMENT_NAME = 'derefUri' # :nodoc:
|
26
|
-
DIGEST_ELEMENT_NAME = 'digest' # :nodoc:
|
27
|
-
RESOURCE_DESC_ELEMENT_NAME = 'resourceDesc' # :nodoc:
|
28
|
-
|
29
|
-
XPATH = "cap:#{ XML_ELEMENT_NAME }" # :nodoc:
|
30
|
-
MIME_TYPE_XPATH = "cap:#{ MIME_TYPE_ELEMENT_NAME }" # :nodoc:
|
31
|
-
SIZE_XPATH = "cap:#{ SIZE_ELEMENT_NAME }" # :nodoc:
|
32
|
-
URI_XPATH = "cap:#{ URI_ELEMENT_NAME }" # :nodoc:
|
33
|
-
DEREF_URI_XPATH = "cap:#{ DEREF_URI_ELEMENT_NAME }" # :nodoc:
|
34
|
-
DIGEST_XPATH = "cap:#{ DIGEST_ELEMENT_NAME }" # :nodoc:
|
35
|
-
RESOURCE_DESC_XPATH = "cap:#{ RESOURCE_DESC_ELEMENT_NAME }" # :nodoc:
|
36
|
-
|
37
|
-
def initialize( attributes = {} )
|
38
|
-
@mime_type = attributes[ :mime_type ]
|
39
|
-
@size = attributes[ :size ]
|
40
|
-
@uri = attributes[ :uri ]
|
41
|
-
@deref_uri = attributes[ :deref_uri ]
|
42
|
-
@digest = attributes[ :digest ]
|
43
|
-
@resource_desc = attributes[ :resource_desc ]
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_xml_element # :nodoc:
|
47
|
-
xml_element = REXML::Element.new( XML_ELEMENT_NAME )
|
48
|
-
xml_element.add_element( RESOURCE_DESC_ELEMENT_NAME ).add_text( self.resource_desc )
|
49
|
-
xml_element.add_element( MIME_TYPE_ELEMENT_NAME ).add_text( self.mime_type ) if self.mime_type
|
50
|
-
xml_element.add_element( SIZE_ELEMENT_NAME ).add_text( self.size ) if self.size
|
51
|
-
xml_element.add_element( URI_ELEMENT_NAME ).add_text( self.uri ) if self.uri
|
52
|
-
xml_element.add_element( DEREF_URI_ELEMENT_NAME ).add_text( self.deref_uri ) if self.deref_uri
|
53
|
-
xml_element.add_element( DIGEST_ELEMENT_NAME ).add_text( self.digest ) if self.digest
|
54
|
-
xml_element
|
55
|
-
end
|
56
|
-
|
57
|
-
# If size is defined returns the size in kilobytes
|
58
|
-
def size_in_kb
|
59
|
-
if self.size
|
60
|
-
self.size.to_f/1024
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def to_xml # :nodoc:
|
65
|
-
self.to_xml_element.to_s
|
66
|
-
end
|
67
|
-
|
68
|
-
def inspect # :nodoc:
|
69
|
-
[ self.resource_desc, self.uri, self.mime_type, self.size ? format( "%.1fKB", self.size_in_kb ) : nil ].compact.join(' - ')
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns a string representation of the resource of the form
|
73
|
-
# resource_desc
|
74
|
-
def to_s
|
75
|
-
self.resource_desc
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.from_xml_element( resource_xml_element ) # :nodoc:
|
79
|
-
resource = self.new( :resource_desc => RCAP.xpath_text( resource_xml_element, RESOURCE_DESC_XPATH ),
|
80
|
-
:uri => RCAP.xpath_text( resource_xml_element, URI_XPATH ),
|
81
|
-
:mime_type => RCAP.xpath_text( resource_xml_element, MIME_TYPE_XPATH ),
|
82
|
-
:deref_uri => RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH ),
|
83
|
-
:size => RCAP.xpath_text( resource_xml_element, SIZE_XPATH ),
|
84
|
-
:digest => RCAP.xpath_text( resource_xml_element, DIGEST_XPATH ))
|
85
|
-
end
|
86
|
-
|
87
|
-
RESOURCE_DESC_YAML = "Resource Description" # :nodoc:
|
88
|
-
URI_YAML = "URI" # :nodoc:
|
89
|
-
MIME_TYPE_YAML = "Mime Type" # :nodoc:
|
90
|
-
DEREF_URI_YAML = "Derefrenced URI Data" # :nodoc:
|
91
|
-
SIZE_YAML = "Size" # :nodoc:
|
92
|
-
DIGEST_YAML = "Digest" # :nodoc:
|
93
|
-
|
94
|
-
def to_yaml( options ) # :nodoc:
|
95
|
-
RCAP.attribute_values_to_hash(
|
96
|
-
[ RESOURCE_DESC_YAML, self.resource_desc ],
|
97
|
-
[ URI_YAML, self.uri ],
|
98
|
-
[ MIME_TYPE_YAML, self.mime_type ],
|
99
|
-
[ DEREF_URI_YAML, self.deref_uri ],
|
100
|
-
[ SIZE_YAML, self.size ],
|
101
|
-
[ DIGEST_YAML, self.digest ]
|
102
|
-
).to_yaml( options )
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.from_yaml_data( resource_yaml_data ) # :nodoc:
|
106
|
-
self.new(
|
107
|
-
:resource_desc => reource_yaml_data[ RESOURCE_DESC_YAML ],
|
108
|
-
:uri => reource_yaml_data[ URI_YAML ],
|
109
|
-
:mime_type => reource_yaml_data[ MIME_TYPE_YAML ],
|
110
|
-
:deref_uri => reource_yaml_data[ DEREF_URI_YAML ],
|
111
|
-
:size => reource_yaml_data[ SIZE_YAML ],
|
112
|
-
:digest => reource_yaml_data[ DIGEST_YAML ]
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
|
-
RESOURCE_DESC_KEY = 'resource_desc' # :nodoc:
|
117
|
-
URI_KEY = 'uri' # :nodoc:
|
118
|
-
MIME_TYPE_KEY = 'mime_type' # :nodoc:
|
119
|
-
DEREF_URI_KEY = 'deref_uri' # :nodoc:
|
120
|
-
SIZE_KEY = 'size' # :nodoc:
|
121
|
-
DIGEST_KEY = 'digest' # :nodoc:
|
122
|
-
|
123
|
-
def to_h # :nodoc:
|
124
|
-
RCAP.attribute_values_to_hash(
|
125
|
-
[ RESOURCE_DESC_KEY, self.resource_desc ],
|
126
|
-
[ URI_KEY, self.uri],
|
127
|
-
[ MIME_TYPE_KEY, self.mime_type],
|
128
|
-
[ DEREF_URI_KEY, self.deref_uri],
|
129
|
-
[ SIZE_KEY, self.size ],
|
130
|
-
[ DIGEST_KEY, self.digest ])
|
131
|
-
end
|
132
|
-
|
133
|
-
def self.from_h( resource_hash ) # :nodoc:
|
134
|
-
self.new(
|
135
|
-
:resource_desc => resource_hash[ RESOURCE_DESC_KEY ],
|
136
|
-
:uri => resource_hash[ URI_KEY ],
|
137
|
-
:mime_type => resource_hash[ MIME_TYPE_KEY ],
|
138
|
-
:deref_uri => resource_hash[ DEREF_URI_KEY ],
|
139
|
-
:size => resource_hash[ SIZE_KEY ],
|
140
|
-
:digest => resource_hash[ DIGEST_KEY ])
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
data/spec/area_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe( RCAP::Area ) do
|
4
|
-
context( 'on initialisation' ) do
|
5
|
-
before( :each ) do
|
6
|
-
@area = RCAP::Area.new
|
7
|
-
end
|
8
|
-
|
9
|
-
# Atomic
|
10
|
-
it( 'should not have a area_desc' ){ @area.area_desc.should( be_nil )}
|
11
|
-
it( 'should not have a altitude' ){ @area.altitude.should( be_nil )}
|
12
|
-
it( 'should not have a ceiling' ){ @area.ceiling.should( be_nil )}
|
13
|
-
|
14
|
-
# Group
|
15
|
-
it( 'should have an empty polygons' ){ @area.polygons.should( be_empty )}
|
16
|
-
it( 'should have an empty circles' ){ @area.circles.should( be_empty )}
|
17
|
-
it( 'should have an empty geocodes' ){ @area.geocodes.should( be_empty )}
|
18
|
-
|
19
|
-
shared_examples_for( "it can parse into an Area object" ) do
|
20
|
-
it( 'should parse the area_desc correctly' ) do
|
21
|
-
@area.area_desc.should == @original_area.area_desc
|
22
|
-
end
|
23
|
-
|
24
|
-
it( 'should parse the altitude correctly' ) do
|
25
|
-
@area.altitude.should == @original_area.altitude
|
26
|
-
end
|
27
|
-
|
28
|
-
it( 'should parse the ceiling correctly' ) do
|
29
|
-
@area.ceiling.should == @original_area.ceiling
|
30
|
-
end
|
31
|
-
|
32
|
-
it( 'should parse the circles correctly' ) do
|
33
|
-
@area.circles.should == @original_area.circles
|
34
|
-
end
|
35
|
-
|
36
|
-
it( 'should parse the geocodes correctly' ) do
|
37
|
-
@area.geocodes.should == @original_area.geocodes
|
38
|
-
end
|
39
|
-
|
40
|
-
it( 'should parse the polygons correctly' ) do
|
41
|
-
@area.polygons.should == @original_area.polygons
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context( 'from XML' ) do
|
46
|
-
before( :each ) do
|
47
|
-
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
48
|
-
:altitude => 100,
|
49
|
-
:ceiling => 200,
|
50
|
-
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
51
|
-
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
52
|
-
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
53
|
-
|
54
|
-
@alert = RCAP::Alert.new( :infos => RCAP::Info.new( :areas => @original_area ))
|
55
|
-
@xml_string = @alert.to_xml
|
56
|
-
@xml_document = REXML::Document.new( @xml_string )
|
57
|
-
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
|
58
|
-
@area_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::Area::XPATH )
|
59
|
-
@area = RCAP::Area.from_xml_element( @area_xml_element )
|
60
|
-
end
|
61
|
-
|
62
|
-
it_should_behave_like( "it can parse into an Area object" )
|
63
|
-
end
|
64
|
-
|
65
|
-
context( 'from a hash' ) do
|
66
|
-
before( :each ) do
|
67
|
-
@original_area = RCAP::Area.new( :area_desc => 'Area Description',
|
68
|
-
:altitude => 100,
|
69
|
-
:ceiling => 200,
|
70
|
-
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
71
|
-
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
72
|
-
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
73
|
-
|
74
|
-
@area = RCAP::Area.from_h( @original_area.to_h )
|
75
|
-
end
|
76
|
-
|
77
|
-
it_should_behave_like( "it can parse into an Area object" )
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context( 'when exported' ) do
|
82
|
-
before( :each ) do
|
83
|
-
@area = RCAP::Area.new( :area_desc => 'Area Description',
|
84
|
-
:altitude => 100,
|
85
|
-
:ceiling => 200,
|
86
|
-
:circles => RCAP::Circle.new( :lattitude => 0, :longitude => 0 , :radius => 100 ),
|
87
|
-
:geocodes => RCAP::Geocode.new( :name => 'name', :value => 'value' ),
|
88
|
-
:polygons => RCAP::Polygon.new( :points => RCAP::Point.new( :lattitude =>1, :longitude => 1 )))
|
89
|
-
end
|
90
|
-
context( 'to a hash' ) do
|
91
|
-
before( :each ) do
|
92
|
-
@area_hash = @area.to_h
|
93
|
-
end
|
94
|
-
|
95
|
-
it( 'should export the area description correctly' ) do
|
96
|
-
@area_hash[ RCAP::Area::AREA_DESC_KEY ].should == @area.area_desc
|
97
|
-
end
|
98
|
-
|
99
|
-
it( 'should export the altitude correctly' ) do
|
100
|
-
@area_hash[ RCAP::Area::ALTITUDE_KEY ].should == @area.altitude
|
101
|
-
end
|
102
|
-
|
103
|
-
it( 'should set the ceiling correctly' ) do
|
104
|
-
@area_hash[ RCAP::Area::CEILING_KEY ].should == @area.ceiling
|
105
|
-
end
|
106
|
-
|
107
|
-
it( 'should export the circles correctly' ) do
|
108
|
-
@area_hash[ RCAP::Area::CIRCLES_KEY ].should == @area.circles.map{ |circle| circle.to_h }
|
109
|
-
end
|
110
|
-
|
111
|
-
it( 'should export the geocodes correctly' ) do
|
112
|
-
@area_hash[ RCAP::Area::GEOCODES_KEY ].should == @area.geocodes.map{ |geocode| geocode.to_h }
|
113
|
-
end
|
114
|
-
|
115
|
-
it( 'should export the polygons correctly' ) do
|
116
|
-
@area_hash[ RCAP::Area::POLYGONS_KEY ].should == @area.polygons.map{ |polygon| polygon.to_h }
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context( 'is not valid if' ) do
|
122
|
-
before( :each ) do
|
123
|
-
@area = RCAP::Area.new( :area_desc => "Cape Town Metropole" )
|
124
|
-
@area.should( be_valid )
|
125
|
-
end
|
126
|
-
|
127
|
-
it( 'does not have an area descrtiption (area_desc)') do
|
128
|
-
@area.area_desc = nil
|
129
|
-
@area.should_not( be_valid )
|
130
|
-
end
|
131
|
-
|
132
|
-
it( 'has a ceiling defined but no altitude' ) do
|
133
|
-
@area.ceiling = 1
|
134
|
-
@area.altitude = nil
|
135
|
-
@area.should_not( be_valid )
|
136
|
-
end
|
137
|
-
|
138
|
-
context( 'it contains circles and it' ) do
|
139
|
-
before( :each ) do
|
140
|
-
@area.circles << RCAP::Circle.new( :lattitude => 0, :longitude => 0, :radius => 1)
|
141
|
-
@area.should( be_valid )
|
142
|
-
end
|
143
|
-
|
144
|
-
it( 'has an invalid circle' ) do
|
145
|
-
@area.circles.first.lattitude = nil
|
146
|
-
@area.should_not( be_valid )
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context( 'it contains polygons and it' ) do
|
151
|
-
before( :each ) do
|
152
|
-
@polygon = RCAP::Polygon.new
|
153
|
-
@polygon.points.push( RCAP::Point.new( :lattitude => 0, :longitude => 0 ),
|
154
|
-
RCAP::Point.new( :lattitude => 0, :longitude => 1 ),
|
155
|
-
RCAP::Point.new( :lattitude => 1, :longitude => 0 ))
|
156
|
-
@area.polygons << @polygon
|
157
|
-
@area.should( be_valid )
|
158
|
-
end
|
159
|
-
|
160
|
-
it( 'has an invalid polygon' ) do
|
161
|
-
@polygon.points.first.lattitude = nil
|
162
|
-
@area.should_not( be_valid )
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context( 'it contains geocodes and it' ) do
|
167
|
-
before( :each ) do
|
168
|
-
@geocode = RCAP::Geocode.new( :name => 'foo', :value => 'bar' )
|
169
|
-
@area.geocodes << @geocode
|
170
|
-
@area.should( be_valid )
|
171
|
-
end
|
172
|
-
|
173
|
-
it( 'has an invalid geocode' ) do
|
174
|
-
@geocode.value = nil
|
175
|
-
@area.should_not( be_valid )
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|