Class: Stall::ProductFilters::PriceFilter

Inherits:
BaseFilter
  • Object
show all
Defined in:
lib/stall/product_filters/price_filter.rb

Instance Attribute Summary

Attributes inherited from BaseFilter

#options, #products

Instance Method Summary collapse

Methods inherited from BaseFilter

#initialize, #key, #label, #name, #partial_locals, #partial_path, #rendering_options

Constructor Details

This class inherits a constructor from Stall::ProductFilters::BaseFilter

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/stall/product_filters/price_filter.rb', line 4

def available?
  options[:force] || min != max
end

#maxObject



13
14
15
16
# 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

#minObject



8
9
10
11
# 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

#paramObject



18
19
20
# File 'lib/stall/product_filters/price_filter.rb', line 18

def param
  :variants_price_cents_between_cents
end

#ticksObject



22
23
24
25
26
27
28
29
30
# 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