Module: Moolah::ChargeClassBuilder::InstanceMethods
- Defined in:
- lib/moolah/charge_class_builder.rb
Instance Method Summary collapse
Instance Method Details
#+(other_charge) ⇒ Object
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 # will have at least one value c[key] = values.inject(Money.zero, &:+) end end charge_class = ChargeClassBuilder.build(combined_components.keys) charge_class.new(combined_components) end |
#==(other_charge) ⇒ Object
25 26 27 |
# File 'lib/moolah/charge_class_builder.rb', line 25 def ==(other_charge) attributes == other_charge.attributes end |
#total ⇒ Object
21 22 23 |
# File 'lib/moolah/charge_class_builder.rb', line 21 def total attributes.values.inject(Money.zero, &:+) end |