Class: Train::WordLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/wordword/interactors/train/word_loop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_context) ⇒ WordLoop

Returns a new instance of WordLoop.



10
11
12
13
# File 'lib/wordword/interactors/train/word_loop.rb', line 10

def initialize(command_context)
  @command_context = command_context
  @wrong_answers = []
end

Instance Attribute Details

#wrong_answersObject (readonly)

Returns the value of attribute wrong_answers.



8
9
10
# File 'lib/wordword/interactors/train/word_loop.rb', line 8

def wrong_answers
  @wrong_answers
end

Instance Method Details

#run(words, loop_depth:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# 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