lib/cards_lib/ranker.rb in cards_lib-0.0.9 vs lib/cards_lib/ranker.rb in cards_lib-0.1.0

- old
+ new

@@ -1,28 +1,21 @@ 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 + def initialize rank = nil, + ranks: "A23456789TJQK".chars, + rank_lookup: nil + + @rank, @ranks, @rank_lookup = rank, ranks, rank_lookup || + ->rank_face{ @ranks.index(rank_face).to_i + 1 } end def <=>(item) @rank_lookup[self.rank] <=> @rank_lookup[item.rank] end - def inspect - @rank - end - - def sequential(item) + def sequential?(item) (@rank_lookup[self.rank] - @rank_lookup[item.rank]).abs == 1 end end end