leaderboard 3.0.0.rc1 → 3.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## leaderboard 3.0.0.rc2 (2012-11-27)
4
+
5
+ * 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.
6
+
3
7
  ## leaderboard 3.0.0.rc1 (2012-11-08)
4
8
 
5
9
  * 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)
data/lib/leaderboard.rb CHANGED
@@ -120,7 +120,7 @@ class Leaderboard
120
120
  # @param member [String] Member name.
121
121
  # @param score [float] Member score.
122
122
  # @param member_data [Hash] Optional member data.
123
- def rank_member_in(leaderboard_name, member, score, member_data)
123
+ def rank_member_in(leaderboard_name, member, score, member_data = nil)
124
124
  @redis_connection.multi do |transaction|
125
125
  transaction.zadd(leaderboard_name, score, member)
126
126
  transaction.hset(member_data_key(leaderboard_name), member, member_data) if member_data
@@ -320,7 +320,7 @@ class Leaderboard
320
320
  #
321
321
  # @param member Member name.
322
322
  #
323
- # @return the score for a member in the leaderboard.
323
+ # @return the score for a member in the leaderboard or +nil+ if the member is not in the leaderboard.
324
324
  def score_for(member)
325
325
  score_for_in(@leaderboard_name, member)
326
326
  end
@@ -330,9 +330,10 @@ class Leaderboard
330
330
  # @param leaderboard_name Name of the leaderboard.
331
331
  # @param member [String] Member name.
332
332
  #
333
- # @return the score for a member in the leaderboard.
333
+ # @return the score for a member in the leaderboard or +nil+ if the member is not in the leaderboard.
334
334
  def score_for_in(leaderboard_name, member)
335
- @redis_connection.zscore(leaderboard_name, member).to_f
335
+ score = @redis_connection.zscore(leaderboard_name, member)
336
+ score.to_f if score
336
337
  end
337
338
 
338
339
  # Check to see if a member exists in the leaderboard.
@@ -379,7 +380,7 @@ class Leaderboard
379
380
  end
380
381
  end
381
382
 
382
- responses[0] = responses[0].to_f
383
+ responses[0] = responses[0].to_f if responses[0]
383
384
  responses[1] = responses[1] + 1 rescue nil
384
385
 
385
386
  {:member => member, :score => responses[0], :rank => responses[1]}
@@ -790,7 +791,7 @@ class Leaderboard
790
791
  data = {}
791
792
  data[:member] = member
792
793
  data[:rank] = responses[index * 2] + 1 rescue nil
793
- data[:score] = responses[index * 2 + 1].to_f
794
+ data[:score] = responses[index * 2 + 1].to_f if responses[index * 2 + 1]
794
795
 
795
796
  if leaderboard_options[:with_member_data]
796
797
  data[:member_data] = member_data_for_in(leaderboard_name, member)
@@ -1,4 +1,4 @@
1
1
  class Leaderboard
2
2
  # Leaderboard version
3
- VERSION = '3.0.0.rc1'.freeze
3
+ VERSION = '3.0.0.rc2'.freeze
4
4
  end
@@ -75,6 +75,7 @@ describe 'Leaderboard' do
75
75
  rank_members_in_leaderboard(5)
76
76
 
77
77
  @leaderboard.score_for('member_4').should eql(4.0)
78
+ @leaderboard.score_for('jones').should be_nil
78
79
  end
79
80
 
80
81
  it 'should return the correct total pages' do
@@ -477,7 +478,7 @@ describe 'Leaderboard' do
477
478
  score_and_rank_for_member = @leaderboard.score_and_rank_for('jones')
478
479
 
479
480
  score_and_rank_for_member[:member].should eql('jones')
480
- score_and_rank_for_member[:score].should eql(0.0)
481
+ score_and_rank_for_member[:score].should be_nil
481
482
  score_and_rank_for_member[:rank].should be_nil
482
483
  end
483
484
 
@@ -498,7 +499,7 @@ describe 'Leaderboard' do
498
499
  end
499
500
 
500
501
  it 'should allow you to change the score for a member not in the leaderboard' do
501
- @leaderboard.score_for('jones').should eql(0.0)
502
+ @leaderboard.score_for('jones').should be_nil
502
503
  @leaderboard.change_score_for('jones', 5)
503
504
  @leaderboard.score_for('jones').should eql(5.0)
504
505
  end
@@ -630,4 +631,15 @@ describe 'Leaderboard' do
630
631
  ranked_members[2][:rank].should be(16)
631
632
  ranked_members[2][:score].should eql(10.0)
632
633
  end
634
+
635
+ it 'should return nil for the score and rank for ranked_in_list if a member is not in the leaderboard' do
636
+ rank_members_in_leaderboard
637
+
638
+ ranked_members = @leaderboard.ranked_in_list(['jones'])
639
+
640
+ ranked_members.size.should be(1)
641
+ ranked_members[0][:member].should eql('jones')
642
+ ranked_members[0][:score].should be_nil
643
+ ranked_members[0][:rank].should be_nil
644
+ end
633
645
  end
data/spec/version_spec.rb CHANGED
@@ -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
- Leaderboard::VERSION.should == '3.0.0.rc1'
5
+ Leaderboard::VERSION.should == '3.0.0.rc2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaderboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc1
4
+ version: 3.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -93,9 +93,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  - - ! '>='
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
- segments:
97
- - 0
98
- hash: -395088559469707987
99
96
  required_rubygems_version: !ruby/object:Gem::Requirement
100
97
  none: false
101
98
  requirements: