class Wordword::Commands::Compose
Constants
- QUIT_CODE
Public Class Methods
new(options)
click to toggle source
# File lib/wordword/commands/compose.rb, line 12 def initialize(options) @options = options end
Public Instance Methods
execute(input: $stdin, output: $stdout)
click to toggle source
# 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