Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby: sort UTF8 Strings alphabetical via Enumerable extension
Ruby
branch: master

v1.0.1

latest commit fc0703cc8f
@grosser authored
Failed to load latest commit information.
lib removes to_ascii, add string normalization with unicode utils
spec recheck if it is actually pending
.travis.yml Add 2.1.0 to travis
Gemfile bump
Gemfile.lock v1.0.1
Rakefile bundler
Readme.md thanks @ Victor!
sort_alphabetical.gemspec v1.0.1

Readme.md

Adds sort_alphabetical and sort_alphabetical_by to Enumberable(Array/Hash...), which sorts UTF8 Strings alphabetical. This sorting is done by placing variants on the same level as base character (A comes before Ä but ÄA comes before AB).

Requirements

  • Ruby >= 1.9

Setup

  • As gem: sudo gem install sort_alphabetical

Usage

['b','á'].sort_alphabetical == ['á','b']
[['b',1],['á',2]].sort_alphabetical_by(&:first) == [['á',2],['b',1]]

SortAlphabetical.normalize('á') == 'a'

Alternative

Use ICU

collator = ICU::Collation::Collator.new("nb")
array.sort! { |a,b| collator.compare(a, b) }

TODO

  • Sort non-ascii-convertables like ß(ss), œ(oe) , fi(fi), see Ligatures
  • Integrate natural sorting e.g. ['a11', 'a2'] => ['a2', 'a11'] like NaturalSort

Contributors

Michael Grosser
michael@grosser.it
License: MIT
Build Status

Something went wrong with that request. Please try again.