Class: Board

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

Overview

The logical table area where community cards are dealt.

A board can be initialized with flop, turn and river cards.

# A board with the flop set board_one = Board.new “AS,KS,QS”

# A board with the flop and turn set board_two = Board.new “AS,KS,QS,JS”

# A board with the flop, turn and river set. board_three = Board.new “AS,KS,QS,JS,TS”

# An empty baord can be created as well. board_four = Board.new

Boards may also be populated programmatically using the flop, turn and river methods respectively:

board = Board.new board.flop = “AS,KS,QS” board.turn = “JS” board.river = “TS”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards = nil) ⇒ Board

Returns a new instance of Board.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rora/model/board.rb', line 29

def initialize cards=nil
  return if cards.nil?

  cds = cards.kind_of?(Array) ? cards : Card.to_cards(cards)
  raise ArgumentError, "3 to 5 cards are required to create a board, #{cds.size} cards provided" if cds.size < 3 || cds.size > 5
  raise ArgumentError, "The board contains duplicate cards" if cds.uniq.length != cds.length

  @flop = cds[0..2]
  @turn = cds[3] if cds.size >= 4
  @river = cds[4] if cds.size == 5
end

Instance Attribute Details

#flopObject

Returns the value of attribute flop.



27
28
29
# File 'lib/rora/model/board.rb', line 27

def flop
  @flop
end

#riverObject

Returns the value of attribute river.



27
28
29
# File 'lib/rora/model/board.rb', line 27

def river
  @river
end

#turnObject

Returns the value of attribute turn.



27
28
29
# File 'lib/rora/model/board.rb', line 27

def turn
  @turn
end

Instance Method Details

#cardsObject

Returns the community cards that have been dealt



74
75
76
77
78
79
80
# File 'lib/rora/model/board.rb', line 74

def cards
  cds = Array.new
  cds += @flop if !@flop.nil?
  cds.push(@turn) if !@turn.nil?
  cds.push(@river) if !@river.nil?
  cds
end

#contains?(argument) ⇒ Boolean

Determines if the board contains the given card.

Returns:

  • (Boolean)


83
84
85
86
87
88
# File 'lib/rora/model/board.rb', line 83

def contains? argument
  if argument.kind_of? Card
    return cards.include?(argument)
  end
  cards.include? Card.new(argument)
end

#contains_any?(argument) ⇒ Boolean

Determines if the board contains any of the given cards.

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
# File 'lib/rora/model/board.rb', line 91

def contains_any? argument
  if argument.kind_of? Array
    argument.each {|card| return true if cards.include? card}
  end
  if argument.kind_of? String
    Card.to_cards(argument).each {|card| return true if cards.include? card}
  end
  false
end

#sizeObject

Returns the number of community cards that have been dealt.



69
70
71
# File 'lib/rora/model/board.rb', line 69

def size
  cards.size
end

#to_sObject



101
102
103
# File 'lib/rora/model/board.rb', line 101

def to_s
  "Board: flop=#{@flop.map { |card| "#{card.key}" }.join(",")}"
end