lib/leaderboard.rb in leaderboard-3.0.0.rc1 vs lib/leaderboard.rb in leaderboard-3.0.0.rc2

- old
+ new

@@ -118,11 +118,11 @@ # # @param leaderboard_name [String] Name of the leaderboard. # @param member [String] Member name. # @param score [float] Member score. # @param member_data [Hash] Optional member data. - def rank_member_in(leaderboard_name, member, score, member_data) + def rank_member_in(leaderboard_name, member, score, member_data = nil) @redis_connection.multi do |transaction| transaction.zadd(leaderboard_name, score, member) transaction.hset(member_data_key(leaderboard_name), member, member_data) if member_data end end @@ -318,23 +318,24 @@ # Retrieve the score for a member in the leaderboard. # # @param member Member name. # - # @return the score for a member in the leaderboard. + # @return the score for a member in the leaderboard or +nil+ if the member is not in the leaderboard. def score_for(member) score_for_in(@leaderboard_name, member) end # Retrieve the score for a member in the named leaderboard. # # @param leaderboard_name Name of the leaderboard. # @param member [String] Member name. # - # @return the score for a member in the leaderboard. + # @return the score for a member in the leaderboard or +nil+ if the member is not in the leaderboard. def score_for_in(leaderboard_name, member) - @redis_connection.zscore(leaderboard_name, member).to_f + score = @redis_connection.zscore(leaderboard_name, member) + score.to_f if score end # Check to see if a member exists in the leaderboard. # # @param member [String] Member name. @@ -377,11 +378,11 @@ else transaction.zrevrank(leaderboard_name, member) end end - responses[0] = responses[0].to_f + responses[0] = responses[0].to_f if responses[0] responses[1] = responses[1] + 1 rescue nil {:member => member, :score => responses[0], :rank => responses[1]} end @@ -788,10 +789,10 @@ members.each_with_index do |member, index| data = {} data[:member] = member data[:rank] = responses[index * 2] + 1 rescue nil - data[:score] = responses[index * 2 + 1].to_f + data[:score] = responses[index * 2 + 1].to_f if responses[index * 2 + 1] if leaderboard_options[:with_member_data] data[:member_data] = member_data_for_in(leaderboard_name, member) end \ No newline at end of file