Class: AcpcPokerBasicProxy::BasicProxy
- Inherits:
-
Object
- Object
- AcpcPokerBasicProxy::BasicProxy
- Defined in:
- lib/acpc_poker_basic_proxy/basic_proxy.rb
Constant Summary collapse
- CONCATENATED_MODIFIABLE_ACTIONS =
AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.to_a.join
Class Method Summary collapse
-
.send_action(connection, match_state, action) ⇒ Integer
Sends the given
actionto through the givenconnectionin the ACPC format. - .valid_action?(action) ⇒ Boolean
- .validate_action(action) ⇒ Object
Instance Method Summary collapse
-
#initialize(dealer_information) ⇒ BasicProxy
constructor
A new instance of BasicProxy.
- #receive_match_state! ⇒ Object
- #send_action(action) ⇒ Object
Constructor Details
#initialize(dealer_information) ⇒ BasicProxy
Returns a new instance of BasicProxy.
43 44 45 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 43 def initialize(dealer_information) @dealer_communicator = DealerStream.new dealer_information.port_number, dealer_information.host_name, dealer_information.millisecond_response_timeout end |
Class Method Details
.send_action(connection, match_state, action) ⇒ Integer
Sends the given action to through the given connection in the ACPC format.
25 26 27 28 29 30 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 25 def self.send_action(connection, match_state, action) validate_action action full_action = "#{AcpcPokerTypes::MatchState.parse(match_state.to_s)}:#{action.to_s}" connection.write full_action end |
.valid_action?(action) ⇒ Boolean
37 38 39 40 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 37 def self.valid_action?(action) action.to_s.match(/^[#{AcpcPokerTypes::PokerAction::CONCATONATED_ACTIONS}]$/) || action.to_s.match(/^[#{CONCATENATED_MODIFIABLE_ACTIONS}]\d+$/) end |
.validate_action(action) ⇒ Object
33 34 35 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 33 def self.validate_action(action) raise IllegalActionFormat unless self.valid_action?(action) end |
Instance Method Details
#receive_match_state! ⇒ Object
57 58 59 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 57 def receive_match_state! @match_state = AcpcPokerTypes::MatchState.receive @dealer_communicator end |
#send_action(action) ⇒ Object
51 52 53 54 |
# File 'lib/acpc_poker_basic_proxy/basic_proxy.rb', line 51 def send_action(action) raise InitialMatchStateNotYetReceived unless @match_state BasicProxy.send_action @dealer_communicator, @match_state, action end |