Class: Stall::ProductFilters::Builder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(products, options = {}) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
# File 'lib/stall/product_filters/builder.rb', line 6

def initialize(products, options = {})
  @products = products
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#productsObject (readonly)

Returns the value of attribute products.



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

def products
  @products
end

Instance Method Details

#category_filterObject



15
16
17
# File 'lib/stall/product_filters/builder.rb', line 15

def category_filter
  CategoryFilter.new(products, options_for(:category)) if enabled?(:category)
end

#filtersObject



11
12
13
# File 'lib/stall/product_filters/builder.rb', line 11

def filters
  [category_filter, manufacturer_filter, price_filter] + properties_filters
end

#manufacturer_filterObject



19
20
21
# File 'lib/stall/product_filters/builder.rb', line 19

def manufacturer_filter
  ManufacturerFilter.new(products, options_for(:manufacturer)) if enabled?(:manufacturer)
end

#price_filterObject



23
24
25
# File 'lib/stall/product_filters/builder.rb', line 23

def price_filter
  PriceFilter.new(products, options_for(:price)) if enabled?(:price)
end

#properties_filtersObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/stall/product_filters/builder.rb', line 27

def properties_filters
  if enabled?(:property)
    properties.map do |property|
      property_options = options_for(:property, property: property)
      PropertyFilter.new(products, property_options)
    end
  else
    []
  end
end