Class: Invoicing::LedgerItem::AccountSummary
- Inherits:
-
Object
- Object
- Invoicing::LedgerItem::AccountSummary
- Defined in:
- lib/invoicing/ledger_item.rb
Overview
Very simple class for representing the sum of all sales, purchases and payments on an account.
Constant Summary collapse
- NUM_FIELDS =
:nodoc:
[:sales, :purchases, :sale_receipts, :purchase_payments, :balance]
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(hash) ⇒ AccountSummary
constructor
A new instance of AccountSummary.
- #method_missing(name, *args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ AccountSummary
Returns a new instance of AccountSummary.
817 818 819 820 821 |
# File 'lib/invoicing/ledger_item.rb', line 817 def initialize(hash) @currency = hash[:currency]; @sales = hash[:sales]; @purchases = hash[:purchases] @sale_receipts = hash[:sale_receipts]; @purchase_payments = hash[:purchase_payments] @balance = hash[:balance] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
823 824 825 826 827 828 829 |
# File 'lib/invoicing/ledger_item.rb', line 823 def method_missing(name, *args) if name.to_s =~ /(.*)_formatted$/ ::Invoicing::CurrencyValue::Formatter.format_value(currency, send($1)) else super end end |
Instance Method Details
#+(other) ⇒ Object
831 832 833 834 835 |
# File 'lib/invoicing/ledger_item.rb', line 831 def +(other) hash = {:currency => currency} NUM_FIELDS.each {|field| hash[field] = send(field) + other.send(field) } AccountSummary.new hash end |
#to_s ⇒ Object
837 838 839 840 841 842 |
# File 'lib/invoicing/ledger_item.rb', line 837 def to_s NUM_FIELDS.map do |field| val = send("#{field}_formatted") "#{field} = #{val}" end.join('; ') end |