Class: BlendSpreadsheetLoanGenerator::Loan
- Inherits:
-
Object
- Object
- BlendSpreadsheetLoanGenerator::Loan
- Defined in:
- lib/blend_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.
-
#fees_rate ⇒ Object
Returns the value of attribute fees_rate.
-
#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_fees ⇒ Object
Returns the value of attribute starting_capitalized_fees.
-
#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
- #bullet_term?(term) ⇒ 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:, fees_rate:, starting_capitalized_fees:) ⇒ 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:, fees_rate:, starting_capitalized_fees:) ⇒ Loan
Returns a new instance of Loan.
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 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 16 def initialize( amount:, duration:, period_duration:, rate:, due_on:, deferred_and_capitalized:, deferred:, type:, interests_type:, starting_capitalized_interests:, fees_rate:, starting_capitalized_fees:) @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 @fees_rate = fees_rate.to_f @starting_capitalized_interests = starting_capitalized_interests.to_f @starting_capitalized_fees = starting_capitalized_fees.to_f print_validation_errors end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
3 4 5 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 3 def amount @amount end |
#deferred ⇒ Object
Returns the value of attribute deferred.
3 4 5 |
# File 'lib/blend_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/blend_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/blend_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/blend_spreadsheet_loan_generator/loan.rb', line 3 def duration @duration end |
#fees_rate ⇒ Object
Returns the value of attribute fees_rate.
3 4 5 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 3 def fees_rate @fees_rate end |
#interests_type ⇒ Object
Returns the value of attribute interests_type.
3 4 5 |
# File 'lib/blend_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/blend_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/blend_spreadsheet_loan_generator/loan.rb', line 3 def rate @rate end |
#starting_capitalized_fees ⇒ Object
Returns the value of attribute starting_capitalized_fees.
3 4 5 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 3 def starting_capitalized_fees @starting_capitalized_fees end |
#starting_capitalized_interests ⇒ Object
Returns the value of attribute starting_capitalized_interests.
3 4 5 |
# File 'lib/blend_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/blend_spreadsheet_loan_generator/loan.rb', line 3 def type @type end |
Instance Method Details
#bullet? ⇒ Boolean
111 112 113 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 111 def bullet? fully_deferred? && deferred_and_capitalized == total_deferred_duration end |
#bullet_term?(term) ⇒ Boolean
115 116 117 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 115 def bullet_term?(term) deferred_and_capitalized >= term || bullet? # for last term end |
#fully_deferred? ⇒ Boolean
107 108 109 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 107 def fully_deferred? duration > 1 && non_deferred_duration == 1 end |
#in_fine? ⇒ Boolean
119 120 121 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 119 def in_fine? fully_deferred? && deferred == total_deferred_duration end |
#interests_formula ⇒ Object
57 58 59 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 57 def interests_formula "BlendSpreadsheetLoanGenerator::#{interests_type.classify}Interests".constantize.new(loan: self) end |
#loan_type_formula ⇒ Object
53 54 55 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 53 def loan_type_formula "BlendSpreadsheetLoanGenerator::#{type.classify}".constantize.new(loan: self) end |
#name ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 91 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
81 82 83 84 85 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 81 def name_deferred return '0' if fully_deferred? total_deferred_duration end |
#name_due_on ⇒ Object
87 88 89 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 87 def name_due_on due_on.strftime('%Y%m%d') end |
#name_period_duration ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 68 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
61 62 63 64 65 66 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 61 def name_type return 'bullet' if bullet? return 'in_fine' if in_fine? type end |
#non_deferred_duration ⇒ Object
123 124 125 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 123 def non_deferred_duration duration - total_deferred_duration end |
#print_validation_errors ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 45 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
127 128 129 |
# File 'lib/blend_spreadsheet_loan_generator/loan.rb', line 127 def total_deferred_duration deferred_and_capitalized + deferred end |