-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.rb
67 lines (56 loc) · 1.69 KB
/
person.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'rubygems'
require 'twilio-ruby'
account_sid = 'XXX' # replace with your Twilio AccountSID
auth_token = 'XXX' # replace with your Twilio AuthToken
twilio_number = '+15552225555' # replace with your Twilio phone number
@client = Twilio::REST::Client.new account_sid, auth_token
class Person
attr_reader :first, :last, :phone
attr_accessor :santa
def initialize(line)
m = /(\S+)\s+(\S+)\s+(\d{11})/.match(line)
raise unless m
@first = m[1].capitalize
@last = m[2].capitalize
@phone = "+" + m[3]
end
def can_be_santa_of?(other)
# add your contraint logic here
@last != other.last
end
end
filename = ARGV.first
input = open(filename)
people = []
input.each_line do |line|
line.strip!
puts line
people << Person.new(line) unless line.empty?
end
santas = people.dup
people.each do |person|
person.santa = santas.delete_at(rand(santas.size))
end
people.each do |person|
unless person.santa.can_be_santa_of? person
candidates = people.select { |p| p.santa.can_be_santa_of?(person) && person.santa.can_be_santa_of?(p) }
raise if candidates.empty?
other = candidates[rand(candidates.size)]
temp = person.santa
person.santa = other.santa
other.santa = temp
finished = false
end
end
people.each do |person|
printf "%s -> %s \n", person.santa.first, person.first
# add your custom message here
message = "Hi #{person.santa.first}, it's Santa! You're in charge of gifting #{person.first} for the Moss Family Secret Santa. Max $20 - $20 buys a LOT of Lucky Charms. Happy gifting!"
puts message
sms = @client.account.messages.create(
:body => message,
:to => person.santa.phone,
:from => twilio_number
)
puts sms.sid
end