class Stall::ProductFilters::PriceFilter

Public Instance Methods

available?() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 4
def available?
  options[:force] || min != max
end
max() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 13
def max
  return 0 unless variants.any?
  variants.order(price_cents: :desc).first.price.to_d.ceil
end
min() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 8
def min
  return 0 unless variants.any?
  variants.order(price_cents: :asc).first.price.to_d.floor
end
param() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 18
def param
  :variants_price_cents_between_cents
end
ticks() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 22
def ticks
  min_tick = (min / 10.0).floor
  max_tick = (max / 10.0).ceil
  ticks_count = 4

  (ticks_count + 1).times.map do |index|
    ((((max_tick - min_tick) / ticks_count.to_f) * index) + min_tick).to_i * 10
  end
end

Private Instance Methods

variants() click to toggle source
# File lib/stall/product_filters/price_filter.rb, line 34
def variants
  @variants ||= Variant.where(product: products)
end