Sha256: 6909fdffb73685b319585a23a4728204807cc346ba1c6461f8415f4980e81dff
Contents?: true
Size: 572 Bytes
Versions: 2
Compression:
Stored size: 572 Bytes
Contents
module CardsLib class Ranker include Comparable attr :rank, :rank_lookup def initialize(rank = nil, ranks = nil, rank_lookup = nil) @rank, @ranks, @rank_lookup = rank, ranks, rank_lookup end def ranks @ranks || Standard::RANKS end def ranker(rank_face = @rank) @rank_lookup ? @rank_lookup.(rank_face) : ranks.index(rank_face).to_i + 1 end def <=>(item) ranker(self.rank) <=> ranker(item.rank) end def sequential?(item) (ranker(self.rank) - ranker(item.rank)).abs == 1 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.2.1 | lib/cards_lib/ranker.rb |
cards_lib-0.2.0 | lib/cards_lib/ranker.rb |