Class: HeatingSystemCalculator::HeatedArea

Inherits:
Object
  • Object
show all
Defined in:
app/services/heating_system_calculator/heated_area.rb

Constant Summary collapse

MAXIMUM_HEATED_AREA =
9_999_999.9

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HeatedArea

Returns a new instance of HeatedArea.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/heating_system_calculator/heated_area.rb', line 7

def initialize(options = {})
  @room_configuration = options[:room_configuration]
  @room_configuration.present? ? pre_process_from_room(@room_configuration) : pre_process_from_options(options)
  if @heated_area_sqft.nil?
    @error ||= { error_status: :missing_heated_areas,
                 error_message: 'Zones or Sq.Ft. must be present to get a Bill of Materials.' }
  end
  if @heated_area_sqft and (@heated_area_sqft < 1.0)
    @error ||= { error_status: :heated_areas_too_small,
                 error_message: 'Heated Area is too small to get a Bill of Materials.' }
  end
  return unless @heated_area_sqft and (@heated_area_sqft > MAXIMUM_HEATED_AREA)

  @error ||= { error_status: :heated_areas_too_large,
               error_message: 'Heated Area is too large to get a Bill of Materials.' }
end

Instance Attribute Details

#coverage_stateObject (readonly)

Returns the value of attribute coverage_state.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def coverage_state
  @coverage_state
end

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def error
  @error
end

#floor_typeObject (readonly)

Returns the value of attribute floor_type.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def floor_type
  @floor_type
end

#heated_area_sqftObject (readonly)

Returns the value of attribute heated_area_sqft.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def heated_area_sqft
  @heated_area_sqft
end

#installation_postal_codeObject (readonly)

Returns the value of attribute installation_postal_code.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def installation_postal_code
  @installation_postal_code
end

#insulation_surfaceObject (readonly)

Returns the value of attribute insulation_surface.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def insulation_surface
  @insulation_surface
end

#square_footageObject (readonly)

Returns the value of attribute square_footage.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def square_footage
  @square_footage
end

#zonesObject (readonly)

Returns the value of attribute zones.



5
6
7
# File 'app/services/heating_system_calculator/heated_area.rb', line 5

def zones
  @zones
end

Instance Method Details

#calculate_heated_area_sqftObject



68
69
70
71
72
# File 'app/services/heating_system_calculator/heated_area.rb', line 68

def calculate_heated_area_sqft
  sqft = @square_footage
  sqft = @zones.sum { |z| z[:sqft].to_f } if sqft.nil? and !@zones.empty?
  sqft
end

#pre_process_from_options(options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/services/heating_system_calculator/heated_area.rb', line 38

def pre_process_from_options(options)
  @coverage_state = options[:coverage_state]
  @expansion_joint_spacing = options[:expansion_joint_spacing] if options[:require_expansion_joint]
  # get zones, if any
  @zones = options[:zones] || []
  @square_footage ||= options[:square_footage]
  @insulation_surface ||= options[:insulation_surface]
  @installation_postal_code ||= options[:installation_postal_code]
  set_square_footages
end

#pre_process_from_room(room_configuration) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/heating_system_calculator/heated_area.rb', line 24

def pre_process_from_room(room_configuration)
  @coverage_state = room_configuration.coverage_state
  @expansion_joint_spacing = room_configuration.expansion_joint_spacing if room_configuration.require_expansion_joint?
  @zones = []
    # get zones, if any
  room_configuration.zones.each do |zone|
    @zones << { width: zone.width, length: zone.length, sqft: zone.sqft, name: zone.name }
  end
  @square_footage ||= room_configuration.square_footage || room_configuration.installation_sqft
  @insulation_surface ||= room_configuration.insulation_surface
  @installation_postal_code = room_configuration.installation_postal_code
  set_square_footages
end

#pre_process_zones!(zones) ⇒ Object



49
50
51
52
53
# File 'app/services/heating_system_calculator/heated_area.rb', line 49

def pre_process_zones!(zones)
  zones.each do |zone|
    zone[:sqft] ||= zone[:length].to_f * zone[:width].to_f # ensure sqft is populated
  end
end

#set_square_footagesObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/services/heating_system_calculator/heated_area.rb', line 55

def set_square_footages
  pre_process_zones!(@zones)
  @heated_area_sqft = calculate_heated_area_sqft
  # set insulation surface from heated_area_sqft if it's not set, and heated_area_sqft is present
  @insulation_surface = 1.2 * @heated_area_sqft if (@insulation_surface.to_f == 0.0) and !@heated_area_sqft.nil?
  # set square_footage from insulation surface if heated_area_sqft is not set through square_footage nor zones, and insulation surface is present
  @square_footage = 0.8 * @insulation_surface if (@heated_area_sqft.to_f == 0.0) and !@insulation_surface.nil?
  # we need at least one zone using this convention below for cable systems to calculate
  return unless @zones.empty? and !@heated_area_sqft.nil?

  @zones << { sqft: @heated_area_sqft, name: "Heated Area, #{@heated_area_sqft}" }
end