Skip to content

Instantly share code, notes, and snippets.

@trabianmatt
Created May 17, 2011 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trabianmatt/976920 to your computer and use it in GitHub Desktop.
Save trabianmatt/976920 to your computer and use it in GitHub Desktop.
def within_box_or_near(location_class, box, center)
box.present? ? location_class.within_box(box) : location_class.near(center)
end
def filter(params)
locations = {}
within_box_or_near(Location.class_for_provider(services.shift), @box, @center).each do |location|
locations[location.loc_hash] = location
end
services.each do |service|
within_box_or_near(Location.class_for_provider(service), @box, @center).each do |location|
# Look for an existing location in the same physical location
primary_location = locations[location.loc_hash]
if primary_location.present?
# Merge location data for locations in the same physical location
primary_location.write_attributes location.attributes
else
# Add the location if the service should be included in the results
locations[location.loc_hash] = location if service.should_be_included?
end
end
end
locations
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment