Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def manual?
# @param user [User, nil] user to get the percent for
# @return [Integer] edit score percent
def edit_score_percent_for(user)
return 0 if edit_score_threshold.nil? || user.nil?
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)
Expand All @@ -25,7 +25,7 @@ def edit_score_percent_for(user)
# @param user [User, nil] user to get the percent for
# @return [Integer] flag score percent
def flag_score_percent_for(user)
return 0 if flag_score_threshold.nil? || user.nil?
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)
Expand All @@ -38,7 +38,7 @@ def flag_score_percent_for(user)
# @param user [User, nil] user to get the percent for
# @return [Integer] post score percent
def post_score_percent_for(user)
return 0 if post_score_threshold.nil? || user.nil?
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)
Expand All @@ -65,4 +65,13 @@ def self.trust_levels
def self.[](key)
find_by internal_id: key
end

private

# Is a given threshold never reachable for a given user?
# @param threshold [Numeric] threshold to check
# @param user [User, nil] user to check
def unreachable_threshold_for?(threshold, user)
threshold.nil? || threshold.negative? || user.nil?
end
end
Loading