Class: Morsify::Prompt
- Inherits:
-
Object
- Object
- Morsify::Prompt
- Defined in:
- lib/morsify/prompt.rb
Class Method Summary collapse
-
.tty ⇒ Object
Сценарий на случай того если пользователь запустил программу без аргументов командной строки.
Class Method Details
.tty ⇒ Object
Сценарий на случай того если пользователь запустил программу без аргументов командной строки
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/morsify/prompt.rb', line 9 def self.tty prompt = TTY::Prompt.new mode = prompt.select('Select the operation mode:') do |option| option.choice name: 'Text to Morse', value: 1 option.choice name: 'Morse to Text', value: 2 option.choice name: 'Text to WAV File', value: 3 option.choice name: 'Exit', value: 4 end exit if mode == 4 user_input = prompt.ask('Type a text:') if mode == 2 lang = prompt.ask('Select language for decode (en/ru):', value: 'en') end lang = lang.to_sym if mode == 2 if MorseCode.lang_support?(lang) && mode == 2 abort 'The current language is not supported!' end # переключение режимов puts Telegraph.text_to_morse(user_input) if mode == 1 puts Telegraph.morse_to_text(user_input) if mode == 2 && lang == :en puts Telegraph.morse_to_text(user_input) if mode == 2 && lang == :ru puts MorseWave.text_to_wave(user_input) if mode == 3 end |