leaderboard 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,12 @@
1
+ # leaderboard 1.0.4 (2011-04-26)
2
+
3
+ * Minor bug fix
4
+
5
+ # leaderboard 1.0.3 (2011-04-26)
6
+
7
+ * Fixing issue using total_pages in leaderboard_in call
8
+ * Internal `massage_leader_data` method will now respect `with_scores`
9
+
1
10
  # leaderboard 1.0.2 (2011-02-25)
2
11
 
3
12
  * 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
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.4
data/leaderboard.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{leaderboard}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Czarnecki"]
12
- s.date = %q{2011-02-25}
12
+ s.date = %q{2011-04-26}
13
13
  s.description = %q{Leaderboards backed by Redis in Ruby}
14
14
  s.email = %q{dczarnecki@agoragames.com}
15
15
  s.extra_rdoc_files = [
data/lib/leaderboard.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'redis'
2
2
 
3
3
  class Leaderboard
4
- VERSION = '1.0.2'.freeze
4
+ VERSION = '1.0.4'.freeze
5
5
 
6
6
  DEFAULT_PAGE_SIZE = 25
7
7
  DEFAULT_REDIS_HOST = 'localhost'
@@ -133,8 +133,8 @@ class Leaderboard
133
133
  current_page = 1
134
134
  end
135
135
 
136
- if current_page > total_pages
137
- current_page = total_pages
136
+ if current_page > total_pages_in(leaderboard_name)
137
+ current_page = total_pages_in(leaderboard_name)
138
138
  end
139
139
 
140
140
  index_for_redis = current_page - 1
@@ -148,7 +148,7 @@ class Leaderboard
148
148
 
149
149
  raw_leader_data = @redis_connection.zrevrange(leaderboard_name, starting_offset, ending_offset, :with_scores => with_scores)
150
150
  if raw_leader_data
151
- massage_leader_data(leaderboard_name, raw_leader_data, with_rank, use_zero_index_for_rank)
151
+ massage_leader_data(leaderboard_name, raw_leader_data, with_scores, with_rank, use_zero_index_for_rank)
152
152
  else
153
153
  return nil
154
154
  end
@@ -170,7 +170,7 @@ class Leaderboard
170
170
 
171
171
  raw_leader_data = @redis_connection.zrevrange(leaderboard_name, starting_offset, ending_offset, :with_scores => with_scores)
172
172
  if raw_leader_data
173
- massage_leader_data(leaderboard_name, raw_leader_data, with_rank, use_zero_index_for_rank)
173
+ massage_leader_data(leaderboard_name, raw_leader_data, with_scores, with_rank, use_zero_index_for_rank)
174
174
  else
175
175
  return nil
176
176
  end
@@ -207,7 +207,7 @@ class Leaderboard
207
207
 
208
208
  private
209
209
 
210
- def massage_leader_data(leaderboard_name, leaders, with_rank, use_zero_index_for_rank)
210
+ def massage_leader_data(leaderboard_name, leaders, with_scores, with_rank, use_zero_index_for_rank)
211
211
  member_attribute = true
212
212
  leader_data = []
213
213
 
@@ -221,8 +221,13 @@ class Leaderboard
221
221
  leader_data << data
222
222
  data = {}
223
223
  end
224
-
225
- member_attribute = !member_attribute
224
+
225
+ if with_scores
226
+ member_attribute = !member_attribute
227
+ else
228
+ leader_data << data
229
+ data = {}
230
+ end
226
231
  end
227
232
 
228
233
  leader_data
@@ -11,7 +11,7 @@ class TestLeaderboard < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
  def test_version
14
- assert_equal '1.0.2', Leaderboard::VERSION
14
+ assert_equal '1.0.4', Leaderboard::VERSION
15
15
  end
16
16
 
17
17
  def test_initialize_with_defaults
@@ -249,6 +249,31 @@ class TestLeaderboard < Test::Unit::TestCase
249
249
  assert_equal 6, first_leader_in_foobar[:score]
250
250
  end
251
251
 
252
+ def test_massage_leader_data_respects_with_scores
253
+ add_members_to_leaderboard(25)
254
+
255
+ assert_equal 25, @leaderboard.total_members
256
+
257
+ leaders = @leaderboard.leaders(1, false, false, false)
258
+ assert_not_nil leaders[0][:member]
259
+ assert_nil leaders[0][:score]
260
+ assert_nil leaders[0][:rank]
261
+
262
+ @leaderboard.page_size = 25
263
+ leaders = @leaderboard.leaders(1, false, false, false)
264
+ assert_equal 25, leaders.size
265
+
266
+ @leaderboard.page_size = Leaderboard::DEFAULT_PAGE_SIZE
267
+ leaders = @leaderboard.leaders(1, true, true, false)
268
+ assert_not_nil leaders[0][:member]
269
+ assert_not_nil leaders[0][:score]
270
+ assert_not_nil leaders[0][:rank]
271
+
272
+ @leaderboard.page_size = 25
273
+ leaders = @leaderboard.leaders(1, true, true, false)
274
+ assert_equal 25, leaders.size
275
+ end
276
+
252
277
  private
253
278
 
254
279
  def add_members_to_leaderboard(members_to_add = 5)
@@ -256,4 +281,4 @@ class TestLeaderboard < Test::Unit::TestCase
256
281
  @leaderboard.add_member("member_#{index}", index)
257
282
  end
258
283
  end
259
- end
284
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaderboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Czarnecki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-25 00:00:00 -05:00
18
+ date: 2011-04-26 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency