Class: 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.



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

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

Class Method Details

.hash_from_suit_token(suit) ⇒ Object



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

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)


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

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



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

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

#to_htmlObject



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

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

#to_iObject



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

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

#to_symObject



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

def to_sym
  @symbol
end