Class: Invoicing::LedgerItem::AccountSummary

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(hash) ⇒ AccountSummary

Returns a new instance of AccountSummary.


797
798
799
800
801
# File 'lib/invoicing/ledger_item.rb', line 797

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


803
804
805
806
807
808
809
# File 'lib/invoicing/ledger_item.rb', line 803

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


811
812
813
814
815
# File 'lib/invoicing/ledger_item.rb', line 811

def +(other)
  hash = {:currency => currency}
  NUM_FIELDS.each {|field| hash[field] = send(field) + other.send(field) }
  AccountSummary.new hash
end

#to_sObject


817
818
819
820
821
822
# File 'lib/invoicing/ledger_item.rb', line 817

def to_s
  NUM_FIELDS.map do |field|
    val = send("#{field}_formatted")
    "#{field} = #{val}"
  end.join('; ')
end