Class: Opium::GeoPoint

Inherits:
Object show all
Defined in:
lib/opium/extensions/geo_point.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#latitudeObject

Returns the value of attribute latitude.



17
18
19
# File 'lib/opium/extensions/geo_point.rb', line 17

def latitude
  @latitude
end

#longitudeObject

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_pointObject



19
20
21
# File 'lib/opium/extensions/geo_point.rb', line 19

def to_geo_point
  self
end

#to_parseObject



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_sObject



27
28
29
# File 'lib/opium/extensions/geo_point.rb', line 27

def to_s
  "#{ self.latitude },#{ self.longitude }"
end