Menu

Tree [4825f1] master /
 History

HTTPS access


File Date Author Commit
 development 2013-02-22 Stefan Rusterholz Stefan Rusterholz [07a535] Added development/TODO.txt
 doc 2013-02-23 Stefan Rusterholz Stefan Rusterholz [4e23d1] Regenerated yard docs.
 documentation 2013-02-22 Stefan Rusterholz Stefan Rusterholz [f7ca7e] Initial commit.
 lib 2013-02-23 Stefan Rusterholz Stefan Rusterholz [8a8417] Changed how Sorting::Helpers' methods are added...
 rake 2013-03-02 Stefan Rusterholz Stefan Rusterholz [15556c] Added initial versions of "gem" and "test" rake...
 test 2013-03-02 Stefan Rusterholz Stefan Rusterholz [4825f1] Slightly reorganized test internals.
 .gitignore 2013-02-22 Stefan Rusterholz Stefan Rusterholz [80720e] Updated .gitignore.
 .yardopts 2013-02-22 Stefan Rusterholz Stefan Rusterholz [d2c500] Updated yard options.
 LICENSE.txt 2013-02-22 Stefan Rusterholz Stefan Rusterholz [f7ca7e] Initial commit.
 README.markdown 2013-02-23 Stefan Rusterholz Stefan Rusterholz [601010] Changed order of first examples (README and Sor...
 Rakefile 2013-02-22 Stefan Rusterholz Stefan Rusterholz [f7ca7e] Initial commit.
 sorting.gemspec 2013-02-23 Stefan Rusterholz Stefan Rusterholz [7686f0] Cleaned up gemspec and added documentation dir ...

Read Me

README

Summary

Helpful functionality for sorting and comparing.

Installation

gem install sorting

Usage

Sort a list of Person objects

# Convenient
require 'sorting/convenience'
people.sort_by { |person| [asc(person.first_name), asc(person.last_name), desc(person.age)] }

# Or without patching Kernel
require 'sorting'
people.sort_by { |person|
  [Sorting.asc(person.first_name), Sorting.asc(person.last_name), Sorting.desc(person.age)]
}

# Care about expensive comparison values which may not always be needed
# assume item.expensive_value takes a lot of time to compute, but since it's the second value,
# it might only be needed in a small number of cases.
require 'sorting/convenience'
items.sort_by { |item|
  [asc(item.cheap_value), asc(:nils_last) { item.expensive_value }]
}

# Care about nil values in your data
require 'sorting/convenience'
people.sort_by { |person|
  [asc(person.first_name, :nils_first), asc(person.first_name, :nils_last)]
}

# Only care about nil values in your data
[5,3,nil,9].sort_by { |x| x || Sorting::Bigger } # Sorting::Smaller is available too

Take a look at {file:documentation/examples.rb} for more examples.

License

You can use this code under the {file:LICENSE.txt BSD-2-Clause License}, free of charge.
If you need a different license, please ask the author.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.