Class: AcpcPokerTypes::Rank
- Inherits:
-
Object
- Object
- AcpcPokerTypes::Rank
- Includes:
- Comparable
- 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
- #<=>(rank) ⇒ Object
-
#initialize(rank) ⇒ Rank
constructor
A new instance of Rank.
- #to_acpc ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object (also: #to_html, #to_str)
- #to_sym ⇒ Object
Constructor Details
#initialize(rank) ⇒ Rank
Returns a new instance of Rank.
48 49 50 |
# File 'lib/acpc_poker_types/rank.rb', line 48 def initialize(rank) @symbol = AcpcPokerTypes::Rank.symbol_from_rank_token rank end |
Class Method Details
.hash_from_rank_token(rank) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/acpc_poker_types/rank.rb', line 26 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
40 41 42 43 44 45 46 |
# File 'lib/acpc_poker_types/rank.rb', line 40 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
#<=>(rank) ⇒ Object
52 53 54 |
# File 'lib/acpc_poker_types/rank.rb', line 52 def <=>(rank) self.to_i <=> rank.to_i end |
#to_acpc ⇒ Object
64 65 66 |
# File 'lib/acpc_poker_types/rank.rb', line 64 def to_acpc DOMAIN[@symbol][:acpc_character] end |
#to_i ⇒ Object
60 61 62 |
# File 'lib/acpc_poker_types/rank.rb', line 60 def to_i DOMAIN[@symbol][:number] end |
#to_s ⇒ Object Also known as: to_html, to_str
68 69 70 |
# File 'lib/acpc_poker_types/rank.rb', line 68 def to_s DOMAIN[@symbol][:text] end |
#to_sym ⇒ Object
56 57 58 |
# File 'lib/acpc_poker_types/rank.rb', line 56 def to_sym @symbol end |