Module: Telegraph
Constant Summary
Constants included from MorseCode
MorseCode::ENCODE_DICT, MorseCode::EN_DECODE_DICT, MorseCode::LETTER_SPACE, MorseCode::RU_DECODE_DICT
Constants included from MorseDictionaries
MorseDictionaries::LATIN, MorseDictionaries::NUMBERS, MorseDictionaries::PUNCTUATION_MARKS, MorseDictionaries::RUSSIAN
Class Method Summary collapse
Methods included from MorseCode
choose_dictionary, lang_support?
Class Method Details
.morse_to_text(morse, language = :en) ⇒ Object
Morse to Text
В режиме morse_to_text: Между одним символом азбуки морзе, используется один пробел. Между словами отступ равен 7 пробелам. К примеру: “… — … … — …”.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/morsify/telegraph.rb', line 21 def self.morse_to_text(morse, language = :en) unless morse.nil? # выбор словаря для расшифровки dict = MorseCode.choose_dictionary(language) # массив слов words = to_words_array(morse) # массив, содержащий вложенные массивы # в которых слова разбиты на символы азбуки морзе letters = words_to_morse_char(words) # массив расшифрованных букв convert_letters = decode_chars(dict, letters) # результат конвертирования convert_letters.join('').encode('utf-8') end end |
.text_to_morse(text) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/morsify/telegraph.rb', line 6 def self.text_to_morse(text) unless text.nil? # массив букв включая пробелы letters = to_letters_array(text.strip.upcase) # результат конвертирования convert_letters(letters).join('').strip end end |