Class: Item::Materials::Checks::InfraredHeatingPanel
- Inherits:
-
BaseService
- Object
- BaseService
- Item::Materials::Checks::InfraredHeatingPanel
- Defined in:
- app/services/item/materials/checks/infrared_heating_panel.rb
Overview
Service object: infrared heating panel.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
Instance Method Details
#process(container:, options: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/item/materials/checks/infrared_heating_panel.rb', line 13 def process(container:, options: {}) return Result.new(status: :skipped) unless qualify?(container) material_alerts = [] num_infrared_heating_panels_plug_in = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_plug_in? }.sum(&:quantity) num_infrared_heating_panels_hardwired = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_hardwired? }.sum(&:quantity) num_infrared_heating_panel_controls_plug_in = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_plug_in_control? }.sum(&:quantity) num_infrared_heating_panel_controls_hardwired = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_hardwired_control? }.sum(&:quantity) num_infrared_heating_panels_dual_connect = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_dual_connect? }.sum(&:quantity) if (num_infrared_heating_panel_controls_plug_in != num_infrared_heating_panels_plug_in) && (num_infrared_heating_panel_controls_plug_in != (num_infrared_heating_panels_plug_in + num_infrared_heating_panels_dual_connect)) = {}.merge() [:room] = container [:recommended_qty] = num_infrared_heating_panels_plug_in [:actual_qty] = num_infrared_heating_panel_controls_plug_in [:items] = if (ctrl_lis = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_plug_in_control? }).any? ctrl_lis.map(&:item) else Item.infrared_heating_panel_controls_plug_in.to_a end [:unmaskable] = true [:name] = "One plug in control per plug in infrared heating panel is recommended." material_alerts << Item::Materials::Alert.new() end if (num_infrared_heating_panel_controls_hardwired != num_infrared_heating_panels_hardwired) && (num_infrared_heating_panel_controls_hardwired != (num_infrared_heating_panels_hardwired + num_infrared_heating_panels_dual_connect)) = {}.merge() [:room] = container [:recommended_qty] = num_infrared_heating_panels_hardwired [:actual_qty] = num_infrared_heating_panel_controls_hardwired [:items] = if (ctrl_lis = container.line_items.parents_only.select { |l| l.item.is_infrared_heating_panel_hardwired_control? }).any? ctrl_lis.map(&:item) else Item.infrared_heating_panel_controls_hardwired.to_a end [:unmaskable] = true [:name] = "One hardwired control per hardwired infrared heating panel is recommended." material_alerts << Item::Materials::Alert.new() end Result.new(status: :ok, alerts: material_alerts) end |
#qualify?(container) ⇒ Boolean
9 10 11 |
# File 'app/services/item/materials/checks/infrared_heating_panel.rb', line 9 def qualify?(container) container.line_items.any? { |li| li.item.is_infrared_heating_panel? } end |