Module: Kirillica::Passport
- Defined in:
- lib/kirillica/passport.rb
Constant Summary collapse
- TABLE =
{ 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => ['e', 'ye'], 'ё' => ['e', 'ye'], 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'kh', 'ц' => 'ts', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shch', 'ъ' => '``', 'ы' => 'y', 'ь' => '`', 'э' => 'e`', 'ю' => 'yu', 'я' => 'ya', }
- DIPHTHONGS =
{ 'ай' => 'ay', 'ей' => ['ey', 'yey'], 'ий' => 'iy', 'ой' => 'oy', 'уй' => 'uy', 'ый' => 'yy', 'эй' => 'ey', 'юй' => 'yuy' }
- WINDOW =
3
Class Method Summary collapse
-
.revert!(phrase) ⇒ Object
invert transliteration.
-
.translit(phrase = '') ⇒ Object
transliteration.
Class Method Details
.revert!(phrase) ⇒ Object
invert transliteration
82 83 84 |
# File 'lib/kirillica/passport.rb', line 82 def self.revert!(phrase) # TODO end |
.translit(phrase = '') ⇒ Object
transliteration
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kirillica/passport.rb', line 53 def self.translit(phrase='') return '' if phrase.empty? translitted_phrase = '' chars = phrase.downcase.chars while chars.any? window = 2 if diphthong = DIPHTHONGS[chars.take(window).join] c = diphthong.is_a?(Array) ? diphthong.first : diphthong translitted_phrase << c chars.drop(window) else translitted_char = TABLE[chars.first] if translitted_char.nil? translitted_phrase << chars.first else c = translitted_char.is_a?(Array) ? translitted_char.first : translitted_char translitted_phrase << c end chars = chars.drop(1) end end translitted_phrase end |