Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FacetOptionizer
- def initialize(params)
- @params = params
- strip_blanks!
- end
- def generate
- {:conditions => @params[:conditions],
- :geo => geo,
- :with => {:@geodist => geodist,
- :bounty => bounty,
- :category_search => category_search,
- :created_at => created_at},
- :order => order}
- end
- def strip_blanks!
- @params.reject! {|k, v| v.empty? }
- end
- def order
- @params[:order] || "bounty DESC"
- end
- def geo
- [@params[:current_location].lat, @params[:current_location].lng].map(&:to_radians)
- end
- def category_search
- @params[:category].gsub('&', '').to_crc32 if @params[:category]
- end
- def geodist
- # return 100,000,000.0 if "any" or nil
- @params[:distance].to_i.zero? ? 100_000_000.0 : @params[:distance].to_f.to_miles
- end
- def bounty
- price_start = @params[:price_range_start]
- price_end = @params[:price_range_end]
- (price_start.to_f)..(price_end.to_f) if price_start && price_end
- end
- def created_at
- start_date = @params[:start_date]
- end_date = @params[:end_date]
- (start_date.to_time)..(end_date.to_time.end_of_day) if start_date && end_date
- end
- end
Add Comment
Please, Sign In to add comment