leaderboard 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +5 -0
- data/README.markdown +1 -0
- data/lib/leaderboard.rb +9 -1
- data/lib/leaderboard/version.rb +1 -1
- data/lib/tie_ranking_leaderboard.rb +3 -2
- data/spec/leaderboard_spec.rb +9 -0
- data/spec/tie_ranking_leaderboard_spec.rb +3 -0
- data/spec/version_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d3ef8c29d1877020bc95d7a3bad51147aa0eda5
|
4
|
+
data.tar.gz: bd11c053fcd17988950fee87958303c0186c2ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9b8be3c741a3af3c79a88901fef4d131c58436e4402f46423709884106ed2b45c07cee7ea4a17895798e9c7fb5ba71e5189fdfcb138a5fc5bd6ea39b52c1312
|
7
|
+
data.tar.gz: f0d00fc7e09a22e68df13882611bf4599f2d9990552f508e80510176370e1c92b4c02431e634ea97f535fba0c743ec7b626cd8e302d71569c5254329bb6055f2
|
data/CHANGELOG.markdown
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 3.12.0 (2017-02-03)
|
4
|
+
|
5
|
+
* Fixed an error with the `ranked_in_list` method when using certain options [#62](https://github.com/agoragames/leaderboard/pull/62)
|
6
|
+
* Added `total_scores` method [#63](https://github.com/agoragames/leaderboard/pull/63)
|
7
|
+
|
3
8
|
## 3.11.0 (2016-09-16)
|
4
9
|
|
5
10
|
* More pipelining [#58](https://github.com/agoragames/leaderboard/pull/58).
|
data/README.markdown
CHANGED
@@ -350,6 +350,7 @@ Competition ranking: The `CompetitionRankingLeaderboard` subclass of `Leaderboar
|
|
350
350
|
total_members: Total # of members in the leaderboard
|
351
351
|
total_pages: Total # of pages in the leaderboard given the leaderboard's page_size
|
352
352
|
total_members_in_score_range(min_score, max_score): Count the number of members within a score range in the leaderboard
|
353
|
+
total_scores: Sum of scores for all members in leaderboard
|
353
354
|
change_score_for(member, delta): Change the score for a member by some amount delta (delta could be positive or negative)
|
354
355
|
rank_for(member): Retrieve the rank for a given member in the leaderboard
|
355
356
|
score_for(member): Retrieve the score for a given member in the leaderboard
|
data/lib/leaderboard.rb
CHANGED
@@ -369,6 +369,13 @@ class Leaderboard
|
|
369
369
|
@redis_connection.zcount(leaderboard_name, min_score, max_score)
|
370
370
|
end
|
371
371
|
|
372
|
+
# Sum of scores for all members in leaderboard
|
373
|
+
#
|
374
|
+
# @return Sum of scores for all members in leaderboard
|
375
|
+
def total_scores
|
376
|
+
all_leaders.map{|hash| hash[:score] }.inject(0, :+)
|
377
|
+
end
|
378
|
+
|
372
379
|
# Change the score for a member in the leaderboard by a score delta which can be positive or negative.
|
373
380
|
#
|
374
381
|
# @param member [String] Member name.
|
@@ -988,7 +995,8 @@ class Leaderboard
|
|
988
995
|
end
|
989
996
|
|
990
997
|
if leaderboard_options[:with_member_data]
|
991
|
-
|
998
|
+
included_members = ranks_for_members.collect { |member| member[@member_key] }
|
999
|
+
members_data_for_in(leaderboard_name, included_members).each_with_index do |member_data, index|
|
992
1000
|
ranks_for_members[index][@member_data_key] = member_data
|
993
1001
|
end
|
994
1002
|
end
|
data/lib/leaderboard/version.rb
CHANGED
@@ -253,7 +253,8 @@ class TieRankingLeaderboard < Leaderboard
|
|
253
253
|
end
|
254
254
|
|
255
255
|
if leaderboard_options[:with_member_data]
|
256
|
-
|
256
|
+
included_members = ranks_for_members.collect { |member| member[@member_key] }
|
257
|
+
members_data_for_in(leaderboard_name, included_members).each_with_index do |member_data, index|
|
257
258
|
ranks_for_members[index][@member_data_key] = member_data
|
258
259
|
end
|
259
260
|
end
|
@@ -278,4 +279,4 @@ class TieRankingLeaderboard < Leaderboard
|
|
278
279
|
def ties_leaderboard_key(leaderboard_name)
|
279
280
|
"#{leaderboard_name}:#{@ties_namespace}"
|
280
281
|
end
|
281
|
-
end
|
282
|
+
end
|
data/spec/leaderboard_spec.rb
CHANGED
@@ -851,5 +851,14 @@ describe 'Leaderboard' do
|
|
851
851
|
expect(leaders[0][:member]).to eql('member_1')
|
852
852
|
expect(leaders[1][:member]).to eql('member_15')
|
853
853
|
expect(leaders[2][:member]).to eql('member_25')
|
854
|
+
|
855
|
+
leaders = @leaderboard.ranked_in_list(['member_200'], :include_missing => false, :with_member_data => true)
|
856
|
+
expect(leaders.size).to be(0)
|
857
|
+
end
|
858
|
+
|
859
|
+
it 'should return the sum of all scores in the leaderboard' do
|
860
|
+
rank_members_in_leaderboard(25)
|
861
|
+
|
862
|
+
expect(@leaderboard.total_scores()).to eq(325)
|
854
863
|
end
|
855
864
|
end
|
@@ -345,6 +345,9 @@ describe 'TieRankingLeaderboard' do
|
|
345
345
|
expect(leaders[0][:member]).to eql('member_1')
|
346
346
|
expect(leaders[1][:member]).to eql('member_15')
|
347
347
|
expect(leaders[2][:member]).to eql('member_25')
|
348
|
+
|
349
|
+
leaders = @leaderboard.ranked_in_list(['member_200'], :include_missing => false, :with_member_data => true)
|
350
|
+
expect(leaders.size).to be(0)
|
348
351
|
end
|
349
352
|
end
|
350
353
|
end
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaderboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Czarnecki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|