Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. def close_enough(content)
  2. _close_enough = false
  3. # content always close enough when inside current users zip code or cherry picked tab
  4. if content.zip_code and self.zip_code and content.zip_code == self.zip_code or (content.is_a? Tab and \
  5. content.features.where(user_id: self.id).where(action: :cherry_pick).present?)
  6. _close_enough = true
  7. # close enough when within the users specified network size
  8. elsif content.latitude and self.latitude and self.network_size and \
  9. GeoDistance.distance(content.latitude, content.longitude, self.latitude,
  10. self.longitude).miles.number < self.network_size
  11. return true
  12. # if previous checks fail, allows
  13. # content access to branch out proportionately
  14. # as the local or global communities expand.
  15. # this last check is only run if both failed
  16. elsif content.zip_code.present?
  17. case content.class
  18. when Post
  19. # the more content in a given area, the less likely it is
  20. # for any particular item from that area to show
  21. near_content = Post.where(zip_code: content.zip_code).size
  22. # gets number of posts with the same zip code and is close
  23. # enough when a random value between 0 and the size of all
  24. # content is less than the number with the same zip code
  25. _close_enough = true if near_content < Random.rand(0..Post.all.size)
  26. when Tab
  27. near_content = Tab.where(zip_code: content.zip_code).size
  28. _close_enough = true if near_content < Random.rand(0..Tab.all.size)
  29. end
  30. else
  31. _close_enough = true
  32. end
  33. return _close_enough
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement