Class: Wordword::Commands::Compose
- Inherits:
-
Wordword::Command
- Object
- Wordword::Command
- Wordword::Commands::Compose
- Defined in:
- lib/wordword/commands/compose.rb
Constant Summary collapse
- QUIT_CODE =
'\\q'
Instance Method Summary collapse
- #execute(input: $stdin, output: $stdout) ⇒ Object
-
#initialize(options) ⇒ Compose
constructor
A new instance of Compose.
Methods inherited from Wordword::Command
#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which
Constructor Details
#initialize(options) ⇒ Compose
Returns a new instance of Compose.
12 13 14 |
# File 'lib/wordword/commands/compose.rb', line 12 def initialize() @options = end |
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wordword/commands/compose.rb', line 16 def execute(input: $stdin, output: $stdout) words = {} loop do word = prompt.ask( "What is the word/phrase?(write #{QUIT_CODE} to exit)", ) do |w| w.required true end break if word == QUIT_CODE translation = prompt.ask( "What is the translation?(write #{QUIT_CODE} to exit)", ) do |t| t.required true end break if translation == QUIT_CODE words[word] = translation end rescue TTY::Reader::InputInterrupt prompt.error("\nYou interrupted the command, exiting...") ensure ::Compose::HandleExit.new(self).call(words) end |