class CardsLib::Ranker

Attributes

rank[R]
rank_lookup[R]

Public Class Methods

new(rank = nil, ranks = nil, rank_lookup = nil) click to toggle source

Initialize's arguments: rank - is whatever part of the object, or the object itself you choose to use. ranks - is a simple hash to lookup a cards value with the keys matching the rank object. rank_lookup - is an optional Proc to redefine how you will lookup a cards value.

# File lib/cards_lib/ranker.rb, line 9
def initialize(rank = nil, ranks = nil, rank_lookup = nil)
  @rank = rank
  @ranks = ranks
  @rank_lookup = rank_lookup
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/cards_lib/ranker.rb, line 27
def <=>(other)
  ranker(rank) <=> ranker(other.rank)
end
ranker(rank_face = @rank) click to toggle source
# File lib/cards_lib/ranker.rb, line 19
def ranker(rank_face = @rank)
  if @rank_lookup
    @rank_lookup.(rank_face)
  else
    ranks.index(rank_face).to_i + 1
  end
end
ranks() click to toggle source
# File lib/cards_lib/ranker.rb, line 15
def ranks
  @ranks || Standard::RANKS
end
sequential?(other) click to toggle source
# File lib/cards_lib/ranker.rb, line 31
def sequential?(other)
  (ranker(rank) - ranker(other.rank)).abs == 1
end