Class: Finance::Transaction
- Inherits:
-
Object
- Object
- Finance::Transaction
- Defined in:
- lib/finance/transaction.rb
Overview
the Transaction class provides a general interface for working with individual cash flows.
Instance Attribute Summary collapse
-
#amount ⇒ DecNum
The cash value of the transaction.
-
#date ⇒ Date
The date of the transaction.
-
#period ⇒ Integer
The period number of the transaction.
Instance Method Summary collapse
-
#difference ⇒ DecNum
The difference between the original transaction amount and the current amount.
-
#initialize(amount, opts = {}) ⇒ Transaction
constructor
create a new Transaction.
- #inspect ⇒ Object
-
#interest? ⇒ Boolean
Whether or not the Transaction is an Interest transaction.
-
#modify ⇒ Object
Modify a Transaction’s amount by passing a block.
-
#payment ⇒ DecNum
deprecated
Deprecated.
Provided for backwards compatibility
-
#payment? ⇒ Boolean
Whether or not the Transaction is a Payment transaction.
Constructor Details
#initialize(amount, opts = {}) ⇒ Transaction
create a new Transaction
51 52 53 54 55 56 57 58 59 |
# File 'lib/finance/transaction.rb', line 51 def initialize(amount, opts={}) @amount = amount @original = amount # Set optional attributes.. opts.each do |key, value| send("#{key}=", value) end end |
Instance Attribute Details
#amount ⇒ DecNum
Returns the cash value of the transaction.
9 10 11 |
# File 'lib/finance/transaction.rb', line 9 def amount @amount end |
#date ⇒ Date
Returns the date of the transaction.
16 17 18 |
# File 'lib/finance/transaction.rb', line 16 def date @date end |
#period ⇒ Integer
this attribute is mainly used in the case of mortgage amortization with no dates
Returns the period number of the transaction.
13 14 15 |
# File 'lib/finance/transaction.rb', line 13 def period @period end |
Instance Method Details
#difference ⇒ DecNum
Returns the difference between the original transaction amount and the current amount.
37 38 39 |
# File 'lib/finance/transaction.rb', line 37 def difference @amount - @original end |
#inspect ⇒ Object
73 74 75 |
# File 'lib/finance/transaction.rb', line 73 def inspect "Transaction(#{@amount})" end |
#interest? ⇒ Boolean
Returns whether or not the Transaction is an Interest transaction.
68 69 70 |
# File 'lib/finance/transaction.rb', line 68 def interest? self.instance_of? Interest end |
#modify ⇒ Object
self is passed as the argument to the block. This makes any public attribute available.
Modify a Transaction’s amount by passing a block
85 86 87 |
# File 'lib/finance/transaction.rb', line 85 def modify @amount = yield(self) end |
#payment ⇒ DecNum
Provided for backwards compatibility
Returns the cash value of the transaction.
91 92 93 |
# File 'lib/finance/transaction.rb', line 91 def payment @amount end |
#payment? ⇒ Boolean
Returns whether or not the Transaction is a Payment transaction.
102 103 104 |
# File 'lib/finance/transaction.rb', line 102 def payment? self.instance_of? Payment end |