Sorting library
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Allow ruby head failures and release Jan 11, 2016
.gitignore Add more doc and split code Sep 23, 2015
.rspec Add .rspec for spec runner colours Oct 30, 2013
.rubocop.yml Add more doc and split code Sep 23, 2015
.rubocop_todo.yml Add more doc and split code Sep 23, 2015
LICENSE moved to bundler Dec 15, 2010
sorted.gemspec Fix uniq block argument error Dec 24, 2015


Build Status

Sorted at it's core is a set of objects that let you sort many different attributes in weird and wonderful ways.


The secret sauce is the Sorted::Set object, in this example we 'toggle' email:

require 'sorted/set'

a =[['email', 'asc'], ['name', 'asc']])
b =[['email', 'asc'], ['phone', 'asc']])

s = a.direction_intersect(b)

s.to_a #=> [['email', 'desc'], ['phone', 'asc'], ['name', 'asc']]

The best way to think about this is to imagine a spreed sheet and what happens when you sort by various columns, Sorted::Set pretty much just does that.


Parsers return a Sorted::Set that can then be used by an encoder:

require 'sorted/uri_query'

set = Sorted::URIQuery.parse('name_asc!email_asc')
Sorted::SQLQuery.encode(set) #=> 'name ASC email ASC'

Currently implemented:

  • Sorted::SQLQuery
  • Sorted::URIQuery
  • Sorted::JSONQuery
  • Sorted::ElasticsearchQuery
  • Sorted::ParamsQuery