5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/moolah/charge_class_builder.rb', line 5
def +(other_charge)
return self unless other_charge
all_component_keys = Set.new(attributes.keys + other_charge.attributes.keys)
combined_components = all_component_keys.inject({}) do |com, key|
com.tap do |c|
values = [attributes[key], other_charge.attributes[key]].compact c[key] = values.inject(Money.zero, &:+)
end
end
charge_class = ChargeClassBuilder.build(combined_components.keys)
charge_class.new(combined_components)
end
|