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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f0aeb0cd68034cf6d268f8f1d8d4e8a39c0df66
4
- data.tar.gz: 4576a03574ab9f93200d11ab861b9b3203a179dc
3
+ metadata.gz: 0d3ef8c29d1877020bc95d7a3bad51147aa0eda5
4
+ data.tar.gz: bd11c053fcd17988950fee87958303c0186c2ee3
5
5
  SHA512:
6
- metadata.gz: ac3cc4247ea3c1ca634375112b2614dbe18a1d1a8ab818f08c2f27fe1c1167dea897b95eb7014704a81c0a9303ed03865537837f0eb7efed8bd1b34e8990de1e
7
- data.tar.gz: 68128561ee0b7d89d929c251d19b5463ca836325d15a1a163a48e370dba1a39e8475106c7575d9ddbc0ea04dcdbeb8c544e88512879ca25805d124f023ae2b6a
6
+ metadata.gz: c9b8be3c741a3af3c79a88901fef4d131c58436e4402f46423709884106ed2b45c07cee7ea4a17895798e9c7fb5ba71e5189fdfcb138a5fc5bd6ea39b52c1312
7
+ data.tar.gz: f0d00fc7e09a22e68df13882611bf4599f2d9990552f508e80510176370e1c92b4c02431e634ea97f535fba0c743ec7b626cd8e302d71569c5254329bb6055f2
@@ -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).
@@ -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
@@ -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
- members_data_for_in(leaderboard_name, members).each_with_index do |member_data, index|
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
@@ -1,3 +1,3 @@
1
1
  class Leaderboard
2
- VERSION = '3.11.0'.freeze
2
+ VERSION = '3.12.0'.freeze
3
3
  end
@@ -253,7 +253,8 @@ class TieRankingLeaderboard < Leaderboard
253
253
  end
254
254
 
255
255
  if leaderboard_options[:with_member_data]
256
- members_data_for_in(leaderboard_name, members).each_with_index do |member_data, index|
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
@@ -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
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Leaderboard::VERSION' do
4
4
  it 'should be the correct version' do
5
- expect(Leaderboard::VERSION).to eq('3.11.0')
5
+ expect(Leaderboard::VERSION).to eq('3.12.0')
6
6
  end
7
7
  end
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.11.0
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: 2016-09-16 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis