Project

multi_sort

0.0
No commit activity in last 3 years
No release in over 3 years
Sort a array of hashes with one or multiple values
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

MultiSort

Many times I came across the requirements of sorting a array of hashes with one or more then one key's value of hash. I have wrote this gem which will accept the array of hashes as first parameter and array of keys to be sort by in a order.

Will add more features to this gem such as type of sorting, sorting of different type of multi-level hashes etc.

Installation

Add this line to your application's Gemfile:

gem 'multi_sort'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multi_sort

Usage

ARR_HASH = [{ foo: 'a', bar: 4 },
{ foo: 'b', bar: 3 },
{ foo: 'c', bar: 1 },
{ foo: 'b', bar: 4 }]
		
MultiSort.sort_by_order ARR_HASH, [:bar, :foo]

Note: By default it will sort in ASC order

If you Want to sort in DESC order. 

MultiSort.sort_by_order ARR_HASH, [:bar, :foo], "DESC"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request