module CodebreakerGem::ConsoleUserInteraction

Constants

ENTITIES

Public Instance Methods

create_entity(klass) click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 25
def create_entity(klass)
  loop do
    class_heading(klass)
    entity = klass.new(user_input)
    return entity if entity.valid?

    output.display(entity.errors)
  end
end
exit_from_console() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 20
def exit_from_console
  output.exit
  exit
end
failing() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 43
def failing
  @failing ||= Failing.new
end
options_list() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 11
def options_list
  Console::COMMANDS.values.map(&:capitalize)
end
output() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 39
def output
  @output ||= Output.new
end
statistic() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 35
def statistic
  @statistic ||= Statistic.new
end
user_input() click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 15
def user_input
  input_value = gets.chomp.downcase
  exit?(input_value) ? exit_from_console : input_value
end

Private Instance Methods

class_heading(klass) click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 49
def class_heading(klass)
  case klass.to_s
  when ENTITIES[:player] then output.registration
  when ENTITIES[:difficulty] then output.difficulty_heading
  when ENTITIES[:guess] then output.statistics(@game)
  end
end
exit?(input_value) click to toggle source
# File lib/app/modules/console_user_interaction.rb, line 57
def exit?(input_value)
  input_value == Console::COMMANDS[:exit]
end