Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/acpc_poker_types/card.rb
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
-
.acpc_card_number(rank, suit) ⇒ Integer
The numeric ACPC representation of the card.
- .cards(acpc_string_of_cards) ⇒ Array<Card>
-
.from_acpc(acpc_card) ⇒ Object
Card.
Instance Method Summary collapse
-
#initialize(rank, suit) ⇒ Card
constructor
A new instance of Card.
- #to_acpc ⇒ Object
- #to_i ⇒ Object
- #to_str ⇒ Object (also: #to_s)
Constructor Details
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
30 31 32 |
# File 'lib/acpc_poker_types/card.rb', line 30 def rank @rank end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
30 31 32 |
# File 'lib/acpc_poker_types/card.rb', line 30 def suit @suit end |
Class Method Details
.acpc_card_number(rank, suit) ⇒ Integer
Returns The numeric ACPC representation of the card.
26 27 28 |
# File 'lib/acpc_poker_types/card.rb', line 26 def self.acpc_card_number(rank, suit) rank.to_i * Suit::DOMAIN.length + suit.to_i end |
.cards(acpc_string_of_cards) ⇒ Array<Card>
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/acpc_poker_types/card.rb', line 12 def self.cards(acpc_string_of_cards) all_ranks = Rank::DOMAIN.map do |rank, rank_properties| rank_properties[:acpc_character] end.join all_suits = Suit::DOMAIN.map do |suit, suit_properties| suit_properties[:acpc_character] end.join acpc_string_of_cards.scan(/[#{all_ranks}][#{all_suits}]/).inject([]) do |pile, acpc_card| pile.push << Card.from_acpc(acpc_card) end end |
.from_acpc(acpc_card) ⇒ Object
Returns Card.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/acpc_poker_types/card.rb', line 33 def self.from_acpc(acpc_card) all_ranks = Rank::DOMAIN.values.map do |card_rank| card_rank[:acpc_character] end.join all_suits = Suit::DOMAIN.values.map do |card_suit| card_suit[:acpc_character] end.join if acpc_card.match(/([#{all_ranks}])([#{all_suits}])/) rank = $1 suit = $2 Card.from_components rank, suit else raise UnableToParseAcpcCard, acpc_card end end |
Instance Method Details
#to_acpc ⇒ Object
68 69 70 |
# File 'lib/acpc_poker_types/card.rb', line 68 def to_acpc @rank.to_acpc + @suit.to_acpc end |
#to_i ⇒ Object
58 59 60 |
# File 'lib/acpc_poker_types/card.rb', line 58 def to_i Card.acpc_card_number(@rank, @suit) end |
#to_str ⇒ Object Also known as: to_s
62 63 64 |
# File 'lib/acpc_poker_types/card.rb', line 62 def to_str @rank.to_s + @suit.to_s end |