class Wordword::Commands::Train
Public Class Methods
new(file, options)
click to toggle source
# File lib/wordword/commands/train.rb, line 12 def initialize(file, options) @file = file @options = options end
Public Instance Methods
execute(input: $stdin, output: $stdout)
click to toggle source
# File lib/wordword/commands/train.rb, line 17 def execute(input: $stdin, output: $stdout) read_result = ReadWordTable.new.call(filename: @file) if read_result.success? words = read_result.success else output.puts( pastel.red( I18n.t("errors.#{read_result.failure}"), ), ) return end word_loop.run( words, loop_depth: @options[:number], ) rescue TTY::Reader::InputInterrupt prompt.error( pastel.red( I18n.t("train.interrupted"), ), ) ensure if words && word_loop if word_loop.wrong_answers.any? prompt.error(I18n.t("train.wrong_answers_intro")) word_loop.wrong_answers.each do |wrong_answer_message| prompt.say(wrong_answer_message) end elsif words.any? prompt.ok( I18n.t("train.everything_correct"), ) end end end
Private Instance Methods
pastel()
click to toggle source
# File lib/wordword/commands/train.rb, line 61 def pastel @pastel ||= Pastel.new end
word_loop()
click to toggle source
# File lib/wordword/commands/train.rb, line 57 def word_loop @word_loop ||= ::Train::WordLoop.new(self) end