Class: Item::Auditor
- Inherits:
-
BaseService
- Object
- BaseService
- Item::Auditor
- Defined in:
- app/services/item/auditor.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
#process(items: nil, auto_fix: false, limit: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/item/auditor.rb', line 3 def process(items: nil, auto_fix: false, limit: nil) items ||= Item.heating_elements.active items = items.limit(limit) if limit&.>0 res = {} items_to_fix = [] items.each do |item| msg = process_item(item) if msg.present? res["#{item.sku} - #{item.id}"] = msg items_to_fix << item end end if auto_fix && items_to_fix.present? puts "#{items_to_fix.size} items are incorrect and attempting auto fix" items_to_fix.each{|i| i.update_rendered_product_specifications(tokens: %i[voltage amps watts ohms] ) } puts "Auto fix complete, rechecking" res = process(items: items_to_fix, auto_fix: false) end res end |
#process_item(item) ⇒ Object
24 25 26 |
# File 'app/services/item/auditor.rb', line 24 def process_item(item) res = OhmsLawCalculator.validate({ voltage: item.voltage, current: item.amps, power: item.watts, resistance: item.ohms }) end |