Class: AdHonorem::Progress
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AdHonorem::Progress
- Defined in:
- lib/adhonorem/models/progress.rb
Overview
Store users’ progress in database for each badge triggered at least once
Constant Summary collapse
- PROGRESS_TYPES =
{ numeric: :capped_numeric_progress, percentage: :percentage_progress, stringified: :stringified_progress }.freeze
Instance Method Summary collapse
- #advance(amount = 1) ⇒ Object
- #done? ⇒ Boolean
- #objective ⇒ Object
- #progress(progress_type = :numeric) ⇒ Object
Instance Method Details
#advance(amount = 1) ⇒ Object
14 15 16 17 18 |
# File 'lib/adhonorem/models/progress.rb', line 14 def advance(amount = 1) return if done? self.numeric_progress += amount save end |
#done? ⇒ Boolean
24 25 26 |
# File 'lib/adhonorem/models/progress.rb', line 24 def done? numeric_progress >= objective.amount_needed end |
#objective ⇒ Object
20 21 22 |
# File 'lib/adhonorem/models/progress.rb', line 20 def objective badge.objectives[objective_slug.to_sym] end |
#progress(progress_type = :numeric) ⇒ Object
28 29 30 31 |
# File 'lib/adhonorem/models/progress.rb', line 28 def progress(progress_type = :numeric) raise AdHonorem::NotSuchProgressType unless PROGRESS_TYPES.keys.include?(progress_type) send(PROGRESS_TYPES[progress_type]) end |