loan_creator 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f7d2dcd74aa8a01bb25577eaf1c6ea05daba9eef071d76119d7ad00773fe0f7
4
- data.tar.gz: ed40fe1ff5610cbef9bc5c5c92f31095a0eaa6ad745a8f194861e65d5b8e316b
3
+ metadata.gz: 9a85f9d61c45df0f972e329a33a1beedbedc1e0090d481613e93ad90d66dea98
4
+ data.tar.gz: 7dab891b9a5d3acefb8d6cd43eef0bdb5cfe511631f5674ae655046cda11ca25
5
5
  SHA512:
6
- metadata.gz: 16256ac04047a1b505e37dddec9299d5409d1940dfe2d7271ebc0cc5207bfb5301f3375fbf3f793cb5a70dbacab3e5a7c3c6bd87d07c6449faeba2dd73368f71
7
- data.tar.gz: 4fe77879f1dfa61adecaf5d30dcf2dd5d6c501c1d82b75232cd106ffa827c440d52326a37c25bc939f445010ab7c4d256527e92edef2124d3c6ed8369337c0eb
6
+ metadata.gz: f92cd167e57a06b93169011fe8c178e7e3f434dc4c99c4a9458fb29501dd643d6011da2b8af7adfd94dd7412e7e0cd9566f281c5ff3331815daa2aa39bc27d58
7
+ data.tar.gz: c21997ee861f81b7ad4a28b334f2f1d4258e2df54eb01865de79e0b30dae5abba1d4a6771055564a6e349d16ad07ea82e6aac57a3f35ef70fee07c9ba8f94f6a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ v0.12.0
2
+ -------------------------
3
+ - improve argument error management and allow amount equal to zero.
4
+
5
+ v0.11.0
6
+ -------------------------
7
+ - add `multi_part_interests_calculation` option.
8
+
9
+ v0.10.0
10
+ -------------------------
11
+ - fix `term_dates` options, notably with `starts_on`.
12
+
1
13
  v0.9.1
2
14
  -------------------------
3
15
  - add spec importer `scripts/convert_export_to_spec.rb {csv_url}`
@@ -107,20 +107,34 @@ module LoanCreator
107
107
  OPTIONAL_ATTRIBUTES.each { |k, v| instance_variable_set(:"@#{k}", @options.fetch(k, v)) }
108
108
  end
109
109
 
110
- def validate(key, &block)
111
- raise unless block.call(instance_variable_get(:"@#{key}"))
112
- rescue => e
113
- raise ArgumentError.new([key, e.message].join(': '))
110
+ def validate(message, &block)
111
+ raise ArgumentError.new(message) unless block.call
114
112
  end
115
113
 
116
114
  def validate_attributes
117
- validate(:period) { |v| PERIODS_IN_MONTHS.keys.include?(v) } unless term_dates?
118
- validate(:amount) { |v| v.is_a?(BigDecimal) && v > 0 }
119
- validate(:annual_interests_rate) { |v| v.is_a?(BigDecimal) && v >= 0 }
120
- validate(:starts_on) { |v| v.is_a?(Date) }
121
- validate(:duration_in_periods) { |v| v.is_a?(Integer) && v > 0 }
122
- validate(:deferred_in_periods) { |v| v.is_a?(Integer) && v >= 0 && v < duration_in_periods }
123
- validate_term_dates if term_dates?
115
+ validate("amount #{@amount} must be positive") do
116
+ @amount.is_a?(BigDecimal) && @amount >= 0
117
+ end
118
+ validate("annual_interests_rate #{@annual_interests_rate} must be positive") do
119
+ @annual_interests_rate.is_a?(BigDecimal) && @annual_interests_rate >= 0
120
+ end
121
+ validate("starts_on #{@starts_on} must be a date but is a #{@starts_on.class}") do
122
+ @starts_on.is_a?(Date)
123
+ end
124
+ validate("duration_in_periods #{@duration_in_periods} must be positive") do
125
+ @duration_in_periods.is_a?(Integer) && @duration_in_periods > 0
126
+ end
127
+ validate("deferred_in_periods #{@deferred_in_periods} must be positive and less than duration_in_periods #{@duration_in_periods}") do
128
+ @deferred_in_periods.is_a?(Integer) && @deferred_in_periods >= 0 && @deferred_in_periods < duration_in_periods
129
+ end
130
+ if term_dates?
131
+ validate_term_dates
132
+ else
133
+ validate("period #{@period} must be in #{PERIODS_IN_MONTHS}") do
134
+ PERIODS_IN_MONTHS.keys.include?(@period)
135
+ end
136
+ end
137
+
124
138
  end
125
139
 
126
140
  def validate_term_dates
@@ -135,10 +149,18 @@ module LoanCreator
135
149
  def validate_initial_values
136
150
  return if initial_values.blank?
137
151
 
138
- validate(:total_paid_capital_end_of_period) { |v| v.is_a?(BigDecimal) && v >= 0 }
139
- validate(:total_paid_interests_end_of_period) { |v| v.is_a?(BigDecimal) && v >= 0 }
140
- validate(:accrued_delta_interests) { |v| v.is_a?(BigDecimal) }
141
- validate(:starting_index) { |v| v.is_a?(Integer) && v >= 0 }
152
+ validate("total_paid_capital_end_of_period #{@total_paid_capital_end_of_period} must be positive") do
153
+ @total_paid_capital_end_of_period.is_a?(BigDecimal) && @total_paid_capital_end_of_period >= 0
154
+ end
155
+ validate("total_paid_interests_end_of_period #{@total_paid_interests_end_of_period} must be positive") do
156
+ @total_paid_interests_end_of_period.is_a?(BigDecimal) && @total_paid_interests_end_of_period >= 0
157
+ end
158
+ validate("accrued_delta_interests must be a BigDecimal but is a #{@accrued_delta_interests.class}") do
159
+ @accrued_delta_interests.is_a?(BigDecimal)
160
+ end
161
+ validate("starting_index #{@starting_index} must be positive") do
162
+ @starting_index.is_a?(Integer) && @starting_index >= 0
163
+ end
142
164
  end
143
165
 
144
166
  def set_initial_values
@@ -1,3 +1,3 @@
1
1
  module LoanCreator
2
- VERSION = '0.11.0'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loan_creator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thibaulth
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2021-11-03 00:00:00.000000000 Z
15
+ date: 2022-07-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler