class Opium::GeoPoint
Constants
- NULL_ISLAND
Attributes
latitude[RW]
longitude[RW]
Public Class Methods
===( other )
click to toggle source
Calls superclass method
# File lib/opium/extensions/geo_point.rb, line 51 def ===( other ) other != NULL_ISLAND && super end
new( value )
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 5 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
to_parse(object)
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 59 def to_parse(object) object.to_geo_point.to_parse end
to_ruby(object)
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 55 def to_ruby(object) object.to_geo_point unless object.nil? end
Public Instance Methods
<=>( geo_point )
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 33 def <=>( geo_point ) return nil unless geo_point.is_a?( self.class ) [self.latitude, self.longitude] <=> [geo_point.latitude, geo_point.longitude] end
===( other )
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 38 def ===( other ) if other.is_a? self.class self == other elsif other <= self.class self != NULL_ISLAND else nil end end
to_geo_point()
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 21 def to_geo_point self end
to_parse()
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 25 def to_parse { "__type" => "GeoPoint", "latitude" => self.latitude, "longitude" => self.longitude } end
to_s()
click to toggle source
# File lib/opium/extensions/geo_point.rb, line 29 def to_s "#{ self.latitude },#{ self.longitude }" end