Class: HeatingSystemCalculator::BaseItemFinder
- Inherits:
-
Object
- Object
- HeatingSystemCalculator::BaseItemFinder
- Defined in:
- app/services/heating_system_calculator/base_item_finder.rb
Overview
Service object: base item finder.
Direct Known Subclasses
AccessoriesFinder, BaseElementFinder, FloorHeatingControlsFinder, SmartServicesFinder, SnowMeltingControlsFinder
Instance Method Summary collapse
- #get_number_of_poles_from_consolidated_elements(elements) ⇒ Object
- #get_total_from_solution(elements, attribute_key) ⇒ Object
Instance Method Details
#get_number_of_poles_from_consolidated_elements(elements) ⇒ Object
20 21 22 23 |
# File 'app/services/heating_system_calculator/base_item_finder.rb', line 20 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
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/heating_system_calculator/base_item_finder.rb', line 5 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 |