Class: MortgageBuddy::MortgageCost
- Inherits:
-
Object
- Object
- MortgageBuddy::MortgageCost
- Defined in:
- lib/mortgage_buddy/mortgage_cost.rb
Constant Summary collapse
- DEFAULT_PERIOD =
360- DEFAULT_FEES =
0- DEFAULT_POINTS =
0
Instance Attribute Summary collapse
-
#fees ⇒ Object
readonly
Returns the value of attribute fees.
-
#interest_rate ⇒ Object
readonly
Returns the value of attribute interest_rate.
-
#loan_amount ⇒ Object
readonly
Returns the value of attribute loan_amount.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #apr ⇒ Object
-
#initialize(params = {}) ⇒ MortgageCost
constructor
Parameters [:loan_amount] Loan amount.
- #monthly_payment ⇒ Object
- #monthly_payment_with_fees ⇒ Object
- #total_fees(negative_allowed = false) ⇒ Object
Methods included from SafeNum
Methods included from Monthly
Constructor Details
#initialize(params = {}) ⇒ MortgageCost
Parameters
- :loan_amount
-
Loan amount. Price of home minus down payment
- :interest_rate
-
The interest rate of the loan
- :period
-
Number of months of the loan. 30 yr is 360. 15 yr is 189
- :fees
-
Closing cost fees. Optional and defaults to 0
- :points
-
Points. Optional and defaults to 0
15 16 17 18 19 20 21 22 23 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 15 def initialize(params={}) raise '[:loan_amount] required' if params[:loan_amount].blank? raise '[:interest_rate] required' if params[:interest_rate].blank? @loan_amount = safe_float params[:loan_amount] @interest_rate = safe_float params[:interest_rate] @period = safe_int params.fetch(:period, DEFAULT_PERIOD) @fees = safe_int params.fetch(:fees, DEFAULT_FEES) @points = safe_float params.fetch(:points, DEFAULT_POINTS) end |
Instance Attribute Details
#fees ⇒ Object (readonly)
Returns the value of attribute fees.
4 5 6 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 4 def fees @fees end |
#interest_rate ⇒ Object (readonly)
Returns the value of attribute interest_rate.
4 5 6 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 4 def interest_rate @interest_rate end |
#loan_amount ⇒ Object (readonly)
Returns the value of attribute loan_amount.
4 5 6 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 4 def loan_amount @loan_amount end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
4 5 6 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 4 def period @period end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
4 5 6 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 4 def points @points end |
Instance Method Details
#apr ⇒ Object
25 26 27 28 29 30 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 25 def apr @apr ||= MortgageBuddy::AprCalculator.new(loan_amount: @loan_amount, monthly_payment_with_fees: monthly_payment_with_fees, period: period, monthly_interest_rate: monthly_interest_rate).apr end |
#monthly_payment ⇒ Object
32 33 34 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 32 def monthly_payment @monthly_payment ||= calculate_monthly_payment(@loan_amount, monthly_interest_rate, @period) end |
#monthly_payment_with_fees ⇒ Object
36 37 38 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 36 def monthly_payment_with_fees @monthly_payment_with_fees ||= calculate_monthly_payment(@loan_amount + total_fees, monthly_interest_rate, @period) end |
#total_fees(negative_allowed = false) ⇒ Object
40 41 42 43 44 |
# File 'lib/mortgage_buddy/mortgage_cost.rb', line 40 def total_fees(negative_allowed = false) #fees may not be negative (borrower is not paid) total_fees = calculate_total_fees !negative_allowed && total_fees < 0 ? 0 : total_fees end |