Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

miry/calculations_by_time_range

Repository files navigation

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 © 2010 Michael Nikitochkin of JetThoughts, released under the MIT license

About

Add to ActiveRecord methods to calculate agregate values by time range.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages