Sha256: 027c16d4cefcc9fbece6b4dcb54d53da1007936e2034aab428d404fa60053b7b
Contents?: true
Size: 711 Bytes
Versions: 3
Compression:
Stored size: 711 Bytes
Contents
# frozen string literal: true require 'spy_alley_application/types/nationality' module SpyAlleyApplication class NewGame class AssignSpyIdentities def call(seat_assignments) seat_assignments = seat_assignments.to_a spy_identities = SpyAlleyApplication::Types::Nationality.values - (seat_assignments.map{|s| s[:spy_identity]}.reject(&:nil?)) seat_assignments.each do |seat| if seat[:spy_identity].nil? index = rand(spy_identities.size) seat[:spy_identity] = spy_identities[index] spy_identities = spy_identities - [spy_identities[index]] end end seat_assignments end end end end
Version data entries
3 entries across 3 versions & 1 rubygems