Class: MudratProjector::MortgageAmortizer
Instance Attribute Summary collapse
#schedule
Attributes inherited from Amortizer
#balance
Instance Method Summary
collapse
#initial_value, #interest, #months_amortized, #next_transaction, #payment, #principal, #rate, #schedule_range
Constructor Details
#initialize(*args, extra_principal: 0) ⇒ MortgageAmortizer
70
71
72
73
|
# File 'lib/mudrat_projector/amortizer.rb', line 70
def initialize *args, extra_principal: 0
=
super
end
|
Instance Attribute Details
Returns the value of attribute extra_principal.
68
69
70
|
# File 'lib/mudrat_projector/amortizer.rb', line 68
def
end
|
Instance Method Details
#amortize ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/mudrat_projector/amortizer.rb', line 86
def amortize
interest_paid = 0
principal_paid = 0
mp = monthly_payment
new_balance = months_amortized.times.inject initial_value do |balance, _|
interest = balance * rate
principal = (mp - interest) +
interest_paid += interest
principal_paid += principal
balance - principal
end
[new_balance, interest_paid, principal_paid]
end
|
#each_entry(&block) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/mudrat_projector/amortizer.rb', line 79
def each_entry &block
[[:credit, interest, schedule.payment_account ],
[:credit, principal, schedule.payment_account ],
[:debit, interest, schedule.interest_account ],
[:debit, principal, schedule.principal_account]].each &block
end
|
#monthly_payment ⇒ Object
75
76
77
|
# File 'lib/mudrat_projector/amortizer.rb', line 75
def monthly_payment
schedule.monthly_payment
end
|