class Misc::GeoPoint

Point Class

Public Class Methods

new(lat: nil, lng: nil, latlng: nil, geo_hash: nil) click to toggle source

@params [Numeric] lat latitude @params [Numeric] lng longitude @params [Array|String] latlng

latitude and longitude as array or string
Format in [lon, lat] when array, such as [-70,40]
Format in lat,lon when string, such as '40,-70'

@params [String] geohash point geohash

# File lib/misc/geo_point.rb, line 15
def initialize(lat: nil, lng: nil, latlng: nil, geo_hash: nil)
  if lat.present? && lng.present?
    @lat = lat.to_f
    @lng = lng.to_f
    @type = :float
  elsif latlng.present?
    @latlng = latlng
    @type = latlng.class.name.downcase.intern
  elsif geo_hash.present?
    @geo_hash = geo_hash
    @type = :geohash
  else
    raise 'Provide Point as floating values latitude and longitude
           or a string or an array or a geohash'
  end
end

Public Instance Methods

geo_hash_expr() click to toggle source

@!visibility protected

# File lib/misc/geo_point.rb, line 60
def geo_hash_expr
  @geo_hash
end
lat_expr() click to toggle source

@!visibility protected

# File lib/misc/geo_point.rb, line 45
def lat_expr
  @lat
end
latlng_expr() click to toggle source

@!visibility protected

# File lib/misc/geo_point.rb, line 55
def latlng_expr
  @latlng
end
lng_expr() click to toggle source

@!visibility protected

# File lib/misc/geo_point.rb, line 50
def lng_expr
  @lng
end
settings() click to toggle source

@return [Hash] serialized json query for object

# File lib/misc/geo_point.rb, line 33
def settings
  case @type
  when :float
    { lat: @lat, lon: @lng }
  when :array || :string
    @latlng
  when :geohash
    @geohash
  end
end