Skip to content
Ruby: sort UTF8 Strings alphabetical via Enumerable extension
Ruby
Find file
Latest commit 66cb8c1 Aug 14, 2015 @grosser bump
Failed to load latest commit information.
lib Freeze un-mutated string literal Aug 14, 2015
spec bump Aug 14, 2015
.travis.yml Add 2.1.0 to travis Mar 4, 2014
Gemfile bump Sep 20, 2013
Gemfile.lock bump Aug 14, 2015
Rakefile bundler Sep 20, 2013
Readme.md thanks @ Victor! Sep 20, 2013
sort_alphabetical.gemspec v1.0.2 Aug 14, 2015

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.