Class: Workarea::BrowseOptionIds

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/browse_option_ids.rb

Class Method Summary collapse

Class Method Details

.all_for(product, options = []) ⇒ Object



4
5
6
7
8
9
10
# File 'app/services/workarea/browse_option_ids.rb', line 4

def all_for(product, options = [])
  return [product.id] unless product.browses_by_option?

  (Array.wrap(options).presence || product.browse_options).map do |option|
    build(product.id, option.optionize)
  end
end

.build(product_id, option) ⇒ Object



22
23
24
# File 'app/services/workarea/browse_option_ids.rb', line 22

def build(product_id, option)
  [product_id, conjunction, option.optionize].join
end

.conjunctionObject



34
35
36
# File 'app/services/workarea/browse_option_ids.rb', line 34

def conjunction
  Workarea.config.browse_option_product_id_conjunction
end

.extract(browse_option_id) ⇒ Object



30
31
32
# File 'app/services/workarea/browse_option_ids.rb', line 30

def extract(browse_option_id)
  split(browse_option_id).first
end

.for(product, option = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/services/workarea/browse_option_ids.rb', line 12

def for(product, option = nil)
  return product.id unless product.browses_by_option?

  if option.present?
    build(product.id, option.optionize)
  else
    all_for(product).first
  end
end

.split(browse_option_id) ⇒ Object



26
27
28
# File 'app/services/workarea/browse_option_ids.rb', line 26

def split(browse_option_id)
  browse_option_id.to_s.split(conjunction)
end