Class: Mortgagerb::Scenario

Inherits:
Object
  • Object
show all
Defined in:
lib/mortgagerb/scenario.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount, rate, type) ⇒ Scenario

Returns a new instance of Scenario.



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

def initialize(amount, rate, type)
  @amount = amount
  @rate = rate
  @type = type
  @amortization_payment = nil
  @principal = nil
end

Instance Attribute Details

#amortization_paymentObject

Returns the value of attribute amortization_payment.



3
4
5
# File 'lib/mortgagerb/scenario.rb', line 3

def amortization_payment
  @amortization_payment
end

#principalObject

Returns the value of attribute principal.



3
4
5
# File 'lib/mortgagerb/scenario.rb', line 3

def principal
  @principal
end

Instance Method Details

#calculateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mortgagerb/scenario.rb', line 13

def calculate
  if %i[thirty_year_fixed three_year_arm five_year_arm seven_year_arm ten_year_arm].include?(@type)
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(30)
    @amortization_payment = Calculator.periodic_amortization_payment(@amount, r, n)
  elsif %i[thirty_year_fixed_get_pricipal three_year_arm_get_principal five_year_arm_get_principal
           seven_year_arm_get_principal ten_year_arm_get_principal].include?(@type)
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(30)
    @principal = Calculator.principal_from_amortization_payment(@amount, r, n)
  elsif @type === :twenty_year_fixed
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(20)
    @amortization_payment = Calculator.periodic_amortization_payment(@amount, r, n)
  elsif @type === :twenty_year_fixed_get_principal
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(20)
    @principal = Calculator.principal_from_amortization_payment(@amount, r, n)
  elsif @type === :fifteen_year_fixed
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(15)
    @amortization_payment = Calculator.periodic_amortization_payment(@amount, r, n)
  elsif @type === :fifteen_year_fixed_get_principal
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(15)
    @principal = Calculator.principal_from_amortization_payment(@amount, r, n)
  elsif @type === :ten_year_fixed
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(10)
    @amortization_payment = Calculator.periodic_amortization_payment(@amount, r, n)
  elsif @type === :ten_year_fixed_get_principal
    r = Calculator.periodic_interest_rate(@rate)
    n = Calculator.total_number_of_payments(10)
    @principal = Calculator.principal_from_amortization_payment(@amount, r, n)
  end
end