Class: Finrb::Amortization::Entry
- Inherits:
-
Object
- Object
- Finrb::Amortization::Entry
- Defined in:
- lib/finrb/amortization.rb,
sig/finrb.rbs
Overview
Immutable breakdown of one amortization period. Payments retain finrb's cashflow sign convention and are negative; the other monetary fields are non-negative.
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #additional_payment ⇒ decimal
- #balloon_payment ⇒ decimal
- #closing_balance ⇒ decimal
- #hash ⇒ Integer
-
#initialize(period:, opening_balance:, payment:, interest:, principal:, additional_payment:, balloon_payment:, interest_only:, closing_balance:) ⇒ Entry
constructor
A new instance of Entry.
- #interest ⇒ decimal
- #interest_only ⇒ Boolean (also: #interest_only?)
- #opening_balance ⇒ decimal
- #payment ⇒ decimal
- #period ⇒ Integer
- #principal ⇒ decimal
- #to_h ⇒ Hash[Symbol, Integer | decimal]
Constructor Details
#initialize(period:, opening_balance:, payment:, interest:, principal:, additional_payment:, balloon_payment:, interest_only:, closing_balance:) ⇒ Entry
Returns a new instance of Entry.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/finrb/amortization.rb', line 32 def initialize(period:, opening_balance:, payment:, interest:, principal:, additional_payment:, balloon_payment:, interest_only:, closing_balance:) raise(ArgumentError, 'period must be a non-negative integer.') unless period.is_a?(Integer) && !period.negative? raise(ArgumentError, 'interest_only must be true or false.') unless [true, false].include?(interest_only) @period = period @interest_only = interest_only MONETARY_ATTRIBUTES.each do |name| value = binding.local_variable_get(name) instance_variable_set("@#{name}", Validation.decimal(value, name: name.to_s.tr('_', ' '))) end freeze end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
45 46 47 |
# File 'lib/finrb/amortization.rb', line 45 def ==(other) other.instance_of?(self.class) && ATTRIBUTES.all? { |name| public_send(name) == other.public_send(name) } end |
#additional_payment ⇒ decimal
104 |
# File 'sig/finrb.rbs', line 104
def additional_payment: () -> decimal
|
#balloon_payment ⇒ decimal
105 |
# File 'sig/finrb.rbs', line 105
def balloon_payment: () -> decimal
|
#closing_balance ⇒ decimal
108 |
# File 'sig/finrb.rbs', line 108
def closing_balance: () -> decimal
|
#hash ⇒ Integer
50 51 52 53 |
# File 'lib/finrb/amortization.rb', line 50 def hash attributes = ATTRIBUTES.map { |name| public_send(name) } attributes.hash end |
#interest ⇒ decimal
102 |
# File 'sig/finrb.rbs', line 102
def interest: () -> decimal
|
#interest_only ⇒ Boolean Also known as: interest_only?
106 |
# File 'sig/finrb.rbs', line 106
def interest_only: () -> bool
|
#opening_balance ⇒ decimal
100 |
# File 'sig/finrb.rbs', line 100
def opening_balance: () -> decimal
|
#payment ⇒ decimal
101 |
# File 'sig/finrb.rbs', line 101
def payment: () -> decimal
|
#period ⇒ Integer
99 |
# File 'sig/finrb.rbs', line 99
def period: () -> Integer
|
#principal ⇒ decimal
103 |
# File 'sig/finrb.rbs', line 103
def principal: () -> decimal
|
#to_h ⇒ Hash[Symbol, Integer | decimal]
55 56 57 |
# File 'lib/finrb/amortization.rb', line 55 def to_h ATTRIBUTES.to_h { |name| [name, public_send(name)] } end |