Class: MortgageCalc::MortgageUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/mortgage_calc/mortgage_util.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loan_amount, interest_rate, fee, period = 360, borrowed_fees = 0) ⇒ MortgageUtil

Returns a new instance of MortgageUtil.



5
6
7
8
9
10
11
# File 'lib/mortgage_calc/mortgage_util.rb', line 5

def initialize(loan_amount, interest_rate, fee, period=360, borrowed_fees=0)
  self.loan_amount = Float(loan_amount.to_s)
  self.interest_rate = Float(interest_rate.to_s)
  self.period = Integer(period.to_s)
  self.fee = Float(fee.to_s)
  self.borrowed_fees = Float(borrowed_fees.to_s)
end

Instance Attribute Details

#borrowed_feesObject

Returns the value of attribute borrowed_fees.



3
4
5
# File 'lib/mortgage_calc/mortgage_util.rb', line 3

def borrowed_fees
  @borrowed_fees
end

#feeObject

Returns the value of attribute fee.



3
4
5
# File 'lib/mortgage_calc/mortgage_util.rb', line 3

def fee
  @fee
end

#interest_rateObject

Returns the value of attribute interest_rate.



3
4
5
# File 'lib/mortgage_calc/mortgage_util.rb', line 3

def interest_rate
  @interest_rate
end

#loan_amountObject

Returns the value of attribute loan_amount.



3
4
5
# File 'lib/mortgage_calc/mortgage_util.rb', line 3

def loan_amount
  @loan_amount
end

#periodObject

Returns the value of attribute period.



3
4
5
# File 'lib/mortgage_calc/mortgage_util.rb', line 3

def period
  @period
end

Instance Method Details

#aprObject



13
14
15
# File 'lib/mortgage_calc/mortgage_util.rb', line 13

def apr
  @apr ||= calculate_apr
end

#monthly_paymentObject



17
18
19
# File 'lib/mortgage_calc/mortgage_util.rb', line 17

def monthly_payment
  @monthly_payment ||= calculate_monthly_payment(self.loan_amount + self.borrowed_fees, monthly_interest_rate, self.period)
end