Sha256: 7e0e12b2a2dc418a1d09d6059ffa04309c6ebc143f16b9a15fc101840ff9d7e7

Contents?: true

Size: 474 Bytes

Versions: 1

Compression:

Stored size: 474 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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cards_lib-0.0.6 lib/cards_lib/ranker.rb