Class: Generalis::Entry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Generalis::Entry
- Defined in:
- lib/generalis/entry.rb
Constant Summary collapse
- CREDIT =
-1
- DEBIT =
+1
Class Method Summary collapse
Instance Method Summary collapse
- #credit? ⇒ Boolean
- #debit? ⇒ Boolean
-
#net_amount ⇒ Money
The net change in balance that is applied to the account.
- #no_op? ⇒ Boolean
- #opposite ⇒ Entry?
Class Method Details
.coefficient=(coefficient) ⇒ void
This method returns an undefined value.
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
40 41 42 |
# File 'lib/generalis/entry.rb', line 40 def credit? coefficient == CREDIT end |
#debit? ⇒ Boolean
45 46 47 |
# File 'lib/generalis/entry.rb', line 45 def debit? coefficient == DEBIT end |
#net_amount ⇒ Money
The net change in balance that is applied to the account.
52 53 54 |
# File 'lib/generalis/entry.rb', line 52 def net_amount amount * coefficient * account.coefficient end |
#no_op? ⇒ Boolean
57 58 59 |
# File 'lib/generalis/entry.rb', line 57 def no_op? amount.zero? end |
#opposite ⇒ Entry?
62 63 64 |
# File 'lib/generalis/entry.rb', line 62 def opposite ledger_transaction.entries.find_by(pair_id: pair_id, coefficient: -coefficient) end |