class Sorare::Rewards::Picker
Picker
allows to randomly pick a card
Attributes
cards[RW]
player_counter[RW]
Public Class Methods
new(seed, salt)
click to toggle source
# File lib/sorare/rewards/picker.rb, line 13 def initialize(seed, salt) @random = Random.new(seed, salt) @cards = [] @player_counter = Hash.new(0) @shuffled = false end
Public Instance Methods
add_player(slug, count)
click to toggle source
# File lib/sorare/rewards/picker.rb, line 20 def add_player(slug, count) raise "Can't add a player to a started draw" if @shuffled @cards += Array.new(count, slug) end
pick()
click to toggle source
# File lib/sorare/rewards/picker.rb, line 26 def pick shuffle! unless @shuffled @cards.shift.tap do |card| @player_counter[card] += 1 if card end end
shuffle!()
click to toggle source
# File lib/sorare/rewards/picker.rb, line 34 def shuffle! @cards.shuffle!(random: @random) @shuffled = true end