Scorecard
A Rails engine for tracking points, badges and levels for gamification.
For anyone who comes across this, please note this is not yet feature complete, and the API will very likely change.
Installation
Add this line to your application's Gemfile:
gem 'scorecard', '0.0.2'
Don't forget to bundle:
$ bundle
Then, add the migrations to your app and update your database accordingly:
$ rake scorecard:install:migrations db:migrate
Rules
In an initializer, define the events that points are tied to - with a unique context and the number of points:
Scorecard::PointRule.new :new_post, 50
You can also provide a block with logic for whether to award the points, the maximum number of points allowed to be awarded for this rule, and the timeframe for that limit:
Scorecard::PointRule.new :new_post, 50, limit: 100, timeframe: :day,
if: lambda { |payload| payload[:user].posts.count <= 1 }
The payload object contains the context plus every option you send through to score call (see below).
Scoring
And then, when you want to fire those events, use code much like the following:
Scorecard::Points.score :new_post, gameable: post
This presumes that the user the points are for is a method on the gameable object. If that's not the case, you can pass in a custom user:
Scorecard::Points.score :new_post, gameable: post, user: user
If you're using Sidekiq, you can push the scoring behaviour into a background worker using score_async instead. Make sure scorecard is listed below sidekiq in your Gemfile.
Scorecard::Points.score_async :new_post, gameable: post
Results
To get the current points count for a given user:
Scorecard::Points.for user
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Licence
Copyright (c) 2013, Scorecard is developed and maintained by Inspire9, and is released under the open MIT Licence.