Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add #top_member and #bottom_member convenience methods.

  • Loading branch information...
commit 26481fd0ad864685b3b47e0ff342cb53597f445d 1 parent 9374a01
Matt Wilson authored

Showing 2 changed files with 29 additions and 1 deletion. Show diff stats Hide diff stats

  1. +15 1 lib/leaderboard.rb
  2. +14 0 spec/leaderboard_spec.rb
16 lib/leaderboard.rb
@@ -675,7 +675,21 @@ def member_at_in(leaderboard_name, position, options = {})
675 675 leaders[offset] if leaders
676 676 end
677 677 end
678   -
  678 +
  679 + # Retrieve the first member from the leaderboard, with member data
  680 + #
  681 + # @return the top item in the leaderboard
  682 + def top_member(options = {})
  683 + member_at(1, { :with_member_data => true }.merge(options))
  684 + end
  685 +
  686 + # Retrieve the last member from the leaderboard, with member data
  687 + #
  688 + # @return the bottom item in the leaderboard
  689 + def bottom_member(options = {})
  690 + member_at(total_members, { :with_member_data => true }.merge(options))
  691 + end
  692 +
679 693 # Retrieve a page of leaders from the leaderboard around a given member.
680 694 #
681 695 # @param member [String] Member name.
14 spec/leaderboard_spec.rb
@@ -272,6 +272,20 @@
272 272 @leaderboard.member_at(1, :use_zero_index_for_rank => true)[:rank].should == 0
273 273 end
274 274
  275 + it 'should return the first member when calling #top_member' do
  276 + rank_members_in_leaderboard(10)
  277 + top = @leaderboard.top_member
  278 + top[:rank].should == 1
  279 + top[:member_data].should == { 'member_name' => 'Leaderboard member 10' }
  280 + end
  281 +
  282 + it 'should return the last member when calling #bottom_member' do
  283 + rank_members_in_leaderboard(10)
  284 + bot = @leaderboard.bottom_member
  285 + bot[:rank].should == 10
  286 + bot[:member_data].should == { 'member_name' => 'Leaderboard member 1' }
  287 + end
  288 +
275 289 it 'should return the correct information when calling around_me' do
276 290 rank_members_in_leaderboard(Leaderboard::DEFAULT_PAGE_SIZE * 3 + 1)
277 291

0 comments on commit 26481fd

Please sign in to comment.
Something went wrong with that request. Please try again.