Class: Item::KitAttributeGenerator
- Inherits:
-
BaseService
show all
- Includes:
- ActionView::Helpers::NumberHelper, Memery
- Defined in:
- app/services/item/kit_attribute_generator.rb
Constant Summary
collapse
- CABLE_STRIP_DESCRIPTION =
%(TempZone Cable Fixing Strips: used for securing TempZone Electric Radiant Floor Heating Cable in place on floors at predetermined spacing, this kit includes cable strips, enables you to fix the heating cable to the floor at 3 or 4 in spacing and keeps the heating cable secured in position, uniformly positioned across the floor, while you install the floor adhesive)
- MEMBRANE_DESCRIPTION =
%(Prodeso Uncoupling Membrane: Designed for TempZone electric floor heating cable. The polypropylene membrane ensures proper spacing, provides uncoupling and crack isolation benefits, and can be waterproofed. Its low 7/32 in profile minimizes floor height increase)
Instance Attribute Summary collapse
Delegated Instance Attributes
collapse
Instance Method Summary
collapse
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger
Constructor Details
#initialize(main_he_item:, control_item:, accessories:, membranes: nil, kit_item: nil) ⇒ KitAttributeGenerator
Returns a new instance of KitAttributeGenerator.
12
13
14
15
16
17
18
19
|
# File 'app/services/item/kit_attribute_generator.rb', line 12
def initialize(main_he_item:, control_item:, accessories:, membranes: nil, kit_item: nil)
@kit_item = kit_item
@main_he_item = main_he_item
@control_item = control_item
@accessories = accessories
@membranes = membranes
@kit_component_items = [main_he_item, control_item, *Item.where(sku: membranes.keys).to_a, *[accessories].flatten].compact.uniq
end
|
Instance Attribute Details
#accessories ⇒ Object
Returns the value of attribute accessories.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def accessories
@accessories
end
|
#control_item ⇒ Object
Returns the value of attribute control_item.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def control_item
@control_item
end
|
#kit_component_items ⇒ Object
Returns the value of attribute kit_component_items.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def kit_component_items
@kit_component_items
end
|
#kit_item ⇒ Object
Returns the value of attribute kit_item.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def kit_item
@kit_item
end
|
#main_he_item ⇒ Object
Returns the value of attribute main_he_item.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def main_he_item
@main_he_item
end
|
#membranes ⇒ Object
Returns the value of attribute membranes.
10
11
12
|
# File 'app/services/item/kit_attribute_generator.rb', line 10
def membranes
@membranes
end
|
Instance Method Details
#amps ⇒ Object
Alias for Main_he_item#amps
5
|
# File 'app/services/item/kit_attribute_generator.rb', line 5
delegate :amps, :voltage, :length, to: :main_he_item
|
#base_primary_product_line_slug_ltree ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/services/item/kit_attribute_generator.rb', line 59
def base_primary_product_line_slug_ltree
if tz_cable_kit?
if membranes.present?
'floor_heating.tempzone.cable.kits_with_uncoupling_membrane'
else
'floor_heating.tempzone.cable.kits_with_fixing_strips'
end
elsif tz_flex_roll_kit?
'floor_heating.tempzone.flex_roll.twin_conductor.kits'
elsif tz_easy_mat_kit?
'floor_heating.tempzone.easy_mat.twin_conductor.kits'
end
end
|
#cable_length ⇒ Object
96
97
98
|
# File 'app/services/item/kit_attribute_generator.rb', line 96
def cable_length
coverage_data[:cable_length]
end
|
#cable_spacing ⇒ Object
132
133
134
|
# File 'app/services/item/kit_attribute_generator.rb', line 132
def cable_spacing
coverage_data[:cable_spacing]
end
|
#control_feature ⇒ Object
140
141
142
|
# File 'app/services/item/kit_attribute_generator.rb', line 140
def control_feature
Item::KitComposer::CONTROLS[control_item.sku][:feature]
end
|
#control_prefix ⇒ Object
55
56
57
|
# File 'app/services/item/kit_attribute_generator.rb', line 55
def control_prefix
Item::KitComposer::CONTROLS[control_item.sku][:kit_code]
end
|
#control_slug_suffix ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'app/services/item/kit_attribute_generator.rb', line 73
def control_slug_suffix
case control_prefix
when 'UWG5'
'njoy'
when 'UTN5'
'ntrust2'
end
end
|
#coverage_data ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'app/services/item/kit_attribute_generator.rb', line 144
def coverage_data
res = {}
if tz_flex_roll_kit? || tz_easy_mat_kit?
res[:sqft] = number_with_precision(main_he_item.sqft, precision: 1, strip_insignificant_zeros: true)
res[:size] = main_he_item.calculate_size_2d(output_unit: :ft)
res[:watts_per_sqft] = main_he_item.watts_per_sqft
elsif tz_cable_kit?
_, watts_per_ft, cable_length = main_he_item.sku.split('-')
res[:watts_per_ft] = watts_per_ft.to_f.round(1)
res[:cable_length] = cable_length.presence&.to_i || main_he_item.length(output_unit: :ft)
if membranes.present?
res[:cable_spacing] = 3.75
res[:sqft] = number_with_precision(main_he_item.coverage_at_3_75_in, precision: 1, strip_insignificant_zeros: true)
else
res[:cable_spacing] = 4
res[:sqft] = number_with_precision(main_he_item.coverage_at_4_in, precision: 1, strip_insignificant_zeros: true)
end
end
res
end
|
#dump ⇒ Object
194
195
196
197
198
199
200
201
|
# File 'app/services/item/kit_attribute_generator.rb', line 194
def dump
[
kit_sku,
item_name,
item_features,
coverage_data
]
end
|
#item_features ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'app/services/item/kit_attribute_generator.rb', line 170
def item_features
features = Array.new(5)
features[3] = 'Warranty: 25 years for Tempzone Heating Element, 3 years for thermostat'
if tz_flex_roll_kit? || tz_easy_mat_kit?
features[0] = "Underfloor Heating: Heats #{sqft} sq ft under Tile, Wood, Laminate, and Vinyl floor area with a #{size} ft TempZone heating element"
features[1] = "#{voltage}V, #{amps}A, #{watts_per_sqft}"
elsif tz_cable_kit?
features[0] = "Underfloor Heating System: Heats #{sqft} sq ft under Tile, Wood, Laminate, and Vinyl floor area at #{cable_spacing} in spacing"
features[1] = "#{cable_length} ft heating cable length, UL certified, #{voltage}V, #{amps}A, #{watts_per_ft}/ft"
if membranes.present?
features[2] = MEMBRANE_DESCRIPTION
features[3] << ', 10 years for uncoupling membranes' if membranes.present?
else
features[2] = CABLE_STRIP_DESCRIPTION
end
end
features[4] = control_feature
features
end
|
#item_name ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'app/services/item/kit_attribute_generator.rb', line 104
def item_name
name = +''
if tz_flex_roll_kit?
name << "TempZone Flex Roll Kit #{size} (#{sqft} sqft)"
name << " with #{control_item.public_short_name}"
name << ", #{voltage}V, #{amps}A"
elsif tz_easy_mat_kit?
name << "TempZone Easy Mat Kit #{size} (#{sqft} sqft)"
name << " with #{control_item.public_short_name}"
name << ", #{voltage}V, #{amps}A"
elsif tz_cable_kit? name << "TempZone Cable Kit #{cable_length} ft (#{sqft} sqft @ #{cable_spacing} in spacing)"
name << " with #{control_item.public_short_name}"
name << ', Uncoupling Membrane' if membranes.present?
name << ", #{voltage}V, #{watts_per_ft}/ft, #{amps}A"
else
raise 'Category not yet supported'
end
end
|
#kit_control_code ⇒ Object
136
137
138
|
# File 'app/services/item/kit_attribute_generator.rb', line 136
def kit_control_code
Item::KitComposer::CONTROLS[control_item.sku][:kit_code]
end
|
#kit_product_line_slug_ltree ⇒ Object
82
83
84
85
86
|
# File 'app/services/item/kit_attribute_generator.rb', line 82
def kit_product_line_slug_ltree
raise NotImplementedError, 'Define other control scenarios, only UWG5/UTN5 supported' unless control_prefix.in?(%w[UWG5 UTN5])
"#{base_primary_product_line_slug_ltree}.#{control_slug_suffix}"
end
|
#kit_sku ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/services/item/kit_attribute_generator.rb', line 21
def kit_sku
kit_sku_prefix = nil
size = nil
sku_parts = main_he_item.sku.split('-')
if sku_parts.size == 3
kit_sku_prefix, _, size = *sku_parts
elsif sku_parts.size == 2
kit_sku_prefix, size = *sku_parts
else
raise "Unrecognized format #{main_he_item.sku}"
end
sku = "#{kit_sku_prefix}-KIT-#{control_prefix}"
sku << '-MEM' if membranes.present?
sku << "-#{size}"
sku
end
|
#length ⇒ Object
Alias for Main_he_item#length
5
|
# File 'app/services/item/kit_attribute_generator.rb', line 5
delegate :amps, :voltage, :length, to: :main_he_item
|
#membranes_count ⇒ Object
100
101
102
|
# File 'app/services/item/kit_attribute_generator.rb', line 100
def membranes_count
(membranes&.values&.size || 0).to_i
end
|
#model_suffix ⇒ Object
166
167
168
|
# File 'app/services/item/kit_attribute_generator.rb', line 166
def model_suffix
Item::KitComposer::CONTROLS[control_item.sku][:model_suffix]
end
|
#size ⇒ Object
92
93
94
|
# File 'app/services/item/kit_attribute_generator.rb', line 92
def size
coverage_data[:size]
end
|
#sqft ⇒ Object
88
89
90
|
# File 'app/services/item/kit_attribute_generator.rb', line 88
def sqft
coverage_data[:sqft]
end
|
#to_s ⇒ Object
190
191
192
|
# File 'app/services/item/kit_attribute_generator.rb', line 190
def to_s
kit_sku
end
|
#tz_cable_kit? ⇒ Boolean
51
52
53
|
# File 'app/services/item/kit_attribute_generator.rb', line 51
def tz_cable_kit?
main_he_item.sku.start_with?('TCT')
end
|
#tz_easy_mat_kit? ⇒ Boolean
47
48
49
|
# File 'app/services/item/kit_attribute_generator.rb', line 47
def tz_easy_mat_kit?
main_he_item.primary_product_line_slug_ltree.to_s.start_with?('floor_heating.tempzone.easy_mat')
end
|
#tz_flex_roll_kit? ⇒ Boolean
43
44
45
|
# File 'app/services/item/kit_attribute_generator.rb', line 43
def tz_flex_roll_kit?
main_he_item.primary_product_line_slug_ltree.to_s.start_with?('floor_heating.tempzone.flex_roll')
end
|
#voltage ⇒ Object
Alias for Main_he_item#voltage
5
|
# File 'app/services/item/kit_attribute_generator.rb', line 5
delegate :amps, :voltage, :length, to: :main_he_item
|
#watts_per_ft ⇒ Object
124
125
126
|
# File 'app/services/item/kit_attribute_generator.rb', line 124
def watts_per_ft
coverage_data[:watts_per_ft]
end
|
#watts_per_sqft ⇒ Object
128
129
130
|
# File 'app/services/item/kit_attribute_generator.rb', line 128
def watts_per_sqft
coverage_data[:watts_per_sqft]
end
|