Class: AcpcPokerTypes::Suit

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/suit.rb

Constant Summary collapse

DOMAIN =
{
  clubs: {acpc_character: 'c', html_character: '♣', number: 0},
  diamonds: {acpc_character: 'd', html_character: '♦', number: 1},
  hearts: {acpc_character: 'h', html_character: '♥', number: 2},
  spades: {acpc_character: 's', html_character: '♠', number: 3}
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suit) ⇒ Suit

Returns a new instance of Suit.



37
38
39
# File 'lib/acpc_poker_types/suit.rb', line 37

def initialize(suit)
  @symbol = AcpcPokerTypes::Suit.symbol_from_suit_token suit
end

Class Method Details

.hash_from_suit_token(suit) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/acpc_poker_types/suit.rb', line 15

def self.hash_from_suit_token(suit)
  if suit.kind_of?(Integer)
    DOMAIN.find do |suit_symbol, properties|
      properties[:number] == suit
    end
  else
    DOMAIN.find do |suit_symbol, properties|
      suit_symbol == suit.to_sym ||
      properties[:acpc_character] == suit.to_s ||
      properties[:html_character] == suit.to_s
    end
  end
end

.symbol_from_suit_token(suit) ⇒ Object

Raises:

  • (UnrecognizedSuit)


29
30
31
32
33
34
35
# File 'lib/acpc_poker_types/suit.rb', line 29

def self.symbol_from_suit_token(suit)
  suit_hash = hash_from_suit_token suit

  raise UnrecognizedSuit, suit.to_s unless suit_hash

  suit_hash.first
end

Instance Method Details

#to_acpcObject Also known as: to_s



49
50
51
# File 'lib/acpc_poker_types/suit.rb', line 49

def to_acpc
  DOMAIN[@symbol][:acpc_character]
end

#to_htmlObject



56
57
58
# File 'lib/acpc_poker_types/suit.rb', line 56

def to_html
  DOMAIN[@symbol][:html_character]
end

#to_iObject



45
46
47
# File 'lib/acpc_poker_types/suit.rb', line 45

def to_i
  DOMAIN[@symbol][:number]
end

#to_symObject



41
42
43
# File 'lib/acpc_poker_types/suit.rb', line 41

def to_sym
  @symbol
end