Skip to content

Instantly share code, notes, and snippets.

@forrestwilkins
Last active August 29, 2015 14:08
Show Gist options
  • Save forrestwilkins/e5cde8685c2eeae72547 to your computer and use it in GitHub Desktop.
Save forrestwilkins/e5cde8685c2eeae72547 to your computer and use it in GitHub Desktop.
ZIP_CODE_RANGE = 10
def close_enough(content)
_close_enough = false
zips_in_range = []
for zip in Zip.all
if self.zip_code and self.network_size and content.zip_code
if (self.zip_code - zip.zip_code).abs < ZIP_CODE_RANGE + self.network_size
zips_in_range << zip.zip_code
end
end
end
# sorts by difference
zips_in_range.sort_by! do |zip|
(self.zip_code - zip).abs
end
# removes the most different and searches for match
for zip in zips_in_range.reverse.drop zips_in_range.size / 5
if content.zip_code == zip
_close_enough = true
end
end
return _close_enough
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment