Sha256: a3b385341498416aec9659a33eb17c9953584fec4a04cee3a80fda1df24516a4
Contents?: true
Size: 575 Bytes
Versions: 3
Compression:
Stored size: 575 Bytes
Contents
module CardsLib class Ranker include Comparable attr :rank, :ranks, :rank_lookup def initialize( rank = nil, ranks: "A23456789TJQK".split(''), rank_lookup: ->rank_face{ @ranks.index(rank_face).to_i + 1 }) @rank = rank @ranks = ranks @rank_lookup = rank_lookup end def <=>(item) @rank_lookup[self.rank] <=> @rank_lookup[item.rank] end def inspect @rank end def sequential(item) (@rank_lookup[self.rank] - @rank_lookup[item.rank]).abs == 1 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.0.9 | lib/cards_lib/ranker.rb |
cards_lib-0.0.8 | lib/cards_lib/ranker.rb |
cards_lib-0.0.7 | lib/cards_lib/ranker.rb |