Class: Mastermind::CLI
- Inherits:
-
Object
- Object
- Mastermind::CLI
- Defined in:
- lib/mastermind/cli.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#game ⇒ Object
readonly
Returns the value of attribute game.
-
#instream ⇒ Object
readonly
Returns the value of attribute instream.
-
#interact ⇒ Object
readonly
Returns the value of attribute interact.
-
#outstream ⇒ Object
readonly
Returns the value of attribute outstream.
Instance Method Summary collapse
- #get_command ⇒ Object
-
#initialize(instream, outstream) ⇒ CLI
constructor
A new instance of CLI.
- #instructions? ⇒ Boolean
- #play? ⇒ Boolean
- #process_command ⇒ Object
- #quit? ⇒ Boolean
- #run ⇒ Object
Constructor Details
#initialize(instream, outstream) ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 12 13 |
# File 'lib/mastermind/cli.rb', line 8 def initialize(instream, outstream) @instream = instream @outstream = outstream @command = "" @interact = Mastermind::Interact.new end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/mastermind/cli.rb', line 5 def command @command end |
#game ⇒ Object (readonly)
Returns the value of attribute game.
6 7 8 |
# File 'lib/mastermind/cli.rb', line 6 def game @game end |
#instream ⇒ Object (readonly)
Returns the value of attribute instream.
6 7 8 |
# File 'lib/mastermind/cli.rb', line 6 def instream @instream end |
#interact ⇒ Object (readonly)
Returns the value of attribute interact.
6 7 8 |
# File 'lib/mastermind/cli.rb', line 6 def interact @interact end |
#outstream ⇒ Object (readonly)
Returns the value of attribute outstream.
6 7 8 |
# File 'lib/mastermind/cli.rb', line 6 def outstream @outstream end |
Instance Method Details
#get_command ⇒ Object
25 26 27 28 |
# File 'lib/mastermind/cli.rb', line 25 def get_command outstream.print interact.command_prompt self.command = instream.gets.strip.upcase end |
#instructions? ⇒ Boolean
47 48 49 |
# File 'lib/mastermind/cli.rb', line 47 def instructions? command == 'I' || command == 'INSTRUCTIONS' end |
#play? ⇒ Boolean
43 44 45 |
# File 'lib/mastermind/cli.rb', line 43 def play? command == 'P' || command == 'PLAY' end |
#process_command ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mastermind/cli.rb', line 30 def process_command case when quit? then outstream.puts interact.print_farewell when instructions? then outstream.puts interact.print_instructions(Mastermind.color_option_string(6)) when play? then Mastermind::PlayGame.new(instream, outstream, interact).run else outstream.puts interact.print_invalid(command) end end |
#quit? ⇒ Boolean
39 40 41 |
# File 'lib/mastermind/cli.rb', line 39 def quit? command == 'Q' || command == 'QUIT' end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/mastermind/cli.rb', line 15 def run outstream.puts interact.screen_clear outstream.puts interact.print_title outstream.puts interact.print_intro until quit? get_command process_command end end |