Created
August 29, 2014 13:16
-
-
Save pumpkincouture/1b6194656336b7010d84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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