Class: Apy::Loan
- Inherits:
-
Object
- Object
- Apy::Loan
- Defined in:
- lib/apy/loan.rb
Overview
A loan object; Provides helpers for calculating various debt-related scenarios
Instance Attribute Summary collapse
-
#apy ⇒ Object
readonly
Returns the value of attribute apy.
-
#borrow ⇒ Object
readonly
Returns the value of attribute borrow.
Instance Method Summary collapse
-
#amortized_payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
Similar to payment_size, except interest accrues based on the remaining debt.
- #amortized_total_owed(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
-
#initialize(borrow, apy:) ⇒ Loan
constructor
A new instance of Loan.
-
#payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
Based on the borrow amount, calculate the payment size required to pay off the principal and accrued interest.
-
#total_owed(start_date:, end_date:, times: 1, days_per_term: 365) ⇒ Object
Get the total amount owed, based on the start & end date.
Constructor Details
#initialize(borrow, apy:) ⇒ Loan
Returns a new instance of Loan.
12 13 14 15 16 17 |
# File 'lib/apy/loan.rb', line 12 def initialize(borrow, apy:) fail(ArgumentError, "apy must be a positive Float") unless apy.positive? && apy.is_a?(Float) @borrow = borrow @apy = apy end |
Instance Attribute Details
#apy ⇒ Object (readonly)
Returns the value of attribute apy.
8 9 10 |
# File 'lib/apy/loan.rb', line 8 def apy @apy end |
#borrow ⇒ Object (readonly)
Returns the value of attribute borrow.
8 9 10 |
# File 'lib/apy/loan.rb', line 8 def borrow @borrow end |
Instance Method Details
#amortized_payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
Finish this
Once finished, make #payment_size accept less args (lump-sum, only accept payment count)
Similar to payment_size, except interest accrues based on the remaining debt
62 63 64 |
# File 'lib/apy/loan.rb', line 62 def amortized_payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) fail end |
#amortized_total_owed(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
Finish this
Once finished, make #total_owed accept less args (lump-sum, only accept payment count)
68 69 70 |
# File 'lib/apy/loan.rb', line 68 def amortized_total_owed(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) fail end |
#payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) ⇒ Object
Based on the borrow amount, calculate the payment size required to pay off the principal and accrued interest
33 34 35 36 37 38 39 40 |
# File 'lib/apy/loan.rb', line 33 def payment_size(start_date:, end_date:, times: 1, days_per_term: 365, payments_per_term: times) total_owed( start_date: start_date, end_date: end_date, times: times, days_per_term: days_per_term ) / (payments_per_term * Interest.get_term_size(start_date, end_date, days_per_term)) end |
#total_owed(start_date:, end_date:, times: 1, days_per_term: 365) ⇒ Object
Because the constructor accepts an APY for the year, an adjusted rate is used here based on days_per_term
Get the total amount owed, based on the start & end date
50 51 52 53 54 55 56 57 |
# File 'lib/apy/loan.rb', line 50 def total_owed(start_date:, end_date:, times: 1, days_per_term: 365) Apy::Interest.new( apy: adjusted_apy(days_per_term), start_date: start_date, end_date: end_date, days_per_term: days_per_term ).total(borrow, times: times) end |