class BetweenTheSheets::Card

Constants

IMAGES
NAMES
SUITS
SUIT_COLORS

Attributes

name[R]
suit[R]
value[R]

Public Class Methods

draw(*skip_cards) click to toggle source
# File lib/between_the_sheets/card.rb, line 38
def self.draw(*skip_cards)
  return Card.new if skip_cards.empty?

  loop do
    card = Card.new
    break card unless skip_cards.include? card.id
  end
end
new() click to toggle source
# File lib/between_the_sheets/card.rb, line 31
def initialize
  @name = NAMES.sample
  @suit = SUITS.sample
  @image = IMAGES[@suit.to_sym]
  @value = self.class.value(@name)
end
value(name) click to toggle source
# File lib/between_the_sheets/card.rb, line 47
def self.value(name)
  case name
  when "A"
    1
  when "J"
    11
  when "Q"
    12
  when "K"
    13
  when "JOKER"
    0
  else
    NAMES.index(name) + 1
  end
end

Public Instance Methods

id() click to toggle source
# File lib/between_the_sheets/card.rb, line 70
def id
  (Digest::MD5.new << self.to_s).to_s
end
joker?() click to toggle source
# File lib/between_the_sheets/card.rb, line 74
def joker?
  @name == "JOKER"
end
to_s() click to toggle source
# File lib/between_the_sheets/card.rb, line 64
def to_s
  # The space at the end is intentional to pad the image with the
  # next character.
  "#{@name}#{@image.colorize(SUIT_COLORS[@suit.to_sym])} "
end