0.01
No commit activity in last 3 years
No release in over 3 years
Add ability to easily sort by entry attributes to Enumerables and Arrays.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
~> 2.8.0
 Project Readme

Sort By Field¶ ↑

This plugin provides sorting by fields to arrays and enumerable objects. By default it is applied to arrays. It can be included in any enumerable class.

It automatically handles nil values and sorting strings without case sensitivity.

Usage¶ ↑

Sort the values array by the value returned by the name attribute on each entry without case sentivity:

values.sort_by_field(:name)

Sort the values array by the name attribute on each entry with case sentivity:

values.sort_by_field(:name, :case_sensitive => true)

Sort the values array by the name attribute putting nil values last instead of first:

values.sort_by_field(:name, :nil_last => true)

Sort the values array by the name attribute and then by the count attribute:

values.sort_by_field(:name, :count)

Sort the values array by the name attribute in descending order:

values.sort_by_field("name desc")

Sort the values array by the name of the class of each entry:

values.sort_by_field("class.name")

or

values.sort_by_field([:class, :name])