-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_santa.rb
49 lines (40 loc) · 1.01 KB
/
secret_santa.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'mail'
class Mailer
def initialize(assignments, host_email = '[email protected]')
@assignments = assignments
@host_email = host_email
end
def send!
@assignments.each do |assignment|
mail_to(assignment)
end
end
def mail_to(assignee)
mail = Mail.new do
from @host_email
to assignee[:email]
subject '🎄 🎄 🎄 Your Secret Santa gift recipient is... 🎅 🎅 🎅'
body "You will be buying a gift for...........\n\n\n#{assignee[:giftee]}!!!!!!"
end
mail.deliver!
end
end
class GifteeListAssigner
attr_reader :santas
def initialize(santas)
@santas = santas
end
def shuffle
@santas = @santas.shuffle
end
def assign_giftees!
@giftees = @santas.cycle(2).to_a
@santas.each do |santa|
next_index = @giftees.find_index { |s| s[:name] == santa[:name] }.next
santa[:giftee] = @giftees[next_index][:name]
end
end
def giftee_of(santa)
@giftees.find { |s| s[:name] == santa }[:giftee]
end
end