Skip to content

Instantly share code, notes, and snippets.

@forrestwilkins
Created January 26, 2015 19:14
Show Gist options
  • Save forrestwilkins/40153078e21f31b9a151 to your computer and use it in GitHub Desktop.
Save forrestwilkins/40153078e21f31b9a151 to your computer and use it in GitHub Desktop.
def close_enough(content)
_close_enough = false
# content always close enough when inside current users zip code or cherry picked tab
if content.zip_code and self.zip_code and content.zip_code == self.zip_code or (content.is_a? Tab and \
content.features.where(user_id: self.id).where(action: :cherry_pick).present?)
_close_enough = true
# close enough when within the users specified network size
elsif content.latitude and self.latitude and self.network_size and \
GeoDistance.distance(content.latitude, content.longitude, self.latitude,
self.longitude).miles.number < self.network_size
return true
# if previous checks fail, allows
# content access to branch out proportionately
# as the local or global communities expand
elsif content.zip_code.present?
case content.class
when Post
# the more content in a given area, the less likely it is
# for any particular item from that area to show
near_content = Post.where(zip_code: content.zip_code).size
# gets number of posts with the same zip code and is close
# enough when a random value between 0 and the size of all
# content is less than the number with the same zip code
_close_enough = true if near_content < Random.rand(0..Post.all.size)
when Tab
near_content = Tab.where(zip_code: content.zip_code).size
_close_enough = true if near_content < Random.rand(0..Tab.all.size)
end
else
_close_enough = true
end
return _close_enough
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment