Class: PokerEngine::HandIndex
- Inherits:
-
Object
- Object
- PokerEngine::HandIndex
- Defined in:
- lib/poker_engine/hand_index.rb
Constant Summary collapse
- RANK_TABLE =
The index is equivalent to the level strength
[HandLevels::HighCard, HandLevels::OnePair, HandLevels::TwoPairs, HandLevels::ThreeOfAKind, HandLevels::Straight, HandLevels::Flush, HandLevels::FullHouse, HandLevels::FourOfAKind, HandLevels::StraightFlush].freeze
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #>(other) ⇒ Object
-
#initialize(cards) ⇒ HandIndex
constructor
A new instance of HandIndex.
- #level ⇒ Object
Constructor Details
#initialize(cards) ⇒ HandIndex
Returns a new instance of HandIndex.
14 15 16 |
# File 'lib/poker_engine/hand_index.rb', line 14 def initialize(cards) @cards = cards end |
Instance Attribute Details
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
12 13 14 |
# File 'lib/poker_engine/hand_index.rb', line 12 def cards @cards end |
Instance Method Details
#<=>(other) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/poker_engine/hand_index.rb', line 18 def <=>(other) outer_level_compare = (RANK_TABLE.index(level) <=> RANK_TABLE.index(other.level)) return outer_level_compare unless outer_level_compare.zero? level <=> other.level end |
#>(other) ⇒ Object
27 28 29 |
# File 'lib/poker_engine/hand_index.rb', line 27 def >(other) level <=> other.level end |
#level ⇒ Object
31 32 33 34 |
# File 'lib/poker_engine/hand_index.rb', line 31 def level @level ||= RANK_TABLE.reverse_each.find { |level| level.owns?(cards) } end |