All Projects → grosser → Sort_alphabetical

grosser / Sort_alphabetical

Licence: mit
Ruby: sort UTF8 Strings alphabetical via Enumerable extension

Programming Languages

ruby
36898 projects - #4 most used programming language

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).

Setup

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
[email protected]
License: MIT
Build Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].