Class: PokerEngine::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/poker_engine/card.rb

Constant Summary collapse

COLORS =
{ spade: :spade, club: :club, heart: :heart, diamond: :diamond }.freeze
RANKS =
(2..10).to_a.map(&:to_s) + %w(J Q K A)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank, color) ⇒ Card

Returns a new instance of Card.



14
15
16
17
# File 'lib/poker_engine/card.rb', line 14

def initialize(rank, color)
  @rank = rank
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



12
13
14
# File 'lib/poker_engine/card.rb', line 12

def color
  @color
end

#rankObject (readonly)

Returns the value of attribute rank.



12
13
14
# File 'lib/poker_engine/card.rb', line 12

def rank
  @rank
end

Class Method Details

.french_deckObject



6
7
8
9
10
# File 'lib/poker_engine/card.rb', line 6

def self.french_deck
  Card::RANKS
    .product(Card::COLORS.values)
    .map { |rank, color| Card.new rank, color }
end

Instance Method Details

#to_sObject



23
24
25
# File 'lib/poker_engine/card.rb', line 23

def to_s
  "#{@rank}#{@color[0]}"
end

#valueObject



19
20
21
# File 'lib/poker_engine/card.rb', line 19

def value
  @value ||= RANKS.index rank
end