Class: Holdem::Card

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/holdem/card.rb

Constant Summary collapse

RANKS =
%w(2 3 4 5 6 7 8 9 T J Q K A)
SUITS =
%w(c s d h)
ICONS =
{ 'c' => '♣', 's' => '♠', 'd' => '♦', 'h' => '♥' }
FACE_CARDS =
{ 'T' => 10, 'J' => 11, 'Q' => 12, 'K' => 13, 'A' => 14 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card) ⇒ Card

Returns a new instance of Card.



11
12
13
14
15
# File 'lib/holdem/card.rb', line 11

def initialize(card)
  @rank, @suit = card.chars if card.respond_to?(:chars)
  @icon = ICONS[suit]
  validate(card)
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'lib/holdem/card.rb', line 4

def icon
  @icon
end

#rankObject (readonly)

Returns the value of attribute rank.



4
5
6
# File 'lib/holdem/card.rb', line 4

def rank
  @rank
end

#suitObject (readonly)

Returns the value of attribute suit.



4
5
6
# File 'lib/holdem/card.rb', line 4

def suit
  @suit
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
# File 'lib/holdem/card.rb', line 25

def <=>(other)
  value <=> other.value
end

#to_sObject



21
22
23
# File 'lib/holdem/card.rb', line 21

def to_s
  "#{rank}#{icon}"
end

#valueObject



17
18
19
# File 'lib/holdem/card.rb', line 17

def value
  rank[/\d/] ? rank.to_i : FACE_CARDS[rank]
end