class Train::WordLoop

Attributes

command_context[R]
wrong_answers[R]

Public Class Methods

new(command_context) click to toggle source
# File lib/wordword/interactors/train/word_loop.rb, line 10
def initialize(command_context)
  @command_context = command_context
  @wrong_answers = []
end

Public Instance Methods

run(words, loop_depth:) click to toggle source
# File lib/wordword/interactors/train/word_loop.rb, line 15
def run(words, loop_depth:)
  selected_words = selected_words(words, loop_depth)

  selected_words.each do |word, translated_word|
    answer = single_choice.call(word, translated_word, words: selected_words)
    if answer.failure?
      command_context.prompt.error(I18n.t("train.wrong_alert"))
      @wrong_answers << answer.failure
    end
  end
end

Private Instance Methods

selected_words(words, loop_depth) click to toggle source
# File lib/wordword/interactors/train/word_loop.rb, line 31
def selected_words(words, loop_depth)
  words.to_a.sample(loop_depth || words.size).to_h
end
single_choice() click to toggle source
# File lib/wordword/interactors/train/word_loop.rb, line 35
def single_choice
  SingleChoice.new(
    @command_context,
  )
end