Class: Alphabet

Inherits:
Object show all
Defined in:
lib/alphabets.rb

Direct Known Subclasses

CzechAlphabet, EnglishAlphabet

Class Method Summary collapse

Class Method Details

.by_locale(locale) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/alphabets.rb', line 15

def self.by_locale(locale)
  language = locale.split('-').first.downcase
  case language
    when 'cs'
      CzechAlphabet
    when 'en'
      EnglishAlphabet
    else
      raise "Language #{language} of locale #{locale} is unknown."
  end
end

.compare_letters(x, y) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/alphabets.rb', line 5

def self.compare_letters(x, y)
  i = letters.mb_chars.index(x)
  j = letters.mb_chars.index(y)
  if i && j
    i <=> j
  else
    x.mb_chars.normalize(:d) <=> y.mb_chars.normalize(:d)
  end
end