Class: Process::Roulette::Controller::Driver
- Inherits:
-
Object
- Object
- Process::Roulette::Controller::Driver
- Defined in:
- lib/process/roulette/controller/driver.rb
Overview
Encapsulates both the controller and spectator behavior. If the password is nil, the controller is considered a spectator, allowed to watch the bout, but not to control it.
It’s state machine works as follows:
CONNECT
- connects to croupier, performs handshake
- advances to COMMAND
COMMAND
- waits for input from terminal (unless spectator)
* "GO" => sends "GO" to croupier
* "EXIT" => sends "EXIT" to croupier
- listens for commands from croupier
* "GO" => advances to GAME
* "EXIT" => advances to FINISH
GAME
- listens for updates from croupier
# "GO" => begins next round
* "UPDATE" => print update from croupier
* "DONE" => advances to DONE
DONE
- diplays final scoreboard
- advances to COMMAND
FINISH
- closes sockets, terminates
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(host, port, password = nil) ⇒ Driver
constructor
A new instance of Driver.
- #run ⇒ Object
- #spectator? ⇒ Boolean
Constructor Details
#initialize(host, port, password = nil) ⇒ Driver
Returns a new instance of Driver.
38 39 40 41 42 |
# File 'lib/process/roulette/controller/driver.rb', line 38 def initialize(host, port, password = nil) @host = host @port = port @password = password end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
35 36 37 |
# File 'lib/process/roulette/controller/driver.rb', line 35 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
35 36 37 |
# File 'lib/process/roulette/controller/driver.rb', line 35 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
35 36 37 |
# File 'lib/process/roulette/controller/driver.rb', line 35 def port @port end |
#socket ⇒ Object
Returns the value of attribute socket.
36 37 38 |
# File 'lib/process/roulette/controller/driver.rb', line 36 def socket @socket end |
Instance Method Details
#run ⇒ Object
48 49 50 51 |
# File 'lib/process/roulette/controller/driver.rb', line 48 def run handler = Controller::ConnectHandler handler = handler.new(self).run while handler end |
#spectator? ⇒ Boolean
44 45 46 |
# File 'lib/process/roulette/controller/driver.rb', line 44 def spectator? password.nil? end |