class RpgTools::PlayingCardDeck

Attributes

card_picks[RW]
type[RW]
value[RW]

Public Class Methods

new(type) click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 5
def initialize(type)
  @type = type
  type_check
  @card_picks = 0
  @value = nil
end

Public Instance Methods

card() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 12
def card
  @card_picks += 1

  @value =
    if @type == 52
      joker_picked? ? 'Joker' : standard_card
    else
      standard_card
    end
end
hand() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 23
def hand
  [].tap do |hand|
    until hand.count == 5
      card = standard_card

      unless hand.include?(card) || hand.count('Joker') == 2
        hand << card
        @card_picks += 1
      end
    end
  end
end

Private Instance Methods

color() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 56
def color
  ['Clubs', 'Hearts', 'Diamonds', 'Spades'].sample(1)
end
joker_picked?() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 44
def joker_picked?
  [0, 1].include?((0..54).to_a.sample(1).first)
end
number() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 48
def number
  if @type == 32
    [(7..10).to_a, 'Jack', 'Queen', 'King'].flatten.sample(1)
  else
    [(1..10).to_a, 'Jack', 'Queen', 'King'].flatten.sample(1)
  end
end
standard_card() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 60
def standard_card
  @value = [number, color].join(' of ')
end
type_check() click to toggle source
# File lib/rpg_tools/playing_card_deck.rb, line 38
def type_check
  unless [32, 52].include?(@type)
    raise ArgumentError.new('A playing card deck contains 32 or 52 cards only.')
  end
end