Class: TexasHoldem::Card
- Inherits:
-
Object
- Object
- TexasHoldem::Card
- Includes:
- Comparable
- Defined in:
- lib/texas-holdem/card.rb
Constant Summary collapse
- NUM_RANKS =
2..10
- FACE_CARD_RANKS =
{ J: 11, Q: 12, K: 13, A: 14 }
- SUITS =
{c: '♣', s: '♠', h: '♥', d: '♦'}
- ACE_HIGH =
FACE_CARD_RANKS[:A]
- ACE_LOW =
NUM_RANKS.min - 1
Instance Attribute Summary collapse
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#suit ⇒ Object
readonly
Returns the value of attribute suit.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other_card) ⇒ Object
-
#initialize(card_as_string) ⇒ Card
constructor
A new instance of Card.
- #is_face_card? ⇒ Boolean
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(card_as_string) ⇒ Card
Returns a new instance of Card.
22 23 24 25 |
# File 'lib/texas-holdem/card.rb', line 22 def initialize(card_as_string) @suit = parse_suit(card_as_string) @rank = parse_rank(card_as_string) end |
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
10 11 12 |
# File 'lib/texas-holdem/card.rb', line 10 def rank @rank end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
10 11 12 |
# File 'lib/texas-holdem/card.rb', line 10 def suit @suit end |
Class Method Details
.build_all ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/texas-holdem/card.rb', line 12 def self.build_all all = [] SUITS.each do |suit, icon| NUM_RANKS.to_a.tap {|num_ranks| num_ranks.concat(FACE_CARD_RANKS.keys) }.each do |rank| all << new(rank.to_s + suit.to_s) end end all end |
Instance Method Details
#<=>(other_card) ⇒ Object
39 40 41 |
# File 'lib/texas-holdem/card.rb', line 39 def <=>(other_card) to_i <=> other_card.to_i end |
#is_face_card? ⇒ Boolean
27 28 29 |
# File 'lib/texas-holdem/card.rb', line 27 def is_face_card? FACE_CARD_RANKS.has_key? rank.to_sym end |
#to_i ⇒ Object
31 32 33 |
# File 'lib/texas-holdem/card.rb', line 31 def to_i is_face_card? ? FACE_CARD_RANKS[rank.to_sym] : rank.to_i end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/texas-holdem/card.rb', line 35 def to_s rank + SUITS[suit.to_sym] end |