Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Created August 29, 2014 13:16
Show Gist options
  • Save pumpkincouture/1b6194656336b7010d84 to your computer and use it in GitHub Desktop.
Save pumpkincouture/1b6194656336b7010d84 to your computer and use it in GitHub Desktop.
class SecretSanta
attr_reader :santa_list, :santa_shuffled, :people
def initialize
@santa_list = santa_list
@santa_shuffled = santa_shuffled
@people = people
end
def people_list
people_list = []
csv_data = CSV.foreach('./lib/example.csv') do |row|
@people = Person.new(row)
people_list << @people
end
@santa_list = people_list
@santa_list
end
def random_list
duplicate_list = @santa_list.clone
@santa_shuffled = duplicate_list.sort_by { rand }
@santa_shuffled
end
def assign_random_santa
number = @santa_shuffled.length - 1
@santa_list.each do |person|
potential_partner = @santa_shuffled[ rand ]
person.assigned_santa = potential_partner if @people.not_assigned(potential_partner)
@santa_shuffled.delete(potential_partner)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment