Module: AbilitiesHelper
- Defined in:
- app/helpers/abilities_helper.rb
Instance Method Summary collapse
-
#ability_err_msg(internal_id, action = nil) ⇒ String
Provides an error message for when a user is unable to complete an ability-restricted action, either because the user doesn’t have the ability or because it has been suspended.
-
#linearize_progress(score) ⇒ Float
Linearizes the Wilson-score progress used by ability calculations.
Instance Method Details
#ability_err_msg(internal_id, action = nil) ⇒ String
Provides an error message for when a user is unable to complete an ability-restricted action, either because the user doesn’t have the ability or because it has been suspended.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/abilities_helper.rb', line 18 def ability_err_msg(internal_id, action = nil) ability = Ability.find_by internal_id: internal_id ua = current_user&.privilege(ability.internal_id) if ua&.suspended? if action.nil? "Your use of the #{ability.name} ability has been temporarily suspended. " \ "See /abilities/#{ability.internal_id} for more information." else "Your use of the #{ability.name} ability has been temporarily suspended, so you cannot #{action}." \ "See /abilities/#{ability.internal_id} for more information." end else if action.nil? "You need the #{ability.name} ability to do this." \ "See /abilities/#{ability.internal_id} for more information." else "You need the #{ability.name} ability to #{action}." \ "See /abilities/#{ability.internal_id} for more information." end end end |
#linearize_progress(score) ⇒ Float
Linearizes the Wilson-score progress used by ability calculations. For example, 0.98 and 0.99 are not far away on a linear scale, but mean a change of about 2x for the actual limit used by the algorithm. This method takes that into account and provides an indicator of progress on a linear scale, for use in progress bars.
8 9 10 11 |
# File 'app/helpers/abilities_helper.rb', line 8 def linearize_progress(score) linear_score = ((4 * score) - 2) / (1 - score) [0, linear_score].max.to_f end |