Class: Point
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Point
- Includes:
- Validation
- Defined in:
- lib/generators/rcap/models/templates/models/point.rb
Overview
A Point object is valid if
-
it has a latitude within the minimum and maximum latitude values
-
it has a longitude within the minimum and maximum longitude values
Direct Known Subclasses
Constant Summary collapse
- MAX_LONGITUDE =
180
- MIN_LONGITUDE =
-180
- MAX_LATITUDE =
90
- MIN_LATITUDE =
-90
- LATITUDE_KEY =
:nodoc:
'latitude_hash'
- LONGITUDE_KEY =
:nodoc:
'longitude_hash'
Instance Attribute Summary collapse
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
Class Method Summary collapse
-
.from_h(point_hash) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two points are equivalent if they have the same latitude and longitude.
-
#initialize(attributes = {}) ⇒ Point
constructor
A new instance of Point.
-
#inspect ⇒ Object
:nodoc:.
-
#to_h ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
Returns a string representation of the point of the form latitude,longitude.
Constructor Details
#initialize(attributes = {}) ⇒ Point
Returns a new instance of Point.
19 20 21 22 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 19 def initialize( attributes = {} ) @latitude = attributes[ :latitude ] @longitude = attributes[ :longitude ] end |
Instance Attribute Details
#latitude ⇒ Object
Returns the value of attribute latitude.
12 13 14 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 12 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
13 14 15 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 13 def longitude @longitude end |
Class Method Details
.from_h(point_hash) ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 48 def self.from_h( point_hash ) # :nodoc: self.new( :latitude => point_hash[ LATITUDE_KEY ], :longitude => point_hash[ LONGITUDE_KEY ]) end |
Instance Method Details
#==(other) ⇒ Object
Two points are equivalent if they have the same latitude and longitude
35 36 37 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 35 def ==( other ) [ self.latitude, self.longitude ] == [ other.latitude, other.longitude ] end |
#inspect ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 30 def inspect # :nodoc: '('+self.to_s+')' end |
#to_h ⇒ Object
:nodoc:
42 43 44 45 46 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 42 def to_h # :nodoc: RCAP.attribute_values_to_hash( [ LATITUDE_KEY, self.latitude ], [ LONGITUDE_KEY, self.longitude ]) end |
#to_s ⇒ Object
Returns a string representation of the point of the form
latitude,longitude
26 27 28 |
# File 'lib/generators/rcap/models/templates/models/point.rb', line 26 def to_s "#{ self.latitude },#{ self.longitude }" end |