module SortAlphabetical
Public Instance Methods
normalize(string)
click to toggle source
# File lib/sort_alphabetical.rb, line 21 def normalize(string) result = String.new UnicodeUtils.compatibility_decomposition(string).each_char do |c| if UnicodeUtils.general_category(c) =~ /Letter|Separator|Punctuation|Number/ result << c end end result end
sort(set) { |item| ... }
click to toggle source
# File lib/sort_alphabetical.rb, line 10 def sort(set) set.sort_by do |item| if block_given? item = yield(item).to_s else item = item.to_s end [normalize(item), item] # when both á and a are present, sort them a, á end end