Skip to content

Instantly share code, notes, and snippets.

@anaumov
Created March 6, 2019 07:51
Show Gist options
  • Save anaumov/ef1e2cf5710ac7659fff9271f4a0fb71 to your computer and use it in GitHub Desktop.
Save anaumov/ef1e2cf5710ac7659fff9271f4a0fb71 to your computer and use it in GitHub Desktop.
Translit с русского на латиницу
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