Class: Finrb::Transaction
- Inherits:
-
Object
- Object
- Finrb::Transaction
- Defined in:
- lib/finrb/transaction.rb
Overview
the Transaction class provides a general interface for working with individual cash flows.
Instance Attribute Summary collapse
-
#amount ⇒ Flt::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 ⇒ Flt::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 ⇒ Flt::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
30 31 32 33 34 35 36 37 38 |
# File 'lib/finrb/transaction.rb', line 30 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 ⇒ Flt::DecNum
Returns the cash value of the transaction.
11 12 13 |
# File 'lib/finrb/transaction.rb', line 11 def amount @amount end |
#date ⇒ Date
Returns the date of the transaction.
18 19 20 |
# File 'lib/finrb/transaction.rb', line 18 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.
15 16 17 |
# File 'lib/finrb/transaction.rb', line 15 def period @period end |
Instance Method Details
#difference ⇒ Flt::DecNum
Returns the difference between the original transaction amount and the current amount.
59 60 61 |
# File 'lib/finrb/transaction.rb', line 59 def difference @amount - @original end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/finrb/transaction.rb', line 75 def inspect "Transaction(#{@amount.round(2)}, date: #{@date})" end |
#interest? ⇒ Boolean
Returns whether or not the Transaction is an Interest transaction.
70 71 72 |
# File 'lib/finrb/transaction.rb', line 70 def interest? 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
87 88 89 |
# File 'lib/finrb/transaction.rb', line 87 def modify @amount = yield(self) end |
#payment ⇒ Flt::DecNum
Provided for backwards compatibility
Returns the cash value of the transaction.
93 94 95 |
# File 'lib/finrb/transaction.rb', line 93 def payment @amount end |
#payment? ⇒ Boolean
Returns whether or not the Transaction is a Payment transaction.
104 105 106 |
# File 'lib/finrb/transaction.rb', line 104 def payment? instance_of?(Payment) end |