sort_by_str¶ ↑
SQL-like sorts on your Enumerables.
Getting Started¶ ↑
gem install sort_by_str require 'sort_by_str'
Usage¶ ↑
a = Date.parse('2010-08-22') b = Date.parse('2010-08-23) [a,b].sort_by_str('year ASC, day DESC') => [b,a]
Call sort_by_str on your Enumerable with a SQL-style sort expression containing a list of fields.
A basic expression might look like like
'year, month, day'.
Optional ASC (ascending) or DESC (descending) modifiers can also be used:
'year ASC, day DESC'
send
is used to extract values for comparison, so any valid method name can be used in the expression.
Author¶ ↑
Ben Koski, bkoski@nytimes.com
Copyright¶ ↑
Copyright © 2010 The New York Times Company. See LICENSE for details.