Guest User

Untitled

a guest
Feb 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. class FacetOptionizer
  2.  
  3. def initialize(params)
  4. @params = params
  5. strip_blanks!
  6. end
  7.  
  8. def generate
  9. {:conditions => @params[:conditions],
  10. :geo => geo,
  11. :with => {:@geodist => geodist,
  12. :bounty => bounty,
  13. :category_search => category_search,
  14. :created_at => created_at},
  15. :order => order}
  16. end
  17.  
  18. def strip_blanks!
  19. @params.reject! {|k, v| v.empty? }
  20. end
  21.  
  22. def order
  23. @params[:order] || "bounty DESC"
  24. end
  25.  
  26. def geo
  27. [@params[:current_location].lat, @params[:current_location].lng].map(&:to_radians)
  28. end
  29.  
  30. def category_search
  31. @params[:category].gsub('&', '').to_crc32 if @params[:category]
  32. end
  33.  
  34. def geodist
  35. # return 100,000,000.0 if "any" or nil
  36. @params[:distance].to_i.zero? ? 100_000_000.0 : @params[:distance].to_f.to_miles
  37. end
  38.  
  39. def bounty
  40. price_start = @params[:price_range_start]
  41. price_end = @params[:price_range_end]
  42.  
  43. (price_start.to_f)..(price_end.to_f) if price_start && price_end
  44. end
  45.  
  46. def created_at
  47. start_date = @params[:start_date]
  48. end_date = @params[:end_date]
  49.  
  50. (start_date.to_time)..(end_date.to_time.end_of_day) if start_date && end_date
  51. end
  52.  
  53. end
Add Comment
Please, Sign In to add comment