From 4cb40a31a331ba15f953fc9525ccfd3e69696a56 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 12 May 2015 11:13:55 -0300 Subject: [PATCH] Improve ranking calculation --- lib/ext/profile.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ext/profile.rb b/lib/ext/profile.rb index 6aff19d..4681046 100644 --- a/lib/ext/profile.rb +++ b/lib/ext/profile.rb @@ -6,10 +6,11 @@ class Profile def gamification_plugin_calculate_level settings = GamificationPlugin.settings(environment) + score = self.points last_level = 0 - (settings.get_setting(:rank_rules) || []).sort_by {|r| r[:points] }.each do |rule| - return last_level if points < rule[:points] - last_level = rule[:level] + (settings.get_setting(:rank_rules) || []).sort_by {|r| r[:points] }.each_with_index do |rule, i| + return last_level if score < rule[:points].to_i + last_level = rule[:level] || i+1 end last_level end -- libgit2 0.21.2