lib/leaderboard_factory/helpers.rb
def top leaderboard, options = {}
      result = pivot(leaderboard, options).first
      if options[:mapper]
        options[:mapper].call(*result)
      else
        result
      end
    end
# Takes the top item off of the pivot and optionally passes the result through a callable mapper.
#
# @param leaderboard [Symbol] the name of the leaderboard
# @param options [Hash] +:mapper+ is the only unique option, other per +#pivot+
#
# Example
#
#    leaderboards.top(:personal_bests) # => [16.0, ['Event ID 1', 'Event ID 3']]
#    leaderboards.top(:personal_bests, mapper: Proc.new do |score, bests|
#      { high_score: score.to_i, tied: bests.size, best_events: bests }
#    end) # => { high_score: 16, tied: 2, best_events: ['Event ID 1', 'Event ID 3'] }
Takes the top item off of the pivot and optionally passes the result through a callable mapper.
Takes the top item off of the pivot and optionally passes the result through a callable mapper .
def top leaderboard, options = {}
      result = pivot(leaderboard, options).first
      if options[:mapper]
        options[:mapper].call(*result)
      else
        result
      end
    end
def top leaderboard , options = { } result = pivot ( leaderboard , options ) . first if options [ :mapper ] options [ :mapper ] . call ( * result ) else result end end
Takes the top item off of the pivot and optionally passes the result through a callable mapper.
Takes the top item off of the pivot and optionally passes the result through a callable mapper .
leaderboard
the name of the leaderboard
the name of the leaderboard
options
+:mapper+ is the only unique option, other per +#pivot+ Example leaderboards.top(:personal_bests) # => [16.0, ['Event ID 1', 'Event ID 3']] leaderboards.top(:personal_bests, mapper: Proc.new do |score, bests| { high_score: score.to_i, tied: bests.size, best_events: bests } end) # => { high_score: 16, tied: 2, best_events: ['Event ID 1', 'Event ID 3'] }
+ : mapper + is the only unique option other per + #pivot + Example leaderboards . top ( : personal_bests ) # = > [ 16 . 0 [ ' Event ID 1 ' ' Event ID 3 ' ]] leaderboards . top ( : personal_bests mapper : Proc . new do |score bests| { high_score : score . to_i tied : bests . size best_events : bests } end ) # = > { high_score : 16 tied : 2 best_events : [ ' Event ID 1 ' ' Event ID 3 ' ] }