Class: Calculus::Loan

Inherits:
Object
  • Object
show all
Defined in:
lib/calculus/loan.rb

Instance Method Summary collapse

Constructor Details

#initialize(amount, count, options = {}) ⇒ Loan

Returns a new instance of Loan.


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/calculus/loan.rb', line 3

def initialize(amount, count, options = {})
  @amount = amount
  @count = count
  @interests  = options[:interests] || {}
  @insurances = options[:insurances] || {}
  @period = options[:period] || 1
  @length = options[:length] || 1.year
  @precision = options[:precision] || 2
  @shift = options[:shift] || 0
  @shift_method = options[:shift_method] || :immediate_payment
  @insurance_method = :"compute_#{options[:insurance_method]}_insurance" || :compute_to_repay_insurance
  @started_on = options[:started_on] || Time.zone.today
end

Instance Method Details

#compute_repayments(repayment_method) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/calculus/loan.rb', line 17

def compute_repayments(repayment_method)
  array = send("compute_#{repayment_method}_repayments")
  array.last[:base_amount] += array.last[:remaining_amount]
  array.last[:remaining_amount] = 0.0
  due_on = @started_on # why ? + 1.month
  array.each_with_index do |r, index|
    r[:due_on] = due_on
    r[:position] = index + 1
    due_on += @length
  end
  array
end