Skip to content

ndbroadbent/dictionary_order_sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dictionary Order Sort

Build Status

Sorts an array of strings in the same manner as the Linux sort command running with the --dictionary-order option. Only blanks and alphanumeric characters are considered.

I created this gem because I needed to use the comm command in a Capistrano recipe, and wanted to sort the list of files in Ruby. comm requires the input files to be sorted using the collating sequence specified by `LC_COLLATE', and this defaults to dictionary sort.

Installation

Add the following line to your Gemfile:

gem 'dictionary_order_sort'

Usage

You can now use the dict_sort method on arrays or sets. Array elements must be strings, or respond to to_s.

Use it like this:

["a", "a-2", "_a-3", "abc_", "_def_"].dict_sort

#=> ["a", "a-2", "_a-3", "abc_", "_def_"]

About

Sort an array of strings with the same logic as `sort --dictionary-sort`

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages