Class: Tratocyr::CyrillicTranslator

Inherits:
Object
  • Object
show all
Includes:
Mapping
Defined in:
lib/tratocyr/cyrillic_translator.rb

Overview

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

Instance Method Summary collapse

Methods included from Mapping

#latin_to_cyr

Instance Method Details

#to_cyrillic(text) ⇒ Object

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

Examples:

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


15
16
17
18
19
20
21
22
23
# 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) ⇒ Object

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

Examples:

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

Raises:

  • (TypeError)


31
32
33
34
35
36
# 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