Skip to content

Instantly share code, notes, and snippets.

@kopylovvlad
Created May 14, 2017 09:16
Show Gist options
  • Save kopylovvlad/5bcb1078d439434fb607d12710b37700 to your computer and use it in GitHub Desktop.
Save kopylovvlad/5bcb1078d439434fb607d12710b37700 to your computer and use it in GitHub Desktop.
class GeoCoordinate
# some code
##
# returns array
def three_nearest_coordinates
return [] unless @latitude.present? and @longitude.present?
coords_count = nearest_coordinates_count
case coords_count
when 0
return []
when ->(integer) { [1, 2, 3].include?(integer) }
nearest_coordinates.limit(coords_count)
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