Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added total_scores method #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ Competition ranking: The `CompetitionRankingLeaderboard` subclass of `Leaderboar
total_members: Total # of members in the leaderboard
total_pages: Total # of pages in the leaderboard given the leaderboard's page_size
total_members_in_score_range(min_score, max_score): Count the number of members within a score range in the leaderboard
total_scores: Sum of scores for all members in leaderboard
change_score_for(member, delta): Change the score for a member by some amount delta (delta could be positive or negative)
rank_for(member): Retrieve the rank for a given member in the leaderboard
score_for(member): Retrieve the score for a given member in the leaderboard
Expand Down Expand Up @@ -487,4 +488,3 @@ Unofficially supported (they need some feature parity love):
## Copyright

Copyright (c) 2011-2016 David Czarnecki. See LICENSE.txt for further details.

7 changes: 7 additions & 0 deletions lib/leaderboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ def total_members_in_score_range_in(leaderboard_name, min_score, max_score)
@redis_connection.zcount(leaderboard_name, min_score, max_score)
end

# Sum of scores for all members in leaderboard
#
# @return boolean
def total_scores
all_leaders.map{|hash| hash[:score] }.sum
end

# Change the score for a member in the leaderboard by a score delta which can be positive or negative.
#
# @param member [String] Member name.
Expand Down