class Gameworks::Player
Attributes
disqualified[R]
disqualified?[R]
id[R]
name[R]
score[RW]
Public Class Methods
new(payload={})
click to toggle source
# File lib/gameworks/player.rb, line 11 def initialize(payload={}) unless payload.is_a?(Hash) && payload.has_key?('name') && payload['name'].is_a?(String) @invalid = true return end @id = SecureRandom.uuid.to_s.split('-').first @name = payload['name'] @score = 0 @disqualified = false # used for evented "block until it's my turn". the game will push a token # on this queue when it's the player's turn, or will push a nil when the # game is completed @em_queue = EventMachine::Queue.new end
Public Instance Methods
as_json(for_player=nil)
click to toggle source
# File lib/gameworks/player.rb, line 48 def as_json(for_player=nil) { id: id, name: name, score: score, disqualified: disqualified } end
disqualify!()
click to toggle source
# File lib/gameworks/player.rb, line 36 def disqualify! @disqualified = true end
signal_turn(token)
click to toggle source
# File lib/gameworks/player.rb, line 40 def signal_turn(token) @em_queue.push(token) end
to_json(for_player=nil)
click to toggle source
# File lib/gameworks/player.rb, line 55 def to_json(for_player=nil) as_json(for_player).to_json end
valid?()
click to toggle source
# File lib/gameworks/player.rb, line 30 def valid? !@invalid end
wait_for_turn() { |token| ... }
click to toggle source
# File lib/gameworks/player.rb, line 44 def wait_for_turn @em_queue.pop{ |token| yield token } end