Created
May 14, 2017 09:15
-
-
Save kopylovvlad/c6636742f01cea09a80bff8e330f60df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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