Class: Ability
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Ability
- Includes:
- AbilitiesHelper, CommunityRelated
- Defined in:
- /var/apps/qpixel/app/models/ability.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#edit_score_percent_for(user) ⇒ Integer
Gets the edit score percent for a given user.
-
#flag_score_percent_for(user) ⇒ Integer
Gets the flag score percent for a given user.
- #manual? ⇒ Boolean
-
#post_score_percent_for(user) ⇒ Integer
Gets the post score percent for a given user.
Methods included from AbilitiesHelper
#ability_err_msg, #ability_link, #linearize_progress
Methods inherited from ApplicationRecord
#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules
Class Method Details
.[](key) ⇒ Object
66 67 68 |
# File '/var/apps/qpixel/app/models/ability.rb', line 66 def self.[](key) find_by internal_id: key end |
.on_user(user) ⇒ Object
51 52 53 |
# File '/var/apps/qpixel/app/models/ability.rb', line 51 def self.on_user(user) Ability.where(id: UserAbility.where(community_user: user.community_user).select(:ability_id).distinct) end |
.trust_levels ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File '/var/apps/qpixel/app/models/ability.rb', line 55 def self.trust_levels { 0 => 'everyone', 1 => 'anyone with a user account', 2 => 'all but new users', 3 => 'veteran users', 4 => 'moderators only', 5 => 'staff only' } end |
Instance Method Details
#edit_score_percent_for(user) ⇒ Integer
Gets the edit score percent for a given user
15 16 17 18 19 20 21 22 23 |
# File '/var/apps/qpixel/app/models/ability.rb', line 15 def edit_score_percent_for(user) return 0 if unreachable_threshold_for?(edit_score_threshold, user) return 100 if edit_score_threshold.zero? linear_score = linearize_progress(user.community_user.edit_score) linear_threshold = linearize_progress(edit_score_threshold) (linear_score / linear_threshold * 100).to_i end |
#flag_score_percent_for(user) ⇒ Integer
Gets the flag score percent for a given user
28 29 30 31 32 33 34 35 36 |
# File '/var/apps/qpixel/app/models/ability.rb', line 28 def flag_score_percent_for(user) return 0 if unreachable_threshold_for?(flag_score_threshold, user) return 100 if flag_score_threshold.zero? linear_score = linearize_progress(user.community_user.flag_score) linear_threshold = linearize_progress(flag_score_threshold) (linear_score / linear_threshold * 100).to_i end |
#manual? ⇒ Boolean
8 9 10 |
# File '/var/apps/qpixel/app/models/ability.rb', line 8 def manual? post_score_threshold.nil? && edit_score_threshold.nil? && flag_score_threshold.nil? end |
#post_score_percent_for(user) ⇒ Integer
Gets the post score percent for a given user
41 42 43 44 45 46 47 48 49 |
# File '/var/apps/qpixel/app/models/ability.rb', line 41 def post_score_percent_for(user) return 0 if unreachable_threshold_for?(post_score_threshold, user) return 100 if post_score_threshold.zero? linear_score = linearize_progress(user.community_user.post_score) linear_threshold = linearize_progress(post_score_threshold) (linear_score / linear_threshold * 100).to_i end |