Class: LoanCreator::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/loan_creator/term.rb

Constant Summary collapse

ARGUMENTS =
[
  # Remaining due capital at the beginning of the term
  :crd_beginning_of_period,

  # Remaining due capital at the end of the term
  :crd_end_of_period,

  # Theoricaly due interests
  :period_theoric_interests,

  # Difference between theorical and real (rounded) due interests
  :delta_interests,

  # Accrued interests' delta
  :accrued_delta_interests,

  # Capitalized interests at the beginning of the term (Bullet only)
  :capitalized_interests_beginning_of_period,

  # Capitalized interests at the end of the term (Bullet only)
  :capitalized_interests_end_of_period,

  # Adjustment of -0.01, 0 or +0.01 cent depending on accrued_delta_interests
  :amount_to_add,

  # Interests to pay this term
  :period_interests,

  # Capital to pay this term
  :period_capital,

  # Total capital paid so far (including current term)
  :total_paid_capital_end_of_period,

  # Total interests paid so far (including current term)
  :total_paid_interests_end_of_period,

  # Amount to pay this term
  :period_amount_to_pay
].freeze
OPTIONAL_ARGUMENTS =
[
  # Term number (starts at 1)
  # This value is to be set by Timetable
  :index,

  # Term date
  # This value is to be set by Timetable
  :due_on,
]
ATTRIBUTES =
(ARGUMENTS + OPTIONAL_ARGUMENTS).freeze

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Term

Returns a new instance of Term.



59
60
61
62
# File 'lib/loan_creator/term.rb', line 59

def initialize(**options)
  ARGUMENTS.each { |k| instance_variable_set(:"@#{k}", options.fetch(k)) }
  OPTIONAL_ARGUMENTS.each { |k| instance_variable_set(:"@#{k}", options.fetch(k, nil)) }
end

Instance Method Details

#to_csvObject



64
65
66
# File 'lib/loan_creator/term.rb', line 64

def to_csv
  ATTRIBUTES.map { |k| instance_variable_get(:"@#{k}") }.join(',')
end

#to_hObject



72
73
74
# File 'lib/loan_creator/term.rb', line 72

def to_h
  ATTRIBUTES.each_with_object({}) { |k, h| h[k] = instance_variable_get(:"@#{k}") }
end

#to_sObject



68
69
70
# File 'lib/loan_creator/term.rb', line 68

def to_s
  to_csv
end