Class: Tratocyr::CyrillicTranslator
- Inherits:
-
Object
- Object
- Tratocyr::CyrillicTranslator
- 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
-
#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'.
-
#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.
Methods included from Mapping
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'
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
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 |