Class: OfcpScoring::RankedHand
- Inherits:
-
Object
- Object
- OfcpScoring::RankedHand
show all
- Includes:
- Comparable
- Defined in:
- lib/ofcp_scoring/ranked_hand.rb
Constant Summary
collapse
- RANKINGS =
[
"HighCard", "Pair", "TwoPair", "ThreeOfAKind", "Straight", "Flush",
"FullHouse", "FourOfAKind", "StraightFlush", "RoyalFlush"
]
Instance Method Summary
collapse
Constructor Details
#initialize(hand = nil) ⇒ RankedHand
Returns a new instance of RankedHand.
17
18
19
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 17
def initialize(hand=nil)
@hand = hand
end
|
Instance Method Details
#<=>(other_hand) ⇒ Object
13
14
15
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 13
def <=>(other_hand)
RANKINGS.index(rank_name) <=> RANKINGS.index(other_hand.rank_name) unless rank_name == other_hand.rank_name
end
|
#compare_ranks(other) ⇒ Object
34
35
36
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 34
def compare_ranks(other)
(ranks - (ranks & other.ranks)).max <=> (other.ranks - (ranks & other.ranks)).max
end
|
#grouped_ranks ⇒ Object
30
31
32
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 30
def grouped_ranks
ranks.group_by{|card| card }
end
|
#rank_name ⇒ Object
9
10
11
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 9
def rank_name
self.class.to_s.split("::").last
end
|
#ranks ⇒ Object
21
22
23
24
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 21
def ranks
ranks = @hand.ranks
ranks.map{|r| r == 1 ? 14 : r}.sort
end
|
#suits ⇒ Object
26
27
28
|
# File 'lib/ofcp_scoring/ranked_hand.rb', line 26
def suits
suits = @hand.suits
end
|