Class: PokerHands::PokerHand

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
Comparable
Defined in:
lib/deck_of_cards_handler/poker_hands/poker_hand.rb

Overview

This represents a poker hands raking

Constant Summary collapse

HANDS =
i[OnePair TwoPairs ThreeOfAKind Straight Flush FullHouse FourOfAKind StraightFlush].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards:) ⇒ PokerHand

Returns a new instance of PokerHand.

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 17

def initialize(cards:)
  raise ArgumentError if cards.size != 5

  @cards = cards
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



14
15
16
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 14

def cards
  @cards
end

Class Method Details

.build_from_string(string:) ⇒ Object



35
36
37
38
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 35

def build_from_string(string:)
  cards = Packet.build_from_string(string:).cards
  PokerHand.create(cards:)
end

.create(cards:) ⇒ Object



55
56
57
58
59
60
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 55

def create(cards:)
  HANDS.reverse_each do |hand|
    return PokerHands.const_get(hand).new(cards:) if PokerHands.const_get(hand).is?(cards)
  end
  HighCard.new(cards:)
end

Instance Method Details

#<=>(other) ⇒ Object



26
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 26

def <=>(other); end

#rankObject



29
# File 'lib/deck_of_cards_handler/poker_hands/poker_hand.rb', line 29

def rank; end