module Sunrise::Utils::Transliteration

Russian transliteration

Constants

LOWER
LOWER_MULTI
LOWER_SINGLE

Transliteration heavily based on rutils gem by Julian “julik” Tarkhanov and Co. <rutils.rubyforge.org/> Cleaned up and optimized.

MULTI_KEYS
UPPER
UPPER_MULTI
UPPER_SINGLE

Public Instance Methods

transliterate(str) click to toggle source

Transliterate a string with russian characters

Возвращает строку, в которой все буквы русского алфавита заменены на похожую по звучанию латиницу

# File lib/sunrise/utils/transliteration.rb, line 51
def transliterate(str)
  chars = str.scan(/#{MULTI_KEYS.join '|'}|\w|./)

  result = ''

  chars.each_with_index do |char, index|
    result << if UPPER.key?(char) && LOWER.key?(chars[index + 1])
                # combined case
                UPPER[char].downcase.capitalize
              elsif UPPER.key?(char)
                UPPER[char]
              elsif LOWER.key?(char)
                LOWER[char]
              else
                char
              end
  end

  result
end