Class: Stall::ProductFilters::PriceFilter
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
Instance Method Details
#available? ⇒ Boolean
4
5
6
|
# File 'lib/stall/product_filters/price_filter.rb', line 4
def available?
options[:force] || min != max
end
|
#max ⇒ Object
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
|
#min ⇒ Object
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
|
#param ⇒ Object
18
19
20
|
# File 'lib/stall/product_filters/price_filter.rb', line 18
def param
:variants_price_cents_between_cents
end
|
#ticks ⇒ Object
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
|