Project

natsort

0.0
No commit activity in last 3 years
No release in over 3 years
Provides natural sorting methods to Enumerable.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.6
~> 5.0
>= 0

Runtime

>= 0
 Project Readme

Build Status

natsort

This gem provides natural sorting methods to Enumerable.

Installation

Add this line to your application's Gemfile:

gem 'natsort'

And then execute:

$ bundle

Or install it yourself as:

$ gem install natsort

Usage

%w(1 10 2).natsort
#=> ["1", "2", "10"]

or

[
  { "n" => "1" },
  { "n" => "10" },
  { "n" => "2" }
].natsort_by { |x| x["n"] }
#=> [
      { "n" => "1" },
      { "n" => "2" },
      { "n" => "10" }
    ]

These sorts are case sensitive by default. If you want to sort objects in case insensitive, pass false to the methods.

%w(B a c).natsort(false)
#=> ["a", "B", "c"]

or

[
  { "n" => "B" },
  { "n" => "a" },
  { "n" => "c" }
].natsort_by(false) { |x| x["n"] }
#=> [
      { "n" => "a" },
      { "n" => "B" },
      { "n" => "c" }
    ]

Contributing

  1. Fork it ( https://github.com/a2ikm/natsort/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request