Class: Holdem::Card
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
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(card) ⇒ Card
constructor
A new instance of Card.
- #to_s ⇒ Object
- #value ⇒ Object
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
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
4 5 6 |
# File 'lib/holdem/card.rb', line 4 def icon @icon end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
4 5 6 |
# File 'lib/holdem/card.rb', line 4 def rank @rank end |
#suit ⇒ Object (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_s ⇒ Object
21 22 23 |
# File 'lib/holdem/card.rb', line 21 def to_s "#{rank}#{icon}" end |
#value ⇒ Object
17 18 19 |
# File 'lib/holdem/card.rb', line 17 def value rank[/\d/] ? rank.to_i : FACE_CARDS[rank] end |