Module: SortAlphabetical
Instance Method Summary collapse
Instance Method Details
#normalize(string) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# 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 |