Class: Opium::GeoPoint
Instance Attribute Summary collapse
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ GeoPoint
constructor
A new instance of GeoPoint.
- #to_geo_point ⇒ Object
- #to_parse ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ GeoPoint
Returns a new instance of GeoPoint.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/opium/extensions/geo_point.rb', line 3 def initialize( value ) self.latitude, self.longitude = * case value when Hash [value[:latitude] || value['latitude'], value[:longitude] || value['longitude']] when Array [value.first, value.last] when /^[+-]?\d+(\.\d+)?\s*,\s*[+-]?\d+(\.\d+)?$/ value.split(',').map {|c| c.to_f} else raise ArgumentError.new( "invalid value for GeoPoint: \"#{ value }\"" ) end end |
Instance Attribute Details
#latitude ⇒ Object
Returns the value of attribute latitude.
17 18 19 |
# File 'lib/opium/extensions/geo_point.rb', line 17 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
17 18 19 |
# File 'lib/opium/extensions/geo_point.rb', line 17 def longitude @longitude end |
Class Method Details
.to_parse(object) ⇒ Object
36 37 38 |
# File 'lib/opium/extensions/geo_point.rb', line 36 def to_parse(object) object.to_geo_point.to_parse end |
.to_ruby(object) ⇒ Object
32 33 34 |
# File 'lib/opium/extensions/geo_point.rb', line 32 def to_ruby(object) object.to_geo_point unless object.nil? end |
Instance Method Details
#to_geo_point ⇒ Object
19 20 21 |
# File 'lib/opium/extensions/geo_point.rb', line 19 def to_geo_point self end |
#to_parse ⇒ Object
23 24 25 |
# File 'lib/opium/extensions/geo_point.rb', line 23 def to_parse { "__type" => "GeoPoint", "latitude" => self.latitude, "longitude" => self.longitude } end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/opium/extensions/geo_point.rb', line 27 def to_s "#{ self.latitude },#{ self.longitude }" end |