Class: AcpcPokerTypes::Rank

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

Constant Summary collapse

DOMAIN =
{
  two: {acpc_character: '2', text: '2', number: 0},
  three: {acpc_character: '3', text: '3', number: 1},
  four: {acpc_character: '4', text: '4', number: 2},
  five: {acpc_character: '5', text: '5', number: 3},
  six: {acpc_character: '6', text: '6', number: 4},
  seven: {acpc_character: '7', text: '7', number: 5},
  eight: {acpc_character: '8', text: '8', number: 6},
  nine: {acpc_character: '9', text: '9', number: 7},
  ten: {acpc_character: 'T', text: '10', number: 8},
  jack: {acpc_character: 'J', text: 'J', number: 9},
  queen: {acpc_character: 'Q', text: 'Q', number: 10},
  king: {acpc_character: 'K', text: 'K', number: 11},
  ace: {acpc_character: 'A', text: 'A', number: 12}
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank) ⇒ Rank

Returns a new instance of Rank.



46
47
48
# File 'lib/acpc_poker_types/rank.rb', line 46

def initialize(rank)
  @symbol = AcpcPokerTypes::Rank.symbol_from_rank_token rank
end

Class Method Details

.hash_from_rank_token(rank) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acpc_poker_types/rank.rb', line 24

def self.hash_from_rank_token(rank)
  if rank.kind_of?(Integer)
    DOMAIN.find do |rank_symbol, properties|
      properties[:number] == rank
    end
  else
    DOMAIN.find do |rank_symbol, properties|
      rank_symbol == rank.to_sym ||
      properties[:acpc_character] == rank.to_s ||
      properties[:text] == rank.to_s
    end
  end
end

.symbol_from_rank_token(rank) ⇒ Object

Raises:

  • (UnrecognizedRank)


38
39
40
41
42
43
44
# File 'lib/acpc_poker_types/rank.rb', line 38

def self.symbol_from_rank_token(rank)
  rank_hash = hash_from_rank_token rank

  raise UnrecognizedRank, rank.to_s unless rank_hash

  rank_hash.first
end

Instance Method Details

#to_acpcObject



58
59
60
# File 'lib/acpc_poker_types/rank.rb', line 58

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

#to_iObject



54
55
56
# File 'lib/acpc_poker_types/rank.rb', line 54

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

#to_sObject Also known as: to_html, to_str



62
63
64
# File 'lib/acpc_poker_types/rank.rb', line 62

def to_s
  DOMAIN[@symbol][:text]
end

#to_symObject



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

def to_sym
  @symbol
end