Class: MudratProjector::MortgageAmortizer
- Inherits:
-
CompoundInterestAmortizer
- Object
- Amortizer
- CompoundInterestAmortizer
- MudratProjector::MortgageAmortizer
- Defined in:
- lib/mudrat_projector/amortizer.rb
Instance Attribute Summary collapse
-
#extra_principal ⇒ Object
readonly
Returns the value of attribute extra_principal.
Attributes inherited from CompoundInterestAmortizer
Attributes inherited from Amortizer
Instance Method Summary collapse
- #amortize ⇒ Object
- #each_entry(&block) ⇒ Object
-
#initialize(*args, extra_principal: 0) ⇒ MortgageAmortizer
constructor
A new instance of MortgageAmortizer.
- #monthly_payment ⇒ Object
Methods inherited from CompoundInterestAmortizer
#initial_value, #interest, #months_amortized, #next_transaction, #payment, #principal, #rate, #schedule_range
Constructor Details
#initialize(*args, extra_principal: 0) ⇒ MortgageAmortizer
Returns a new instance of MortgageAmortizer.
70 71 72 73 |
# File 'lib/mudrat_projector/amortizer.rb', line 70 def initialize *args, extra_principal: 0 @extra_principal = extra_principal super end |
Instance Attribute Details
#extra_principal ⇒ Object (readonly)
Returns the value of attribute extra_principal.
68 69 70 |
# File 'lib/mudrat_projector/amortizer.rb', line 68 def extra_principal @extra_principal 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) + extra_principal 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 |