Class: HeatingSystemCalculator::BaseItemFinder

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

Instance Method Summary collapse

Instance Method Details

#get_number_of_poles_from_consolidated_elements(elements) ⇒ Object



18
19
20
21
# File 'app/services/heating_system_calculator/base_item_finder.rb', line 18

def get_number_of_poles_from_consolidated_elements(elements)
  # Here we use 2 poles for DOUBLE_POLE_VOLTAGES elements, but also 2 poles for any elements > 15 amps so that we respect 30 map limit on each relay
  elements.to_a.sum { |e| (Item::DOUBLE_POLE_VOLTAGES.include?(e['volts'].round(1)) || e['amps'] > 15.0 ? 2 : 1).round * e['qty'] }
end

#get_total_from_solution(elements, attribute_key) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/heating_system_calculator/base_item_finder.rb', line 3

def get_total_from_solution(elements, attribute_key)
  # calculate total amount of attribute from an array of elements
  # set up total
  tot = 0.0
  # loop over elements
  elements.each do |elem|
    # sum total over each element, assume numerical
    qty = 1.0
    qty = elem['qty'].to_f if elem['qty'].to_f > 1.0
    tot += (elem[attribute_key].to_f * qty)
  end
  # return accumulated total
  tot
end