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

#accessoriesObject

Returns the value of attribute accessories.



10
11
12
# File 'app/services/item/kit_attribute_generator.rb', line 10

def accessories
  @accessories
end

#control_itemObject

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_itemsObject

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_itemObject

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_itemObject

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

#membranesObject

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

#ampsObject

Alias for Main_he_item#amps

Returns:

  • (Object)

    Main_he_item#amps

See Also:



5
# File 'app/services/item/kit_attribute_generator.rb', line 5

delegate :amps, :voltage, :length, to: :main_he_item

#base_primary_product_line_slug_ltreeObject



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_lengthObject



96
97
98
# File 'app/services/item/kit_attribute_generator.rb', line 96

def cable_length
  coverage_data[:cable_length]
end

#cable_spacingObject



132
133
134
# File 'app/services/item/kit_attribute_generator.rb', line 132

def cable_spacing
  coverage_data[:cable_spacing]
end

#control_featureObject



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_prefixObject



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_suffixObject



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_dataObject



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

#dumpObject



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_featuresObject



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_nameObject



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? # Cable
    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_codeObject



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_ltreeObject

Raises:

  • (NotImplementedError)


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_skuObject



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
  # Our products for rolls use the format
  # TRT120-1.5x06
  # or TCT120-3.7W-030
  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
  # example kit sku TRT120-KIT-OP-1.5x06
  sku = "#{kit_sku_prefix}-KIT-#{control_prefix}"
  sku << '-MEM' if membranes.present?
  sku << "-#{size}"
  sku
end

#lengthObject

Alias for Main_he_item#length

Returns:

  • (Object)

    Main_he_item#length

See Also:



5
# File 'app/services/item/kit_attribute_generator.rb', line 5

delegate :amps, :voltage, :length, to: :main_he_item

#membranes_countObject



100
101
102
# File 'app/services/item/kit_attribute_generator.rb', line 100

def membranes_count
  (membranes&.values&.size || 0).to_i
end

#model_suffixObject



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

#sizeObject



92
93
94
# File 'app/services/item/kit_attribute_generator.rb', line 92

def size
  coverage_data[:size]
end

#sqftObject



88
89
90
# File 'app/services/item/kit_attribute_generator.rb', line 88

def sqft
  coverage_data[:sqft]
end

#to_sObject



190
191
192
# File 'app/services/item/kit_attribute_generator.rb', line 190

def to_s
  kit_sku
end

#tz_cable_kit?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#voltageObject

Alias for Main_he_item#voltage

Returns:

  • (Object)

    Main_he_item#voltage

See Also:



5
# File 'app/services/item/kit_attribute_generator.rb', line 5

delegate :amps, :voltage, :length, to: :main_he_item

#watts_per_ftObject



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_sqftObject



128
129
130
# File 'app/services/item/kit_attribute_generator.rb', line 128

def watts_per_sqft
  coverage_data[:watts_per_sqft]
end