leaderboard 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +34 -26
- data/README.markdown +6 -4
- data/lib/leaderboard.rb +21 -0
- data/lib/leaderboard/version.rb +1 -1
- data/spec/leaderboard_spec.rb +12 -0
- data/spec/reverse_leaderboard_spec.rb +14 -2
- data/spec/version_spec.rb +1 -1
- metadata +19 -5
- checksums.yaml +0 -15
data/CHANGELOG.markdown
CHANGED
@@ -1,84 +1,92 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
##
|
3
|
+
## 3.2.0 (2013-05-31)
|
4
|
+
|
5
|
+
* Added `remove_members_outside_rank` method to remove members from the leaderboard outside a given rank.
|
6
|
+
|
7
|
+
## 3.1.0 (2013-05-15)
|
8
|
+
|
9
|
+
* Added `:members_only` option for various leaderboard requests.
|
10
|
+
|
11
|
+
## 3.0.2 (2013-02-22)
|
4
12
|
|
5
13
|
* Fixed a data leak in `expire_leaderboard` and `expire_leaderboard_at` to also set expiration on the member data hash.
|
6
14
|
|
7
|
-
##
|
15
|
+
## 3.0.1 (2012-12-19)
|
8
16
|
|
9
17
|
* Fixed a bug in `remove_member` that would remove all of the optional member data.
|
10
18
|
|
11
|
-
##
|
19
|
+
## 3.0.0 (2012-12-03)
|
12
20
|
|
13
|
-
* Added `rank_member_if` and `rank_member_if_in` methods that allow you to rank a member in the leaderboard based on execution of a lambda.
|
21
|
+
* Added `rank_member_if` and `rank_member_if_in` methods that allow you to rank a member in the leaderboard based on execution of a lambda.
|
14
22
|
|
15
|
-
##
|
23
|
+
## 3.0.0.rc2 (2012-11-27)
|
16
24
|
|
17
25
|
* No longer cast scores to a floating point automatically. If requesting a score for an unknown member in the leaderboard, return `nil`. Under the old behavior, a `nil` score gets returned as 0.0. This is misleading as 0.0 is a valid score.
|
18
26
|
|
19
|
-
##
|
27
|
+
## 3.0.0.rc1 (2012-11-08)
|
20
28
|
|
21
29
|
* Removes `:use_zero_index_for_rank_option` as valid option for requesting data from the leaderboard. [Original proposal](https://github.com/agoragames/leaderboard/pull/27)
|
22
30
|
* Optional member data is stored in a single hash. [Original proposal](https://github.com/agoragames/leaderboard/pull/26)
|
23
31
|
* Adds `:sort_by` as valid option for requesting data from the leaderboard. [Original proposal](https://github.com/agoragames/leaderboard/pull/30)
|
24
32
|
* Removes `:with_scores` and `:with_ranks` as valid options for requesting data from the leaderboard.
|
25
33
|
|
26
|
-
##
|
34
|
+
## 2.5.0 (2012-10-12)
|
27
35
|
|
28
36
|
* Added `members_from_rank_range` and `members_from_rank_range_in` methods to be able to retrieve members from a leaderboard in a given rank range.
|
29
37
|
|
30
|
-
##
|
38
|
+
## 2.4.0 (2012-07-30)
|
31
39
|
|
32
40
|
* Added `all_leaders` and `all_leaders_from` methods to retrieve all members from a leaderboard. You may also use the aliases `all_members` or `all_members_from`.
|
33
41
|
|
34
|
-
##
|
42
|
+
## 2.3.0 (2012-07-09)
|
35
43
|
|
36
44
|
* Added `expire_leaderboard(seconds)` to expire the leaderboard in a set number of seconds.
|
37
45
|
* Added `expire_leaderboard_at(timestamp)` to expire the leaderboard at a specific UNIX timestamp.
|
38
46
|
* Added optional `page_size` parameter to the `total_pages` method.
|
39
47
|
|
40
|
-
##
|
48
|
+
## 2.2.1 (2012-06-18)
|
41
49
|
|
42
50
|
* Fix for #17 - Leaderboard not compatible with redis 2.1.1. Redis' `zrangebyscore` and `zrevrangebyscore` methods do not return scores by default. No need to pass the option in the initial call.
|
43
51
|
|
44
|
-
##
|
52
|
+
## 2.2.0 (2012-06-18)
|
45
53
|
|
46
54
|
* Added `members_from_score_range` and `members_from_score_range_in` methods. These will retrieve members from the leaderboard that fall within a given score range.
|
47
55
|
* Add `member_at` and `member_at_in` methods. These will retrieve a given member from the leaderboard at the specified position.
|
48
56
|
* `members` and `members_in` are now aliases for the `leaders` and `leaders_in` methods.
|
49
57
|
|
50
|
-
##
|
58
|
+
## 2.1.0 (2012-06-11)
|
51
59
|
|
52
60
|
* Added ability to store optional member data alongside the leaderboard data.
|
53
61
|
* `:with_member_data` is now a valid request option when retrieving leader data.
|
54
62
|
|
55
|
-
##
|
63
|
+
## 2.0.6 (2012-04-26)
|
56
64
|
|
57
65
|
* Added accessor for `reverse` option so that you can set reverse after creating a leaderboard to see results in either highest-to-lowest or lowest-to-highest order.
|
58
66
|
|
59
|
-
##
|
67
|
+
## 2.0.5 (2012-03-14)
|
60
68
|
|
61
69
|
* Added `rank_members(members_and_scores)` and `rank_members_in(leaderboard_name, members_and_scores)` allowing you to pass in some variable number of `member_name, score` and so on or an actual array of those data items. Use this method to do bulk insert of data, but be mindful of the amount of data you are inserting since a single transaction can get quite large.
|
62
70
|
|
63
|
-
##
|
71
|
+
## 2.0.4 (2012-02-29)
|
64
72
|
|
65
73
|
* Added `page_for(member, page_size = DEFAULT_PAGE_SIZE)` and `page_for_in(leaderboard_name, member, page_size = DEFAULT_PAGE_SIZE)` calls to allow you to determine the page where a member falls in the leaderboard
|
66
74
|
|
67
|
-
##
|
75
|
+
## 2.0.3 (2012-02-22)
|
68
76
|
|
69
77
|
* Added `:reverse => false` to `Leaderboard::DEFAULT_OPTIONS` to support leaderboards sorted from lowest to highest score instead of highest to lowest score. (Thanks @siuying)
|
70
78
|
|
71
|
-
##
|
79
|
+
## 2.0.2 (2012-02-03)
|
72
80
|
|
73
81
|
* Fix for checking to see if a member actually exists in the leaderboard for the `around_me` calls
|
74
82
|
* Return appropriate `nil` in data returned for calls such as `percentile_for` and `ranked_in_list` for non-existent members
|
75
83
|
|
76
|
-
##
|
84
|
+
## 2.0.1 (2011-11-07)
|
77
85
|
|
78
86
|
* Allow for only single options to be passed to `leaders`, `around_me` and `ranked_in_list` methods - https://github.com/agoragames/leaderboard/issues/4
|
79
87
|
* Added `percentile_for(member)` and `percentile_for_in(leaderboard_name, member)` methods to calculate percentile for a given member
|
80
88
|
|
81
|
-
##
|
89
|
+
## 2.0.0 (2011-08-05)
|
82
90
|
|
83
91
|
* Change `add_member` to `rank_member` - https://github.com/agoragames/leaderboard/issues/3
|
84
92
|
* Added `delete_leaderboard` and `delete_leaderboard_named` - https://github.com/agoragames/leaderboard/issues/2
|
@@ -87,33 +95,33 @@
|
|
87
95
|
* Updated initializer to take a leaderboard name, `options` hash and `redis_options` hash
|
88
96
|
* Simplified `leaders`, `around_me` and `ranked_in_list` to use an `options` hash with defaults for the previously individual parameters
|
89
97
|
|
90
|
-
##
|
98
|
+
## 1.0.6 (unreleased)
|
91
99
|
|
92
100
|
* Added `disconnect` method
|
93
101
|
* Check for invalid page size when changing
|
94
102
|
|
95
|
-
##
|
103
|
+
## 1.0.5 (2011-05-04)
|
96
104
|
|
97
105
|
* Updated Rakefile to run tests under ruby 1.8.7 and ruby 1.9.2
|
98
106
|
* Added `page_size` parameter to `total_pages_in` to allow for checking what if values in that scenario
|
99
107
|
* Added `page_size` parameter to `leaders` and `around_me` calls
|
100
108
|
|
101
|
-
##
|
109
|
+
## 1.0.4 (2011-04-26)
|
102
110
|
|
103
111
|
* Minor bug fix
|
104
112
|
|
105
|
-
##
|
113
|
+
## 1.0.3 (2011-04-26)
|
106
114
|
|
107
115
|
* Fixing issue using total_pages in leaderboard_in call
|
108
116
|
* Internal `massage_leader_data` method will now respect `with_scores`
|
109
117
|
|
110
|
-
##
|
118
|
+
## 1.0.2 (2011-02-25)
|
111
119
|
|
112
120
|
* Adding `XXX_to`, `XXX_for`, `XXX_in` and `XXX_from` methods that will allow you to set the leaderboard name to interact with outside of creating a new object
|
113
121
|
* Added `merge_leaderboards(destination, keys, options = {:aggregate => :min})` method to merge leaderboards given by keys with this leaderboard into destination
|
114
122
|
* Added `intersect_leaderboards(destination, keys, options = {:aggregate => :min})` method to intersect leaderboards given by keys with this leaderboard into destination
|
115
123
|
|
116
|
-
##
|
124
|
+
## 1.0.1 (2011-02-16)
|
117
125
|
|
118
126
|
* `redis_options` can be passed in the initializer to pass options for the connection to Redis
|
119
127
|
* `page_size` is now settable outside of the initializer
|
@@ -121,6 +129,6 @@
|
|
121
129
|
* `score_and_rank_for(member, use_zero_index_for_rank = false)`: Retrieve the score and rank for a member in a single call
|
122
130
|
* `remove_members_in_score_range(min_score, max_score)`: Remove members from the leaderboard within a score range
|
123
131
|
|
124
|
-
##
|
132
|
+
## 1.0.0
|
125
133
|
|
126
134
|
* Initial release
|
data/README.markdown
CHANGED
@@ -151,9 +151,9 @@ If you delete the leaderboard, ALL of the member data is deleted as well.
|
|
151
151
|
|
152
152
|
#### Optional member data notes
|
153
153
|
|
154
|
-
If you use optional member data, the use of the `remove_members_in_score_range`
|
155
|
-
hash. This is because the internal Redis method, `zremrangebyscore`,
|
156
|
-
not return the members that it removed.
|
154
|
+
If you use optional member data, the use of the `remove_members_in_score_range` or `remove_members_outside_rank` methods
|
155
|
+
will leave data around in the member data hash. This is because the internal Redis method, `zremrangebyscore`,
|
156
|
+
only returns the number of items removed. It does not return the members that it removed.
|
157
157
|
|
158
158
|
Get some information about a specific member(s) in the leaderboard:
|
159
159
|
|
@@ -311,6 +311,7 @@ Use this method to do bulk insert of data, but be mindful of the amount of data
|
|
311
311
|
check_member?(member): Check to see whether member is in the leaderboard
|
312
312
|
score_and_rank_for(member): Retrieve the score and rank for a member in a single call
|
313
313
|
remove_members_in_score_range(min_score, max_score): Remove members from the leaderboard within a score range
|
314
|
+
remove_members_outside_rank(rank): Remove members from the leaderboard outside a given rank
|
314
315
|
percentile_for(member): Calculate the percentile for a given member
|
315
316
|
page_for(member, page_size): Determine the page where a member falls in the leaderboard
|
316
317
|
expire_leaderboard(seconds): Expire the leaderboard in a set number of seconds.
|
@@ -412,12 +413,13 @@ end
|
|
412
413
|
|
413
414
|
## Ports
|
414
415
|
|
415
|
-
The following ports have been made of the leaderboard gem.
|
416
|
+
The following ports have been made of the [leaderboard gem](https://github.com/agoragames/leaderboard).
|
416
417
|
|
417
418
|
Officially supported:
|
418
419
|
|
419
420
|
* CoffeeScript: https://github.com/agoragames/leaderboard-coffeescript
|
420
421
|
* Python: https://github.com/agoragames/leaderboard-python
|
422
|
+
* Ruby: https://github.com/agoragames/leaderboard
|
421
423
|
|
422
424
|
Unofficially supported (they need some feature parity love):
|
423
425
|
|
data/lib/leaderboard.rb
CHANGED
@@ -445,6 +445,27 @@ class Leaderboard
|
|
445
445
|
@redis_connection.zremrangebyscore(leaderboard_name, min_score, max_score)
|
446
446
|
end
|
447
447
|
|
448
|
+
# Remove members from the leaderboard outside a given rank.
|
449
|
+
#
|
450
|
+
# @param rank [int] The rank (inclusive) which we should keep.
|
451
|
+
# @return the total number of members removed.
|
452
|
+
def remove_members_outside_rank(rank)
|
453
|
+
remove_members_outside_rank_in(@leaderboard_name, rank)
|
454
|
+
end
|
455
|
+
|
456
|
+
# Remove members from the leaderboard outside a given rank.
|
457
|
+
#
|
458
|
+
# @param leaderboard_name [String] Name of the leaderboard.
|
459
|
+
# @param rank [int] The rank (inclusive) which we should keep.
|
460
|
+
# @return the total number of members removed.
|
461
|
+
def remove_members_outside_rank_in(leaderboard_name, rank)
|
462
|
+
if @reverse
|
463
|
+
@redis_connection.zremrangebyrank(leaderboard_name, rank, -1)
|
464
|
+
else
|
465
|
+
@redis_connection.zremrangebyrank(leaderboard_name, 0, -(rank) - 1)
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
448
469
|
# Retrieve the percentile for a member in the leaderboard.
|
449
470
|
#
|
450
471
|
# @param member [String] Member name.
|
data/lib/leaderboard/version.rb
CHANGED
data/spec/leaderboard_spec.rb
CHANGED
@@ -358,6 +358,18 @@ describe 'Leaderboard' do
|
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
+
it 'should allow you to remove members outside a given rank' do
|
362
|
+
rank_members_in_leaderboard
|
363
|
+
|
364
|
+
@leaderboard.total_members.should be(5)
|
365
|
+
@leaderboard.remove_members_outside_rank(3).should be(2)
|
366
|
+
|
367
|
+
leaders = @leaderboard.leaders(1)
|
368
|
+
leaders.size.should be(3)
|
369
|
+
leaders[0][:member].should == 'member_5'
|
370
|
+
leaders[2][:member].should == 'member_3'
|
371
|
+
end
|
372
|
+
|
361
373
|
it 'should allow you to merge leaderboards' do
|
362
374
|
foo = Leaderboard.new('foo', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
|
363
375
|
bar = Leaderboard.new('bar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
|
@@ -173,6 +173,18 @@ describe 'Leaderboard (reverse option)' do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
it 'should allow you to remove members outside a given rank' do
|
177
|
+
rank_members_in_leaderboard
|
178
|
+
|
179
|
+
@leaderboard.total_members.should be(5)
|
180
|
+
@leaderboard.remove_members_outside_rank(3).should be(2)
|
181
|
+
|
182
|
+
leaders = @leaderboard.leaders(1)
|
183
|
+
leaders.size.should be(3)
|
184
|
+
leaders[0][:member].should == 'member_1'
|
185
|
+
leaders[2][:member].should == 'member_3'
|
186
|
+
end
|
187
|
+
|
176
188
|
it 'should allow you to merge leaderboards' do
|
177
189
|
foo = Leaderboard.new('foo', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
|
178
190
|
bar = Leaderboard.new('bar', Leaderboard::DEFAULT_LEADERBOARD_REQUEST_OPTIONS, :host => "127.0.0.1", :db => 15)
|
@@ -299,7 +311,7 @@ describe 'Leaderboard (reverse option)' do
|
|
299
311
|
members = @leaderboard.members_from_rank_range(5, 9)
|
300
312
|
members.size.should be(5)
|
301
313
|
members[0][:member].should eql('member_5')
|
302
|
-
members[0][:score].to_i.should be(5)
|
314
|
+
members[0][:score].to_i.should be(5)
|
303
315
|
members[4][:member].should eql('member_9')
|
304
316
|
|
305
317
|
members = @leaderboard.members_from_rank_range(1, 1)
|
@@ -309,7 +321,7 @@ describe 'Leaderboard (reverse option)' do
|
|
309
321
|
members = @leaderboard.members_from_rank_range(-1, 26)
|
310
322
|
members.size.should be(25)
|
311
323
|
members[0][:member].should eql('member_1')
|
312
|
-
members[0][:score].to_i.should be(1)
|
324
|
+
members[0][:score].to_i.should be(1)
|
313
325
|
members[24][:member].should eql('member_25')
|
314
326
|
end
|
315
327
|
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaderboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- David Czarnecki
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: redis
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -78,26 +85,33 @@ files:
|
|
78
85
|
- spec/version_spec.rb
|
79
86
|
homepage: https://github.com/agoragames/leaderboard
|
80
87
|
licenses: []
|
81
|
-
metadata: {}
|
82
88
|
post_install_message:
|
83
89
|
rdoc_options: []
|
84
90
|
require_paths:
|
85
91
|
- lib
|
86
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
87
94
|
requirements:
|
88
95
|
- - ! '>='
|
89
96
|
- !ruby/object:Gem::Version
|
90
97
|
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -3549560815015692578
|
91
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
92
103
|
requirements:
|
93
104
|
- - ! '>='
|
94
105
|
- !ruby/object:Gem::Version
|
95
106
|
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -3549560815015692578
|
96
110
|
requirements: []
|
97
111
|
rubyforge_project: leaderboard
|
98
|
-
rubygems_version:
|
112
|
+
rubygems_version: 1.8.25
|
99
113
|
signing_key:
|
100
|
-
specification_version:
|
114
|
+
specification_version: 3
|
101
115
|
summary: Leaderboards backed by Redis in Ruby
|
102
116
|
test_files:
|
103
117
|
- spec/leaderboard_spec.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
NjI2NWFlODMyNTM3NWMzZmM4YzUwMzljMWJkMDQ2MmVhMjVlNjQ1ZQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDNhMmYzZjU5MGJjYjU3YTIzMWI0NWJhZDNhNDAwNmRjYzFmMjAyOA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YTk2YTBhNzZhZGUyODgwYzAwYTgzNDAyOTYwYTQzYjVhODdmZGJiZmEwMzc1
|
10
|
-
YzdiODM3MTA2NGI1M2I2NjhjZmVmN2RlMDVlMzBjYmUxMGU1YjkyYjU4ODQy
|
11
|
-
NTRmMWM5NzM3NTE1MDYzYjc1ZjkyNDU1MjA3MDE1NTc0Nzk1ZWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MmIwMTc1ZGVjZmE0N2U4NjRjNGM2OGY3M2ZlZTQ4YTM5ZTQ0ZWI3MDRkNzA4
|
14
|
-
MjhjNDhkMWFiMDhiYTExOTdhMDFjNGU2YWEyNTI2MDVhNzA5YmEwYjA1Nzg3
|
15
|
-
NDljMDM5ZWNmZjY3ZDI5NzVlY2VmZGIxZDczMmJlMTAxZjgxOGI=
|