Module: CodebreakerGem::ConsoleUserInteraction
- Included in:
- Console
- Defined in:
- lib/app/modules/console_user_interaction.rb
Constant Summary collapse
- ENTITIES =
{ player: 'Player', difficulty: 'Difficulty', guess: 'Guess' }.freeze
Instance Method Summary collapse
- #create_entity(klass) ⇒ Object
- #exit_from_console ⇒ Object
- #failing ⇒ Object
- #options_list ⇒ Object
- #output ⇒ Object
- #statistic ⇒ Object
- #user_input ⇒ Object
Instance Method Details
#create_entity(klass) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
20 21 22 23 |
# File 'lib/app/modules/console_user_interaction.rb', line 20 def exit_from_console output.exit exit end |
#failing ⇒ Object
43 44 45 |
# File 'lib/app/modules/console_user_interaction.rb', line 43 def failing @failing ||= Failing.new end |
#options_list ⇒ Object
11 12 13 |
# File 'lib/app/modules/console_user_interaction.rb', line 11 def Console::COMMANDS.values.map(&:capitalize) end |
#output ⇒ Object
39 40 41 |
# File 'lib/app/modules/console_user_interaction.rb', line 39 def output @output ||= Output.new end |
#statistic ⇒ Object
35 36 37 |
# File 'lib/app/modules/console_user_interaction.rb', line 35 def statistic @statistic ||= Statistic.new end |
#user_input ⇒ Object
15 16 17 18 |
# 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 |