Class: AcpcPokerTypes::Card
- Inherits:
-
Object
- Object
- AcpcPokerTypes::Card
- Defined in:
- lib/acpc_poker_types/card.rb
Constant Summary collapse
- CONCATONATED_RANKS =
(AcpcPokerTypes::Rank::DOMAIN.map { |rank, properties| properties[:acpc_character] }).join
- CONCATONATED_SUITS =
(AcpcPokerTypes::Suit::DOMAIN.map { |suit, properties| properties[:acpc_character] }).join
- CONCATONATED_CARDS =
"#{CONCATONATED_RANKS}#{CONCATONATED_SUITS}"
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<AcpcPokerTypes::Card>
-
.from_acpc(acpc_card) ⇒ Object
AcpcPokerTypes::Card.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(rank, suit) ⇒ Card
constructor
A new instance of Card.
- #to_acpc ⇒ Object
- #to_i ⇒ Object
- #to_str ⇒ Object (also: #to_s)
Constructor Details
#initialize(rank, suit) ⇒ Card
Returns a new instance of Card.
35 36 37 38 |
# File 'lib/acpc_poker_types/card.rb', line 35 def initialize(rank, suit) @rank = AcpcPokerTypes::Rank.new rank @suit = AcpcPokerTypes::Suit.new suit end |
Instance Attribute Details
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
23 24 25 |
# File 'lib/acpc_poker_types/card.rb', line 23 def rank @rank end |
#suit ⇒ Object (readonly)
Returns the value of attribute suit.
23 24 25 |
# File 'lib/acpc_poker_types/card.rb', line 23 def suit @suit end |
Class Method Details
.acpc_card_number(rank, suit) ⇒ Integer
Returns The numeric ACPC representation of the card.
19 20 21 |
# File 'lib/acpc_poker_types/card.rb', line 19 def self.acpc_card_number(rank, suit) rank.to_i * AcpcPokerTypes::Suit::DOMAIN.length + suit.to_i end |
.cards(acpc_string_of_cards) ⇒ Array<AcpcPokerTypes::Card>
12 13 14 15 16 |
# File 'lib/acpc_poker_types/card.rb', line 12 def self.cards(acpc_string_of_cards) acpc_string_of_cards.scan(/[#{CONCATONATED_RANKS}][#{CONCATONATED_SUITS}]/).map do |acpc_card| AcpcPokerTypes::Card.from_acpc(acpc_card) end end |
.from_acpc(acpc_card) ⇒ Object
Returns AcpcPokerTypes::Card.
26 27 28 29 30 31 |
# File 'lib/acpc_poker_types/card.rb', line 26 def self.from_acpc(acpc_card) rank = acpc_card[0] suit = acpc_card[1] AcpcPokerTypes::Card.from_components rank, suit end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/acpc_poker_types/card.rb', line 54 def ==(other) to_s == other.to_s end |
#to_acpc ⇒ Object
50 51 52 |
# File 'lib/acpc_poker_types/card.rb', line 50 def to_acpc "#{@rank.to_acpc}#{@suit.to_acpc}" end |
#to_i ⇒ Object
40 41 42 |
# File 'lib/acpc_poker_types/card.rb', line 40 def to_i AcpcPokerTypes::Card.acpc_card_number(@rank, @suit) end |
#to_str ⇒ Object Also known as: to_s
44 45 46 |
# File 'lib/acpc_poker_types/card.rb', line 44 def to_str "#{@rank}#{@suit}" end |