Skip to content
[0.2.0, MIT license] Ruby gem to track consecutive day streaks on your Rails/ActiveRecord models
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gemfiles
lib
spec
.gitignore
.travis.yml
Appraisals
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
_config.yml
streakable.gemspec

README.md

Gem Version Build Status Coverage Status Inline docs Maintainability MIT License Gem GitHub stars

Streakable Logo

Streakable is a Ruby gem to track consecutive day streaks 📆 on your Rails/ActiveRecord models. Hard fork of has_streak by Garrett Martin with a different include interface and more features. Requires Ruby >= 2.1 and ActiveRecord >= 3.2.22.

Github Project Page

Installation

Add this line to your application's Gemfile:

gem 'streakable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install streakable

Usage

Let's say I have a User that has_many posts:

class User < ActiveRecord::Base
  has_many :posts
end

I want to track how many days in a row that each user wrote a post. I just have to include streakable in the model:

class User < ActiveRecord::Base
  include Streakable
end

Now I can display the user's streak:

user.streak(:posts) # => number of days in a row that this user wrote a post (as determined by the created_at column, by default)

The streak instance method can be called with any association:

user.streak(:other_association)

And you can change the column the streak is calculated on:

user.streak(:posts, :updated_at)

Don't penalize the current day being absent when determining streaks (the User could write another Post before the day ends):

user.streak(:posts, except_today: true)

Find the longest streak, not just the current one:

user.streak(:posts, longest: true)

To get all of the streaks, not just the current one:

user.streaks(:posts)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature) or bugfix branch (git checkout -b bugfix/my-helpful-bugfix)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Make sure specs are passing (bundle exec rspec)
  6. Create new Pull Request

License

See the LICENSE file.

You can’t perform that action at this time.