Median for ActiveRecord
Ruby
Latest commit 4e1a1f8 Dec 3, 2016 @ankane Version bump to 0.1.4

README.md

ActiveMedian

Median for ActiveRecord - PostgreSQL only at the moment

Build Status

Item.median(:price)

Works with grouping, too.

Order.group("date_trunc('week', created_at)").median(:total)

Installation

Add this line to your application’s Gemfile:

gem 'active_median'

And create a migration to add the median function to the database.

rails g migration create_median_function

with:

def up
  ActiveMedian.create_function
end

def down
  ActiveMedian.drop_function
end

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help: