Skip to content

Instantly share code, notes, and snippets.

@kopylovvlad
Created May 14, 2017 09:15
Show Gist options
  • Save kopylovvlad/c6636742f01cea09a80bff8e330f60df to your computer and use it in GitHub Desktop.
Save kopylovvlad/c6636742f01cea09a80bff8e330f60df to your computer and use it in GitHub Desktop.
class GeoCoordinate
def initialize(latitude, longitude)
@latitude = latitude
@longitude = longitude
end
##
# returns array
def nearest_coordinates
# magic
end
##
# returns integer
def nearest_coordinates_count
# magic
end
##
# may returns false, nil, <GeoCoordinate>, or array :)
def three_nearest_coordinates
return false unless @latitude.present? and @longitude.present?
case nearest_coordinates_count
when 0
return nil
when 1
nearest_coordinates.limit(1).first
when 2
nearest_coordinates.limit(2)
when 3
nearest_coordinates.limit(3)
else
nearest_coordinates.limit(3)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment