Class: Table

Inherits:
Object
  • Object
show all
Defined in:
lib/rora/model/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seats = nil) ⇒ Table

Returns a new instance of Table.



7
8
9
10
11
12
# File 'lib/rora/model/table.rb', line 7

def initialize seats=nil
  @seats = Array.new(seats.nil? ? 9 : seats)
  @board = Board.new
  @pot = Pot.new
  @deck = Deck.new
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



5
6
7
# File 'lib/rora/model/table.rb', line 5

def board
  @board
end

#deckObject (readonly)

Returns the value of attribute deck.



5
6
7
# File 'lib/rora/model/table.rb', line 5

def deck
  @deck
end

#potObject (readonly)

Returns the value of attribute pot.



5
6
7
# File 'lib/rora/model/table.rb', line 5

def pot
  @pot
end

#seatsObject (readonly)

Returns the value of attribute seats.



5
6
7
# File 'lib/rora/model/table.rb', line 5

def seats
  @seats
end

Instance Method Details

#add(player, seat_number = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rora/model/table.rb', line 20

def add player, seat_number=nil
  if !location.nil?
    raise ArgumentException, "Seat #{seat_number} is already taken by another player." if @seats[seat_number - 1] != nil
    @seats[seat_number - 1] = player
  else
    @seats.each_index do |x|
      if @seats[x].nil?
        @seats[x] = player
        return
      end
    end
  end
  self
end

#remove(player) ⇒ Object



35
36
37
38
# File 'lib/rora/model/table.rb', line 35

def remove player
  @seats.delete player
  self
end

#resetObject



14
15
16
17
18
# File 'lib/rora/model/table.rb', line 14

def reset
  @board = Board.new
  @pot = Pot.new
  @deck = Deck.new
end