Module: EffectiveCpdStatement
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_cpd_statement.rb
Overview
EffectiveCpdStatement
Mark your owner model with effective_cpd_statement to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #carry_forward ⇒ Object
- #completed? ⇒ Boolean (also: #submitted?)
- #import!(date: nil) ⇒ Object
- #in_progress? ⇒ Boolean
-
#round_amount(amount) ⇒ Decimal
This method is used in CpdScore#score so it can be overridden to provide a custom round score calculation.
-
#score_per_category ⇒ Object
=> 20, category_id => 15.
-
#submit! ⇒ Object
This is the review step where they click Submit Ballot.
- #target_score ⇒ Object
- #target_score_required_to_submit? ⇒ Boolean
- #to_s ⇒ Object
-
#unsubmit! ⇒ Object
Called by admin only.
Instance Method Details
#carry_forward ⇒ Object
145 146 147 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 145 def carry_forward cpd_statement_activities.sum { |activity| activity.carry_forward || BigDecimal(0) }.to_d end |
#completed? ⇒ Boolean Also known as: submitted?
132 133 134 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 132 def completed? submitted_at.present? end |
#import!(date: nil) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 106 def import!(date: nil) date ||= Time.zone.now wizard_steps[:start] ||= date wizard_steps[:activities] ||= date cpd_statement_activities.each { |activity| activity.importing = true } save! end |
#in_progress? ⇒ Boolean
128 129 130 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 128 def in_progress? submitted_at.blank? end |
#round_amount(amount) ⇒ Decimal
This method is used in CpdScore#score so it can be overridden to provide a custom round score calculation. Any model that is a statement can override this method to provide a custom round score calculation.
166 167 168 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 166 def round_amount(amount) return amount end |
#score_per_category ⇒ Object
=> 20, category_id => 15
150 151 152 153 154 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 150 def score_per_category @score_per_category ||= Hash.new(BigDecimal(0)).tap do |scores| cpd_statement_activities.each { |activity| scores[activity.cpd_category_id] += activity.score.to_d } end end |
#submit! ⇒ Object
This is the review step where they click Submit Ballot
117 118 119 120 121 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 117 def submit! wizard_steps[:complete] ||= Time.zone.now update!(submitted_at: Time.zone.now) end |
#target_score ⇒ Object
137 138 139 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 137 def target_score user.cpd_target_score(cpd_cycle: cpd_cycle) end |
#target_score_required_to_submit? ⇒ Boolean
141 142 143 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 141 def target_score_required_to_submit? user.cpd_target_score_required_to_submit?(cpd_cycle: cpd_cycle) end |
#to_s ⇒ Object
102 103 104 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 102 def to_s cpd_cycle.present? ? "#{cpd_cycle} #{model_name.human}" : model_name.human end |
#unsubmit! ⇒ Object
Called by admin only. This is an exceptional action
124 125 126 |
# File 'app/models/concerns/effective_cpd_statement.rb', line 124 def unsubmit! update!(wizard_steps: {}, submitted_at: nil, confirm_readonly: nil) end |