class HDeck::Deck
Provides a Harrow deck for a Card
Caster to interact with
Public Class Methods
new()
click to toggle source
# File lib/hdeck/deck.rb, line 9 def initialize card_path = File.expand_path('../../cards.json', File.dirname(__FILE__)) card_data = JSON.parse(File.read(card_path)) @cards = get_cards(card_data) end
Public Instance Methods
draw()
click to toggle source
# File lib/hdeck/deck.rb, line 23 def draw return if @cards.length <= 0 @cards.shift end
each(&block)
click to toggle source
# File lib/hdeck/deck.rb, line 19 def each(&block) @cards.each(&block) end
length()
click to toggle source
# File lib/hdeck/deck.rb, line 15 def length @cards.length end
shuffle()
click to toggle source
# File lib/hdeck/deck.rb, line 29 def shuffle counter = @cards.length - 1 while counter > 0 ri = rand(counter) @cards[counter], @cards[ri] = @cards[ri], @cards[counter] counter -= 1 end @cards end
Private Instance Methods
get_cards(card_data)
click to toggle source
# File lib/hdeck/deck.rb, line 43 def get_cards(card_data) card_data.map do |data| Card.new( name: data['name'], desc: data['desc'], morality: data['morality'], ability: data['ability'] ) end end