Class: Feed::ProductTypeGenerator

Inherits:
BaseService show all
Defined in:
app/services/feed/product_type_generator.rb

Class Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.process(product_line: nil, product_category: nil, item: nil, separator: nil, limit: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/feed/product_type_generator.rb', line 3

def self.process(product_line: nil, product_category: nil, item: nil, separator: nil, limit: nil)
  separator ||= '/'
  limit ||= 10
  product_line ||= item&.primary_product_line
  product_category ||= item&.product_category
  return unless product_line || product_category
  pl_path = product_line&.root_system_product_line&.lineage_expanded&.split(" > ") || []
  pc_path = []
  if product_category
    pc_path = product_category.root_product_category.lineage_expanded.split(" > ") || []
    pc_path.delete('Goods')
    pc_path.delete('Services')
  end
  bc = pl_path | pc_path
  bc = bc.map do |e|
    case e
    when 'Towel Warmer'
      'Towel Warmers'
    else
      e
    end
  end
  bc = bc.uniq.first(limit)
  bc.join(separator)
end