Created
March 6, 2019 07:51
-
-
Save anaumov/ef1e2cf5710ac7659fff9271f4a0fb71 to your computer and use it in GitHub Desktop.
Translit с русского на латиницу
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Translit | |
RU_TO_EN = { | |
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', | |
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', | |
'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', | |
'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts', | |
'ч' => 'ch','ш' => 'sh','щ' => 'sch','ъ' => '','ы' => 'y', 'ь' => '', | |
'э' => 'je', 'ю' => 'yu', 'я' => 'ya' | |
} | |
def self.ru_to_en(word) | |
new.ru_to_en(word) | |
end | |
def ru_to_en(word) | |
word.chars.map { |char| RU_TO_EN[char.downcase] || char }.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment