Skip to content
This repository has been archived by the owner on Mar 6, 2019. It is now read-only.

Latest commit

 

History

History
35 lines (21 loc) · 753 Bytes

README.rdoc

File metadata and controls

35 lines (21 loc) · 753 Bytes

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 © 2010 The New York Times Company. See LICENSE for details.