Class: Train::SingleChoice

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

Constant Summary collapse

CHOICES_SIZE =
4

Instance Method Summary collapse

Constructor Details

#initialize(command_context) ⇒ SingleChoice

Returns a new instance of SingleChoice.



12
13
14
# File 'lib/wordword/interactors/train/single_choice.rb', line 12

def initialize(command_context)
  @command_context = command_context
end

Instance Method Details

#call(word, translated_word, words:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wordword/interactors/train/single_choice.rb', line 16

def call(word, translated_word, words:)
  answer = command_context.prompt.select(
    "What is the translation of '#{word}'?",
    choices(translated_word, words),
  )

  if answer == translated_word
    Success(answer)
  else
    Failure(
      I18n.t(
        "train.wrong_answer_entry",
        word: pastel.blue(word),
        correct_answer: pastel.green(translated_word),
        answer: pastel.red(answer),
      ),
    )
  end
end