Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Add to ActiveRecord methods to calculate agregate values by time range.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
calculations_by_time_range.gemspec

README.rdoc

Calculations By Time Range

Add new methods for ActiveRecord to get agregate values by time range.

Install & use

Install the gem from rubyforge:

sudo gem install calculations_by_time_range

Now just set it as a dependency in your project and you are ready to go.

You can also install this as a plugin:

script/plugin install git://github.com/miry/calculations_by_time_range.git

See below for usage examples.

Usage

# We have the following model
User(id: integer, created_at: datetime, updated_at: datetime, username: string, age: integer)

# CalculationsByTimeRange gives you a bunch of named scopes for free:
User.counts_by_day
User.counts_by(:day)
User.counts_by(:day, '*', 'updated_at')
User.sums_by(:week, 'age')

Examples with Searchlogic and scopes

User.created_at_gt(1.day.ago).counts_by_hours

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Michael Nikitochkin of JetThoughts, released under the MIT license

Something went wrong with that request. Please try again.