Class: AcpcPokerTypes::Suit
- Inherits:
-
Object
- Object
- AcpcPokerTypes::Suit
- Includes:
- Comparable
- 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
- .all_suits ⇒ Object
- .every_suit ⇒ Object
- .hash_from_suit_token(suit) ⇒ Object
- .symbol_from_suit_token(suit) ⇒ Object
Instance Method Summary collapse
- #<=>(suit) ⇒ Object
-
#initialize(suit) ⇒ Suit
constructor
A new instance of Suit.
- #to_acpc ⇒ Object (also: #to_s)
- #to_html ⇒ Object
- #to_i ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(suit) ⇒ Suit
Returns a new instance of Suit.
51 52 53 |
# File 'lib/acpc_poker_types/suit.rb', line 51 def initialize(suit) @symbol = AcpcPokerTypes::Suit.symbol_from_suit_token suit end |
Class Method Details
.all_suits ⇒ Object
17 18 19 20 21 |
# File 'lib/acpc_poker_types/suit.rb', line 17 def self.all_suits DOMAIN.map do |suit, properties| Suit.new(suit) end end |
.every_suit ⇒ Object
23 24 25 26 27 |
# File 'lib/acpc_poker_types/suit.rb', line 23 def self.every_suit DOMAIN.each do |suit, properties| yield Suit.new(suit) end end |
.hash_from_suit_token(suit) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acpc_poker_types/suit.rb', line 29 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
43 44 45 46 47 48 49 |
# File 'lib/acpc_poker_types/suit.rb', line 43 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
#<=>(suit) ⇒ Object
55 56 57 |
# File 'lib/acpc_poker_types/suit.rb', line 55 def <=>(suit) self.to_i <=> suit.to_i end |
#to_acpc ⇒ Object Also known as: to_s
67 68 69 |
# File 'lib/acpc_poker_types/suit.rb', line 67 def to_acpc DOMAIN[@symbol][:acpc_character] end |
#to_html ⇒ Object
74 75 76 |
# File 'lib/acpc_poker_types/suit.rb', line 74 def to_html DOMAIN[@symbol][:html_character] end |
#to_i ⇒ Object
63 64 65 |
# File 'lib/acpc_poker_types/suit.rb', line 63 def to_i DOMAIN[@symbol][:number] end |
#to_sym ⇒ Object
59 60 61 |
# File 'lib/acpc_poker_types/suit.rb', line 59 def to_sym @symbol end |