Class: Decidim::Gamification::Badge
- Inherits:
-
Object
- Object
- Decidim::Gamification::Badge
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/decidim/gamification/badge.rb
Overview
This class represents an abstract badge. Instances of this class can define different badge types with different rules such as gaining new levels, etc.
Instance Method Summary collapse
-
#image ⇒ Object
Public: Returns an image for this badge.
-
#level_of(score) ⇒ Object
Public: Returns the level for this badge given a score.
Instance Method Details
#image ⇒ Object
Public: Returns an image for this badge.
Returns a String with the image.
49 50 51 |
# File 'lib/decidim/gamification/badge.rb', line 49 def image ActionController::Base.helpers.asset_path("decidim/gamification/badges/#{name}.svg") end |
#level_of(score) ⇒ Object
Public: Returns the level for this badge given a score.
Returns an Integer with the level.
38 39 40 41 42 43 44 |
# File 'lib/decidim/gamification/badge.rb', line 38 def level_of(score) levels.each_with_index do |threshold, index| return index if threshold > score end levels.length end |