Class: SpreadsheetLoanGenerator::Loan
- Inherits:
-
Object
- Object
- SpreadsheetLoanGenerator::Loan
- Defined in:
- lib/spreadsheet_loan_generator/loan.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#deferred ⇒ Object
Returns the value of attribute deferred.
-
#deferred_and_capitalized ⇒ Object
Returns the value of attribute deferred_and_capitalized.
-
#due_on ⇒ Object
Returns the value of attribute due_on.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#interests_type ⇒ Object
Returns the value of attribute interests_type.
-
#period_duration ⇒ Object
Returns the value of attribute period_duration.
-
#rate ⇒ Object
Returns the value of attribute rate.
-
#starting_capitalized_interests ⇒ Object
Returns the value of attribute starting_capitalized_interests.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #bullet? ⇒ Boolean
- #fully_deferred? ⇒ Boolean
- #in_fine? ⇒ Boolean
-
#initialize(amount:, duration:, period_duration:, rate:, due_on:, deferred_and_capitalized:, deferred:, type:, interests_type:, starting_capitalized_interests:) ⇒ Loan
constructor
A new instance of Loan.
- #interests_formula ⇒ Object
- #loan_type_formula ⇒ Object
- #name ⇒ Object
- #name_deferred ⇒ Object
- #name_due_on ⇒ Object
- #name_period_duration ⇒ Object
- #name_type ⇒ Object
- #non_deferred_duration ⇒ Object
- #print_validation_errors ⇒ Object
- #total_deferred_duration ⇒ Object
Constructor Details
#initialize(amount:, duration:, period_duration:, rate:, due_on:, deferred_and_capitalized:, deferred:, type:, interests_type:, starting_capitalized_interests:) ⇒ Loan
Returns a new instance of Loan.
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 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 14 def initialize( amount:, duration:, period_duration:, rate:, due_on:, deferred_and_capitalized:, deferred:, type:, interests_type:, starting_capitalized_interests:) @amount = amount.to_f @duration = duration.to_i @period_duration = period_duration.to_i @rate = rate.to_f @due_on = due_on.is_a?(Date) ? due_on : Date.parse(due_on) @deferred_and_capitalized = deferred_and_capitalized.to_i @deferred = deferred.to_i @type = type @interests_type = interests_type @starting_capitalized_interests = starting_capitalized_interests.to_f print_validation_errors end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def amount @amount end |
#deferred ⇒ Object
Returns the value of attribute deferred.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def deferred @deferred end |
#deferred_and_capitalized ⇒ Object
Returns the value of attribute deferred_and_capitalized.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def deferred_and_capitalized @deferred_and_capitalized end |
#due_on ⇒ Object
Returns the value of attribute due_on.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def due_on @due_on end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def duration @duration end |
#interests_type ⇒ Object
Returns the value of attribute interests_type.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def interests_type @interests_type end |
#period_duration ⇒ Object
Returns the value of attribute period_duration.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def period_duration @period_duration end |
#rate ⇒ Object
Returns the value of attribute rate.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def rate @rate end |
#starting_capitalized_interests ⇒ Object
Returns the value of attribute starting_capitalized_interests.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def starting_capitalized_interests @starting_capitalized_interests end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 3 def type @type end |
Instance Method Details
#bullet? ⇒ Boolean
106 107 108 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 106 def bullet? fully_deferred? && deferred_and_capitalized == total_deferred_duration end |
#fully_deferred? ⇒ Boolean
102 103 104 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 102 def fully_deferred? duration > 1 && non_deferred_duration == 1 end |
#in_fine? ⇒ Boolean
110 111 112 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 110 def in_fine? fully_deferred? && deferred == total_deferred_duration end |
#interests_formula ⇒ Object
52 53 54 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 52 def interests_formula "SpreadsheetLoanGenerator::#{interests_type.classify}Interests".constantize.new(loan: self) end |
#loan_type_formula ⇒ Object
48 49 50 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 48 def loan_type_formula "SpreadsheetLoanGenerator::#{type.classify}".constantize.new(loan: self) end |
#name ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 86 def name args = [] args += ['realistic'] if interests_type == 'realistic' args += [ name_type, name_period_duration, amount, (rate * 100).to_s, duration.to_s, name_deferred, name_due_on ] args.join('_') end |
#name_deferred ⇒ Object
76 77 78 79 80 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 76 def name_deferred return '0' if fully_deferred? total_deferred_duration end |
#name_due_on ⇒ Object
82 83 84 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 82 def name_due_on due_on.strftime('%Y%m%d') end |
#name_period_duration ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 63 def name_period_duration if period_duration.in?([1, 3, 6, 12]) { '1' => 'month', '3' => 'quarter', '6' => 'semester', '12' => 'year' }[period_duration.to_s] else period_duration.to_s end end |
#name_type ⇒ Object
56 57 58 59 60 61 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 56 def name_type return 'bullet' if bullet? return 'in_fine' if in_fine? type end |
#non_deferred_duration ⇒ Object
114 115 116 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 114 def non_deferred_duration duration - total_deferred_duration end |
#print_validation_errors ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 40 def print_validation_errors puts 'amount < 0' if amount < 0 puts 'deferred & deferred_and_capitalized >= duration' if total_deferred_duration >= duration if type == 'standard' && interests_type == 'realistic' && !fully_deferred? puts 'standard & realistic interests do not work together' end end |
#total_deferred_duration ⇒ Object
118 119 120 |
# File 'lib/spreadsheet_loan_generator/loan.rb', line 118 def total_deferred_duration deferred_and_capitalized + deferred end |