Sha256: 74565b6b4d9d8e2738caa6d6afd01bdcdc9b2c8892fb9fcce8814835aa8001fb

Contents?: true

Size: 550 Bytes

Versions: 3

Compression:

Stored size: 550 Bytes

Contents

module CardsLib
  class Ranker
    include Comparable
    attr :rank, :ranks, :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 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.1.2 lib/cards_lib/ranker.rb
cards_lib-0.1.1 lib/cards_lib/ranker.rb
cards_lib-0.1.0 lib/cards_lib/ranker.rb