Class: ProductLine::SpecificationsMasher

Inherits:
BaseService show all
Defined in:
app/services/product_line/specifications_masher.rb

Overview

Service object: specifications masher.

Defined Under Namespace

Classes: Result

Instance Attribute Summary

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(product_line, _options = {}) ⇒ Object

Add raw_array: true if you want raw to always return as an array



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/product_line/specifications_masher.rb', line 10

def process(product_line, _options = {})
  specifications = {}
  product_specifications = product_line.self_and_inherited_specifications.where(template: false, method: 'text', propagation: %w[unrestricted product_line])
  product_specifications.each do |ps|
    token = ps.token.presence || ps.name.parameterize.underscore
    result = ps.get_specification_data(product_line, skip_validation: true)

    specifications[token.to_sym] = {
      id: token.to_s.camelize(:lower),
      name: ps.name,
      output: result.formatted,
      raw: result.raw,
      units: ps.units.presence,
      product_specification_id: ps.id,
      visibility: ps.visibility,
      grouping: ps.grouping,
      description: ps.description
    }
  end

  Result.new(specifications: specifications.deep_symbolize_keys)
end