Module: Aloe::Ledger

Extended by:
Ledger
Included in:
Ledger
Defined in:
lib/aloe/ledger.rb

Overview

Ledger is the façade interface to the account. When manipulating accounts (eg. creating transactions between accounts) you should use the Ledger and not the underlying models.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_scope=(value) ⇒ Object

Sets the attribute account_scope

Parameters:

  • value

    the value to set the attribute account_scope to.



14
15
16
# File 'lib/aloe/ledger.rb', line 14

def (value)
  @account_scope = value
end

Instance Method Details

#create_entry(amount, options) ⇒ Aloe::Transaction

Creates entry in the ledger.

Creates entries in both credit and debit account and linking transaction between those two entries. Credit and debit accounts and given amount have to be in the same currency otherwise an exception is raised.

Parameters:

  • amount (Money)

    The amount of money

  • options (Hash)

    Options

Options Hash (options):

  • :from (Aloe::Account)

    Account which to debit

  • :to (Aloe::Account)

    Account which to credit

  • :type (Fixnum)

    Type of transaction

Returns:



50
51
52
# File 'lib/aloe/ledger.rb', line 50

def create_entry(amount, options)
  Aloe::LedgerEntry.new(amount, options).create!
end

#default_currencyString

Return the default currency that gets used when no currency is specified.

Returns:

  • (String)


57
58
59
# File 'lib/aloe/ledger.rb', line 57

def default_currency
  Money.default_currency.to_s
end

#find_account(owner, currency = default_currency) ⇒ Aloe::Account?

Returns an account for given owner.

Parameters:

  • owner (Object, Symbol)

    Account owner or account name

  • currency (String, Symbol) (defaults to: default_currency)

    Currency symbol

Returns:

  • (Aloe::Account, nil)

    Account which belongs to given object or nil



22
23
24
# File 'lib/aloe/ledger.rb', line 22

def (owner, currency = default_currency)
  scope_for_owner(owner).currency(currency.to_s).first
end

#find_accounts(owner, currency = nil) ⇒ Aloe::Account?

Returns accounts for a given owner.

Parameters:

  • owner (Object, Symbol)

    Account owner or account name

  • currency (String, Symbol) (defaults to: nil)

    Currency symbol

Returns:

  • (Aloe::Account, nil)

    Array of accounts which belongs to given object



32
33
34
35
# File 'lib/aloe/ledger.rb', line 32

def find_accounts(owner, currency = nil)
  scope = scope_for_owner(owner)
  currency ? scope.currency(currency) : scope
end