diff --git a/lib/competition_ranking_leaderboard.rb b/lib/competition_ranking_leaderboard.rb index 2b11b0d..c76e8be 100644 --- a/lib/competition_ranking_leaderboard.rb +++ b/lib/competition_ranking_leaderboard.rb @@ -93,7 +93,7 @@ def ranked_in_list_in(leaderboard_name, members, options = {}) end end - rankings_for_members_in(leaderboard_name, included_members, scores).each_with_index do |rank, index| + rankings_for_members_having_scores_in(leaderboard_name, included_members, scores).each_with_index do |rank, index| ranks_for_members[index][@rank_key] = rank end @@ -107,15 +107,26 @@ def ranked_in_list_in(leaderboard_name, members, options = {}) ranks_for_members end - # Retrieve a the rankings of leaders given their member ids and scores + # Retrieve a list of the rankings of leaders given their member names and scores + # + # @param members [Array] Member names. + # @param scores [Array] a list of scores for the members, aligned with the member names + # + # @return a list of the rankings for the passed in members and scores + + def rankings_for_members_having_scores(members, scores) + rankings_for_members_in(@leaderboard_name, members, scores) + end + + # Retrieve a list of the rankings of leaders given their member names and scores # # @param leaderboard_name [String] Name of the leaderboard. # @param members [Array] Member names. - # @param scores [Array] a list of scores for the members + # @param scores [Array] a list of scores for the members, aligned with the member names # # @return a list of the rankings for the passed in members and scores - def rankings_for_members_in(leaderboard_name, members, scores) + def rankings_for_members_having_scores_in(leaderboard_name, members, scores) @redis_connection.multi do |transaction| members.each_with_index do |member, index| if @reverse @@ -126,4 +137,5 @@ def rankings_for_members_in(leaderboard_name, members, scores) end end.map{|rank| rank ? rank + 1 : rank} end + end diff --git a/lib/leaderboard.rb b/lib/leaderboard.rb index 7f75a51..a5f2ed7 100644 --- a/lib/leaderboard.rb +++ b/lib/leaderboard.rb @@ -229,6 +229,15 @@ def members_data_for_in(leaderboard_name, members) @redis_connection.hmget(member_data_key(leaderboard_name), *members) end + # Retrieve the optional member data for the given members in the leaderboard. + # + # @param members [Array] Member names. + # + # @return array of strings of optional member data. + def members_data_for(members) + members_data_for_in(@leaderboard_name, members) + end + # Update the optional member data for a given member in the leaderboard. # # @param member [String] Member name.