class Tratocyr::CyrillicTranslator

Provide functionality for translation between translit symbols string to cyrillic symbols string

Constants

TYPE_ERROR_MESSAGE

Public Instance Methods

to_cyrillic(text) click to toggle source

Translate string symbols from translit to cyrillic @param: text [String] - text with translit symbols @example

Tratocyr::CyrillicTranslator.new.to_cyrillic("Privet medved'!")

@return: [String] - text with translated with cyrillic symbols @note: Return empty string if parameter type not equals to 'String'

# File lib/tratocyr/cyrillic_translator.rb, line 15
def to_cyrillic(text)
  return '' if not is_valid?(text)

  latin_text = text.dup
  latin_to_cyr.each do |mapping|
    latin_text.gsub!(mapping[:latin_regexp], mapping[:cyrillic_value])
  end
  latin_text
end
to_cyrillic!(text) click to toggle source

Translate string symbols from translit to cyrillic @param: text [String] - text with translit symbols @example

Tratocyr::CyrillicTranslator.new.to_cyrillic("Privet medved'!")

@return: [String] - text with translated with cyrillic symbols @raise: [TypeError] - if try to provide not String data

# File lib/tratocyr/cyrillic_translator.rb, line 31
def to_cyrillic!(text)

  raise TypeError, TYPE_ERROR_MESSAGE if not is_valid?(text)

  self.to_cyrillic(text)
end

Private Instance Methods

is_valid?(text) click to toggle source
# File lib/tratocyr/cyrillic_translator.rb, line 42
def is_valid?(text)
  not text.nil? and text.kind_of?(String)
end