Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- # this last check is only run if both failed
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement