Class: Finrb::Transaction
- Inherits:
-
Object
- Object
- Finrb::Transaction
- Defined in:
- lib/finrb/transaction.rb,
sig/finrb.rbs
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 ⇒ String
-
#interest? ⇒ Boolean
Whether or not the Transaction is an Interest transaction.
-
#modify {|arg0| ... } ⇒ 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
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/finrb/transaction.rb', line 25 def initialize(amount, opts = {}) raise(ArgumentError, 'options must be a Hash.') unless opts.is_a?(Hash) raise(ArgumentError, 'options may only contain date and period.') unless (opts.keys - %i[date period]).empty? self.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.
9 10 11 |
# File 'lib/finrb/transaction.rb', line 9 def amount @amount end |
#date ⇒ Date
Returns the date of the transaction.
14 15 16 |
# File 'lib/finrb/transaction.rb', line 14 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.
12 13 14 |
# File 'lib/finrb/transaction.rb', line 12 def period @period end |
Instance Method Details
#difference ⇒ Flt::DecNum
Returns the difference between the original transaction amount and the current amount.
68 69 70 |
# File 'lib/finrb/transaction.rb', line 68 def difference @amount - @original end |
#inspect ⇒ String
82 83 84 |
# File 'lib/finrb/transaction.rb', line 82 def inspect "Transaction(#{@amount.round(2)}, date: #{@date})" end |
#interest? ⇒ Boolean
Returns whether or not the Transaction is an Interest transaction.
78 79 80 |
# File 'lib/finrb/transaction.rb', line 78 def interest? instance_of?(Interest) end |
#modify {|arg0| ... } ⇒ 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
93 94 95 |
# File 'lib/finrb/transaction.rb', line 93 def modify self.amount = yield(self) end |
#payment ⇒ Flt::DecNum
Provided for backwards compatibility
Returns the cash value of the transaction.
99 100 101 |
# File 'lib/finrb/transaction.rb', line 99 def payment @amount end |
#payment? ⇒ Boolean
Returns whether or not the Transaction is a Payment transaction.
109 110 111 |
# File 'lib/finrb/transaction.rb', line 109 def payment? instance_of?(Payment) end |