module FiftyTwo::HasCards
Constants
Attributes
cards[R]
Public Class Methods
new(cards = [])
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 11 def initialize(cards = []) @cards = cards end
Public Instance Methods
draw()
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 15 def draw cards.shift end
locate(identifier)
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 23 def locate(identifier) return cards[identifier] if identifier.is_a?(Integer) cards.find { |c| c.identifier == identifier.upcase } end
render()
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 19 def render map(&:render).join(" ") end
transfer(cards, destination = nil)
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 28 def transfer(cards, destination = nil) gather(cards).map { |c| (destination || c.deck) << self.cards.delete(c) } end
Private Instance Methods
gather(cards)
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 54 def gather(cards) Array(cards).map do |card| card = locate(card) unless card.is_a?(FiftyTwo::Card) raise CardUnavailableError if card.nil? raise CardUnavailableError unless self.cards.include?(card) card end end
select(identifier)
click to toggle source
# File lib/fiftytwo/has_cards.rb, line 50 def select(identifier) self.class.new(cards.select { |c| c.send("#{identifier}?") }) end