Class: AcpcPokerTypes::Card

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#rankObject (readonly)

Returns the value of attribute rank.



23
24
25
# File 'lib/acpc_poker_types/card.rb', line 23

def rank
  @rank
end

#suitObject (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.

Returns:

  • (Integer)

    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>

Parameters:

  • acpc_string_of_cards (String)

    A string of cards in ACPC format

Returns:



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.

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_acpcObject



50
51
52
# File 'lib/acpc_poker_types/card.rb', line 50

def to_acpc
  "#{@rank.to_acpc}#{@suit.to_acpc}"
end

#to_iObject



40
41
42
# File 'lib/acpc_poker_types/card.rb', line 40

def to_i
  AcpcPokerTypes::Card.acpc_card_number(@rank, @suit)
end

#to_strObject Also known as: to_s



44
45
46
# File 'lib/acpc_poker_types/card.rb', line 44

def to_str
  "#{@rank}#{@suit}"
end