Class: Generalis::Entry

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generalis/entry.rb

Direct Known Subclasses

Credit, Debit

Constant Summary collapse

CREDIT =
-1
DEBIT =
+1

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coefficient=(coefficient) ⇒ void

This method returns an undefined value.

Parameters:

  • value (Integer)


35
36
37
# File 'lib/generalis/entry.rb', line 35

def self.coefficient=(coefficient)
  after_initialize(if: :new_record?) { self.coefficient = coefficient }
end

Instance Method Details

#credit?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/generalis/entry.rb', line 40

def credit?
  coefficient == CREDIT
end

#debit?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/generalis/entry.rb', line 45

def debit?
  coefficient == DEBIT
end

#net_amountMoney

The net change in balance that is applied to the account.

Returns:

  • (Money)


52
53
54
# File 'lib/generalis/entry.rb', line 52

def net_amount
  amount * coefficient * .coefficient
end

#no_op?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/generalis/entry.rb', line 57

def no_op?
  amount.zero?
end

#oppositeEntry?

Returns:



62
63
64
# File 'lib/generalis/entry.rb', line 62

def opposite
  ledger_transaction.entries.find_by(pair_id: pair_id, coefficient: -coefficient)
end