Class: Board
- Inherits:
-
Object
- Object
- Board
- 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
-
#flop ⇒ Object
Returns the value of attribute flop.
-
#river ⇒ Object
Returns the value of attribute river.
-
#turn ⇒ Object
Returns the value of attribute turn.
Instance Method Summary collapse
- #cards ⇒ Object
-
#contains?(argument) ⇒ Boolean
Determines if the board contains the given card.
-
#contains_any?(argument) ⇒ Boolean
Determines if the board contains any of the given cards.
-
#initialize(cards = nil) ⇒ Board
constructor
A new instance of Board.
Constructor Details
#initialize(cards = nil) ⇒ Board
Returns a new instance of Board.
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
#flop ⇒ Object
Returns the value of attribute flop.
27 28 29 |
# File 'lib/rora/model/board.rb', line 27 def flop @flop end |
#river ⇒ Object
Returns the value of attribute river.
27 28 29 |
# File 'lib/rora/model/board.rb', line 27 def river @river end |
#turn ⇒ Object
Returns the value of attribute turn.
27 28 29 |
# File 'lib/rora/model/board.rb', line 27 def turn @turn end |
Instance Method Details
#cards ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rora/model/board.rb', line 68 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.
77 78 79 80 81 82 |
# File 'lib/rora/model/board.rb', line 77 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.
85 86 87 88 89 90 91 92 93 |
# File 'lib/rora/model/board.rb', line 85 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 |