class Decidim::Gamification::Badge
This class represents an abstract badge. Instances of this class can define different badge types with different rules such as gaining new levels, etc.
Public Instance Methods
conditions()
click to toggle source
# File lib/decidim/gamification/badge.rb, line 57 def conditions I18n.t("conditions", scope: translation_scope) end
description(organization_name = nil)
click to toggle source
# File lib/decidim/gamification/badge.rb, line 53 def description(organization_name = nil) I18n.t("description", organization_name: organization_name, scope: translation_scope) end
image()
click to toggle source
Public: Returns an image for this badge.
Returns a String with the image.
# File lib/decidim/gamification/badge.rb, line 73 def image ActionController::Base.helpers.asset_path("decidim/gamification/badges/#{name}.svg") end
level_of(score)
click to toggle source
Public: Returns the level for this badge given a score.
Returns an Integer with the level.
# File lib/decidim/gamification/badge.rb, line 41 def level_of(score) levels.each_with_index do |threshold, index| return index if threshold > score end levels.length end
score_descriptions(score)
click to toggle source
# File lib/decidim/gamification/badge.rb, line 61 def score_descriptions(score) { unearned_own: I18n.t("unearned_own", scope: translation_scope), description_own: I18n.t("description_own", score: score, scope: translation_scope), unearned_another: I18n.t("unearned_another", scope: translation_scope), description_another: I18n.t("description_another", score: score, scope: translation_scope) } end
translated_name()
click to toggle source
# File lib/decidim/gamification/badge.rb, line 49 def translated_name I18n.t "name", scope: translation_scope end
valid_for?(model)
click to toggle source
# File lib/decidim/gamification/badge.rb, line 77 def valid_for?(model) valid_for.include?(model.class.name.demodulize.underscore.to_sym) end
Private Instance Methods
translation_scope()
click to toggle source
# File lib/decidim/gamification/badge.rb, line 83 def translation_scope "decidim.gamification.badges.#{name}" end