Created
May 17, 2011 17:31
-
-
Save trabianmatt/976920 to your computer and use it in GitHub Desktop.
This file contains 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
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