Class: Circle
- Includes:
- Validation
- Defined in:
- lib/generators/rcap/models/templates/models/circle.rb
Overview
A Circle object is valid if
-
it has a valid lattitude and longitude
-
it has a radius with a value greater than zero
Constant Summary collapse
- XML_ELEMENT_NAME =
:nodoc:
'circle'
- XPATH =
:nodoc:
'cap:circle'
- RADIUS_KEY =
:nodoc:
'radius'
- LATTITUDE_KEY =
:nodoc:
'lattitude'
- LONGITUDE_KEY =
:nodoc:
'longitude'
Constants inherited from Point
Point::LATITUDE_KEY, Point::MAX_LATITUDE, Point::MAX_LONGITUDE, Point::MIN_LATITUDE, Point::MIN_LONGITUDE
Instance Attribute Summary collapse
-
#radius ⇒ Object
Expresed in kilometers.
Attributes inherited from Point
Class Method Summary collapse
-
.from_h(circle_hash) ⇒ Object
:nodoc:.
-
.from_xml_element(circle_xml_element) ⇒ Object
:nodoc:.
-
.from_yaml_data(circle_yaml_data) ⇒ Object
:nodoc:.
-
.parse_circle_string(circle_string) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two circles are equivalent if their lattitude, longitude and radius are equal.
-
#initialize(attributes = {}) ⇒ Circle
constructor
A new instance of Circle.
-
#inspect ⇒ Object
:nodoc:.
-
#to_h ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
Returns a string representation of the circle of the form lattitude,longitude,radius.
-
#to_xml ⇒ Object
:nodoc:.
-
#to_xml_element ⇒ Object
:nodoc:.
Constructor Details
#initialize(attributes = {}) ⇒ Circle
Returns a new instance of Circle.
17 18 19 20 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 17 def initialize( attributes = {} ) super( attributes ) @radius = attributes[ :radius ] end |
Instance Attribute Details
#radius ⇒ Object
Expresed in kilometers
8 9 10 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 8 def radius @radius end |
Class Method Details
.from_h(circle_hash) ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 73 def self.from_h( circle_hash ) # :nodoc: self.new( :radius => circle_hash[ RADIUS_KEY ], :lattitude => circle_hash[ LATTITUDE_KEY ], :longitude => circle_hash[ LONGITUDE_KEY ]) end |
.from_xml_element(circle_xml_element) ⇒ Object
:nodoc:
47 48 49 50 51 52 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 47 def self.from_xml_element( circle_xml_element ) # :nodoc: lattitude, longitude, radius = self.parse_circle_string( circle_xml_element.text ) circle = self.new( :lattitude => lattitude, :longitude => longitude, :radius => radius ) end |
.from_yaml_data(circle_yaml_data) ⇒ Object
:nodoc:
59 60 61 62 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 59 def self.from_yaml_data( circle_yaml_data ) # :nodoc: lattitude, longitude,radius = circle_yaml_data self.new( :lattitude => lattitude, :longitude => longitude, :radius => radius ) end |
.parse_circle_string(circle_string) ⇒ Object
:nodoc:
42 43 44 45 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 42 def self.parse_circle_string( circle_string ) # :nodoc: lattitude, longitude, radius = circle_string.split( ',' ) [ lattitude, longitude, radius ].map{ |e| e.to_f } end |
Instance Method Details
#==(other) ⇒ Object
Two circles are equivalent if their lattitude, longitude and radius are equal.
55 56 57 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 55 def ==( other ) [ self.lattitude, self.longitude, self.radius ] == [ other.lattitude, other.longitude, other.radius ] end |
#inspect ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 28 def inspect # :nodoc: "(#{ self.lattitude},#{ self.longitude },#{ self.radius })" end |
#to_h ⇒ Object
:nodoc:
67 68 69 70 71 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 67 def to_h # :nodoc: RCAP.attribute_values_to_hash( [ RADIUS_KEY, self.radius ], [ LATTITUDE_KEY, self.lattitude ], [ LONGITUDE_KEY, self.longitude ]) end |
#to_s ⇒ Object
Returns a string representation of the circle of the form
lattitude,longitude,radius
24 25 26 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 24 def to_s # :nodoc: "#{ self.lattitude },#{ self.longitude },#{ self.radius }" end |
#to_xml ⇒ Object
:nodoc:
38 39 40 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 38 def to_xml # :nodoc: self.to_xml_element.to_s end |
#to_xml_element ⇒ Object
:nodoc:
32 33 34 35 36 |
# File 'lib/generators/rcap/models/templates/models/circle.rb', line 32 def to_xml_element # :nodoc: xml_element = REXML::Element.new( XML_ELEMENT_NAME ) xml_element.add_text( self.to_s ) xml_element end |