Class: Item::ConvertElectricalSpecs

Inherits:
BaseService show all
Defined in:
app/services/item/convert_electrical_specs.rb

Instance Method Summary collapse

Methods inherited from BaseService

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

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#processObject



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
28
# File 'app/services/item/convert_electrical_specs.rb', line 3

def process
  # Find all watts already assigned to items
  tokens = %i(watts amps voltage)
  specs_to_fill = ProductSpecification.where.not(item_id:nil).where(text_blurb: nil, token: tokens).includes(:item)
  item_ids = []
  specs_to_fill.each do |spec|
    item = spec.item
    token = spec.token.to_sym
    attribute_name = token
    attribute_name = :volts if attribute_name == :voltage
    val = item.read_attribute(attribute_name)
    if val.present?
      puts "#{item.id} - #{item.sku} : Updating #{token} with value #{val}"
      item_ids << item.id
    else
      puts "#{item.id} - #{item.sku} : No value found for #{item.sku}"
    end
    spec.text_blurb = val
    spec.skip_spec_refresh = true
    #spec.save 
  end
  
  return "Added values to #{item_ids.size} items"
  
  
end