avifoxi/GOLDFINGERhasflashcards — pull request #32 by Joseph-White (2014-08-10 19:45:26+00:00)
Title: Leaders

Implements basic leader board

includes 4 methods in user.rb and a view section on index.erb

some or all of those 4 methods could be moved to improve design, but they have dependencies with each other, so move them with care...

index.erb is currently the only place they are called (the call is to User.leaderboard which then calls the other 3).

new methods in user.rb are 3 class methods:
self. get_results
self.sort_results
self.leaderboard
and 1 instance method (that the 3 class methods depend on):

get_results (which an array of hashes containing results info for each round user has played)

Score generation is handled by self.sort_results and is weighted (50 points for correct answer, -75 points for incorrect answer) -- weighting can be easily adjusted

Note that User.leaderboard defaults to displaying top 3 leaders but can take an argument to change that, e.g., User.leaderboard(5)