Class: HandType

Inherits:
Object
  • Object
show all
Defined in:
lib/rora/model/hand_type.rb

Overview

The nine different types of 5-card poker hand.

A 5-card poker hand will be one of the following hand types:

  1. High Card

  2. One Pair

  3. Two Pair

  4. Three of a Kind

  5. Straight

  6. Flush

  7. Full House

  8. Four of a Kind

  9. Straight Flush

Constant Summary collapse

HIGH_CARD =
new("HC", "High Card", 1)
ONE_PAIR =
new("1P", "One Pair", 2)
TWO_PAIR =
new("2P", "Two Pair", 3)
THREE_OF_A_KIND =
new("3K", "Three of a Kind", 4)
STRAIGHT =
new("ST", "Straight", 5)
FLUSH =
new("FL", "Flush", 6)
FULL_HOUSE =
new("FH", "Full House", 7)
FOUR_OF_A_KIND =
new("4K", "Four of a Kind", 8)
STRAIGHT_FLUSH =
new("SF", "Straight Flush", 9)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, order) ⇒ HandType

Returns a new instance of HandType.



19
20
21
22
23
# File 'lib/rora/model/hand_type.rb', line 19

def initialize(key, value, order)
  @key = key
  @value = value
  @order = order
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



17
18
19
# File 'lib/rora/model/hand_type.rb', line 17

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



17
18
19
# File 'lib/rora/model/hand_type.rb', line 17

def order
  @order
end

#valueObject (readonly)

Returns the value of attribute value.



17
18
19
# File 'lib/rora/model/hand_type.rb', line 17

def value
  @value
end

Class Method Details

.get(key) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'lib/rora/model/hand_type.rb', line 29

def self.get(key)
  self.values.each do |type|
    return type if type.key.casecmp(key) == 0
  end
  raise ArgumentError, "No hand type exists for key '#{key}'"
end

.valuesObject



25
26
27
# File 'lib/rora/model/hand_type.rb', line 25

def self.values
  [HIGH_CARD, ONE_PAIR, TWO_PAIR, THREE_OF_A_KIND, STRAIGHT, FLUSH, FULL_HOUSE, FOUR_OF_A_KIND, STRAIGHT_FLUSH]
end

Instance Method Details

#to_sObject



36
37
38
# File 'lib/rora/model/hand_type.rb', line 36

def to_s
  "HandType: key='#{@key}', value='#{@value}'"
end