Class: RCAP::Base::Circle
- Inherits:
-
Point
- Object
- Point
- RCAP::Base::Circle
show all
- Includes:
- Validation
- Defined in:
- lib/rcap/base/circle.rb
Constant Summary
- XML_ELEMENT_NAME =
'circle'
- XPATH =
'cap:circle'
- RADIUS_KEY =
'radius'
- RADIUS_INDEX =
2
Constants inherited
from Point
Point::LATTITUDE_INDEX, Point::LATTITUDE_KEY, Point::LONGITUDE_INDEX, Point::LONGITUDE_KEY, Point::MAX_LATTITUDE, Point::MAX_LONGITUDE, Point::MIN_LATTITUDE, Point::MIN_LONGITUDE
Instance Attribute Summary (collapse)
Attributes inherited from Point
#lattitude, #longitude
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Constructor Details
- (Circle) initialize {|_self| ... }
20
21
22
|
# File 'lib/rcap/base/circle.rb', line 20
def initialize
yield( self ) if block_given?
end
|
Instance Attribute Details
- (Numeric) radius
7
8
9
|
# File 'lib/rcap/base/circle.rb', line 7
def radius
@radius
end
|
Class Method Details
+ (Circle) from_a(circle_array)
112
113
114
115
116
117
118
|
# File 'lib/rcap/base/circle.rb', line 112
def self.from_a( circle_array )
self.new do |circle|
circle.longitude = circle_array[ LONGITUDE_INDEX ].to_f
circle.lattitude = circle_array[ LATTITUDE_INDEX ].to_f
circle.radius = circle_array[ RADIUS_INDEX ].to_f
end
end
|
+ (Circle) from_h(circle_hash)
95
96
97
98
99
100
101
|
# File 'lib/rcap/base/circle.rb', line 95
def self.from_h( circle_hash )
self.new do |circle|
circle.radius = circle_hash[ RADIUS_KEY ].to_f
circle.lattitude = circle_hash[ LATTITUDE_KEY ].to_f
circle.longitude = circle_hash[ LONGITUDE_KEY ].to_f
end
end
|
+ (Circle) from_xml_element(circle_xml_element)
62
63
64
|
# File 'lib/rcap/base/circle.rb', line 62
def self.from_xml_element( circle_xml_element )
self.from_a( self.parse_circle_string( circle_xml_element.text ))
end
|
+ (Circle) from_yaml_data(circle_yaml_data)
76
77
78
79
80
81
82
83
|
# File 'lib/rcap/base/circle.rb', line 76
def self.from_yaml_data( circle_yaml_data )
lattitude, longitude, radius = circle_yaml_data
self.new do |circle|
circle.lattitude = lattitude.to_f
circle.longitude = longitude.to_f
circle.radius = radius.to_f
end
end
|
+ (Array(Float,Float,Float)) parse_circle_string(circle_string)
Parses a circle string of the form
lattitude,longitude radius
54
55
56
57
58
|
# File 'lib/rcap/base/circle.rb', line 54
def self.parse_circle_string( circle_string )
coordinates, radius = circle_string.split( ' ' )
lattitude, longitude = coordinates.split( ',' )
[ lattitude, longitude, radius ].map{ |e| e.to_f }
end
|
Instance Method Details
- (true, false) ==(other)
Two circles are equivalent if their lattitude, longitude and radius are
equal.
70
71
72
|
# File 'lib/rcap/base/circle.rb', line 70
def ==( other )
self.to_a == other.to_a
end
|
33
34
35
|
# File 'lib/rcap/base/circle.rb', line 33
def inspect
"(#{ self.to_s })"
end
|
- (Array(Numeric,Numeric,Numeric)) to_a
104
105
106
|
# File 'lib/rcap/base/circle.rb', line 104
def to_a
[ @lattitude, @longitude, @radius ]
end
|
- (Hash) to_h
87
88
89
90
91
|
# File 'lib/rcap/base/circle.rb', line 87
def to_h
RCAP.attribute_values_to_hash( [ RADIUS_KEY, @radius ],
[ LATTITUDE_KEY, @lattitude ],
[ LONGITUDE_KEY, @longitude ])
end
|
Returns a string representation of the circle of the form
lattitude,longitude radius
28
29
30
|
# File 'lib/rcap/base/circle.rb', line 28
def to_s
"#{ @lattitude },#{ @longitude } #{ @radius }"
end
|
45
46
47
|
# File 'lib/rcap/base/circle.rb', line 45
def to_xml
self.to_xml_element.to_s
end
|
- (REXML::Element) to_xml_element
38
39
40
41
42
|
# File 'lib/rcap/base/circle.rb', line 38
def to_xml_element
xml_element = REXML::Element.new( XML_ELEMENT_NAME )
xml_element.add_text( self.to_s )
xml_element
end
|