Module: SortAlphabetical

Extended by:
SortAlphabetical
Included in:
SortAlphabetical
Defined in:
lib/sort_alphabetical.rb

Instance Method Summary collapse

Instance Method Details

#sort(set) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/sort_alphabetical.rb', line 8

def sort(set)
  set.sort_by do |item|
    if block_given?
      item = yield(item).to_s
    else
      item = item.to_s
    end
    [to_ascii(item),item]#when both á and a are present, sort them a, á
  end
end

#to_ascii(string) ⇒ Object



19
20
21
# File 'lib/sort_alphabetical.rb', line 19

def to_ascii(string)
  split_codepoints(string).map(&:to_s).reject{|e| e.length > 1}.join
end