effective_cpd 1.6.5 → 1.7.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: cd0911046fcabd42cad5f51a9d1839bb13da67a67276d78bc4c0a3414a1d0e85
4
- data.tar.gz: 1f16f8296435282c808e2fb1e5e4aeff7e0aa1ba40c252c478ff1dd955a930e6
3
+ metadata.gz: 94c7c2fc57c5109c37e1ae0216f297eebb6556210e96db897e6592cd357b49e7
4
+ data.tar.gz: 2561bc3bae5ca830c72ad9b3499b0e303db66fa5121c685b2d15fb3a5743da85
5
5
  SHA512:
6
- metadata.gz: 3bf52660128e824a470059d1399cc8321038a87d67bd56c101d4f57b959c9ecf58e577e0fb0d9e31abe5f3a5cb5c1c2cf88ebf134043fffd5570eeea67d7f7d9
7
- data.tar.gz: e242876c24636b77819f64835edc02c187776532389be838658999e2cd1136a93f67d24ea7a4e8181d1346f250989647ab58208f13a77c7884f151159d68e12f
6
+ metadata.gz: 750ffcaba4258184debafb988238cbe47774b19a74a494656d600dff4234fc1e94d057040f177f9c07348e81ad2f32258abe52f76b4d4e3a53fa163562586d97
7
+ data.tar.gz: 6571b2816b5616a2fd00928d3ebf142cf7ada391eccd5b7bfa9ca18e5ecc1708ba2d3728e5a67fe046b21879158d04ed2b45a5a3352faaae5dbcbfcc2bf28453
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Continuing professional development.
4
4
 
5
- An admin creates a set of categories, activites and rules. User enters number of hours or work done to have a scored statement. Audits.
5
+ An admin creates a set of categories, activities and rules. User enters number of hours or work done to have a scored statement. Audits.
6
6
 
7
7
  Works with action_text for content bodies, and active_storage for file uploads.
8
8
 
@@ -93,7 +93,7 @@ Use the following datatables to display to your user their statements and audits
93
93
  = render_datatable(reviewed, simple: true)
94
94
  ```
95
95
 
96
- On the Admin::Users#edit, you can use the following datatables as well:
96
+ On the `Admin::Users#edit`, you can use the following datatables as well:
97
97
 
98
98
  ```haml
99
99
  %h2 CPD Statements
@@ -138,7 +138,7 @@ Once all these 3 areas have been configured, users can submit statements and aud
138
138
 
139
139
  You can specify the required score in the CPD Cycle.
140
140
 
141
- You can also programatically do it. Add the following to your user class.
141
+ You can also programmatically do it. Add the following to your user class.
142
142
 
143
143
  ```
144
144
  # This is an ActiveRecord concern to add the has_many :cpd_statements
@@ -167,6 +167,22 @@ def cpd_statement_required_score(cpd_statement)
167
167
  end
168
168
  ```
169
169
 
170
+ ## Custom Score Rounding
171
+
172
+ In your `effective_cpd_statement` model you can override the `#round_amount` method to perform
173
+ specific rounding on the score that will be applied to `amount` and `amount2`.
174
+
175
+ Example:
176
+
177
+ ```ruby
178
+ # Rounding to the nearest 0.5
179
+ def round_amount(amount)
180
+ return 0 if amount.blank?
181
+
182
+ (amount * 2.0).round / 2.0
183
+ end
184
+ ```
185
+
170
186
  ## Rake Tasks
171
187
 
172
188
  You can use
@@ -181,7 +197,7 @@ All authorization checks are handled via the effective_resources gem found in th
181
197
 
182
198
  ## Permissions
183
199
 
184
- The permissions you actually want to define are as follows (using CanCan):
200
+ The permissions you actually want to define are as follows (using CanCanCan):
185
201
 
186
202
  ```ruby
187
203
  # Regular signed up user. Guest users not supported.
@@ -152,4 +152,18 @@ module EffectiveCpdStatement
152
152
  cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_d }
153
153
  end
154
154
  end
155
+
156
+ #
157
+ # This method is used in CpdScore#score so it can be overridden to provide a
158
+ # custom round score calculation.
159
+ # Any model that is a statement can override this method to provide a custom
160
+ # round score calculation.
161
+ #
162
+ # @param [Decimal] amount
163
+ #
164
+ # @return [Decimal] rounded decimal
165
+ #
166
+ def round_amount(amount)
167
+ return amount
168
+ end
155
169
  end
@@ -13,7 +13,7 @@ module Effective
13
13
  log_changes(to: :cpd_cycle)
14
14
  end
15
15
 
16
- # Only permit the words amount, amount2 and any charater 0-9 + - / * . ( )
16
+ # Only permit the words amount, amount2 and any character 0-9 + - / * . ( )
17
17
  INVALID_FORMULA_CHARS = /[^0-9\+\-\.\/\*\(\)]/
18
18
 
19
19
  effective_resource do
@@ -111,7 +111,14 @@ module Effective
111
111
 
112
112
  return cpd_statement_activity.carry_over if cpd_statement_activity.is_carry_over?
113
113
 
114
- eval_equation(amount: cpd_statement_activity.amount, amount2: cpd_statement_activity.amount2)
114
+ # Statements can override the #round_amount method to perform their own
115
+ # calculations. For example, a statement may round to the nearest 0.5 or
116
+ # to the nearest 0.25 or to the nearest 0.1.
117
+ statement = cpd_statement_activity.cpd_statement
118
+ amount = statement.round_amount(cpd_statement_activity.amount)
119
+ amount2 = statement.round_amount(cpd_statement_activity.amount2)
120
+
121
+ eval_equation(amount: amount, amount2: amount2)
115
122
  end
116
123
 
117
124
  private
@@ -1,3 +1,3 @@
1
1
  module EffectiveCpd
2
- VERSION = '1.6.5'
2
+ VERSION = '1.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_cpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-03 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -483,7 +483,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
483
483
  - !ruby/object:Gem::Version
484
484
  version: '0'
485
485
  requirements: []
486
- rubygems_version: 3.1.2
486
+ rubygems_version: 3.4.10
487
487
  signing_key:
488
488
  specification_version: 4
489
489
  summary: Continuing professional development and audits rails engine