secretsanta 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +2 -3
- data/bin/secretsanta +1 -1
- data/lib/secretsanta.rb +54 -26
- data/secretsanta.gemspec +1 -1
- metadata +1 -2
- data/lib/secretsanta/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d303454bdb8a9514390fca95bf5345fb4130594911d1c743e39b0e554ccb2ce
|
4
|
+
data.tar.gz: f95b26a7fa26c01f1c935f9bc38abdd6d0039d6bee49b02094e03a639b55fe46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a7897f0595fefe1cf45e7cb7617948673db4f5d778c753279e31a34feda9d1a3418e7cdaba867be2873599ede680ee9c23318b9c132c766d861f65ee24406f0
|
7
|
+
data.tar.gz: 458aacc92f2bda8efbaf0d4f392283d4eedc71ac5143a1e46a395aa2907de1506f4a9f37df76d482a2a705a0b0e5553de205b5c21eef3c38baecea87d7880c7c
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/bin/secretsanta
CHANGED
data/lib/secretsanta.rb
CHANGED
@@ -2,63 +2,71 @@
|
|
2
2
|
|
3
3
|
require 'twilio-ruby'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
module SecretSanta
|
5
|
+
class SecretSanta
|
8
6
|
class Error < StandardError; end
|
9
7
|
|
10
|
-
|
8
|
+
VERSION = '1.1.0'
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
@dry_run = options.dry_run
|
12
|
+
@from_number = options.from_number
|
13
|
+
@participants = options.participants
|
14
|
+
@sms = Twilio::REST::Client.new(options.twilio_account_sid, options.twilio_auth_token) unless @dry_run
|
15
|
+
end
|
11
16
|
|
12
|
-
def notify_participants!
|
13
|
-
|
14
|
-
pairs = generate_pairs(options.participants)
|
17
|
+
def notify_participants!
|
18
|
+
pairs = generate_pairs
|
15
19
|
|
16
|
-
return pairs if
|
20
|
+
return pairs if @dry_run
|
17
21
|
|
18
22
|
pairs.each do |pair|
|
19
|
-
|
23
|
+
@sms.messages.create(
|
20
24
|
body: "Happy holidays! You have been assigned to give a gift to #{pair.recipient_name} this year.",
|
21
|
-
from:
|
25
|
+
from: @from_number,
|
22
26
|
to: pair.sender_number
|
23
27
|
)
|
24
28
|
rescue Twilio::Rest::TwilioError => e
|
25
29
|
puts e.message
|
26
30
|
end
|
27
31
|
|
28
|
-
"\nAll participants have been notified
|
32
|
+
"\nAll participants have been notified. Happy holidays! 🎅 🎄 🎁\n\n"
|
29
33
|
end
|
30
34
|
|
31
|
-
def generate_pairs
|
35
|
+
def generate_pairs
|
36
|
+
raise Error, SecretSanta.error_message if impossible?
|
37
|
+
|
32
38
|
[].tap do |list|
|
33
39
|
loop do
|
34
|
-
participants.each do |
|
35
|
-
|
36
|
-
recipient = participants[index]
|
40
|
+
@participants.each do |sender|
|
41
|
+
recipient = @participants.sample
|
37
42
|
|
38
|
-
next if try_again?(
|
43
|
+
next if try_again?(sender, recipient)
|
39
44
|
|
40
|
-
list << { sender_number:
|
45
|
+
list << { sender_number: sender[:number], recipient_name: recipient[:name] }
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
sender[:has_assignment] = true
|
48
|
+
recipient[:is_assigned] = true
|
44
49
|
end
|
45
50
|
|
46
|
-
break if done?
|
51
|
+
break if done?
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
def
|
52
|
-
|
56
|
+
def done?
|
57
|
+
@participants.all? { |p| p[:has_assignment] && p[:is_assigned] }
|
58
|
+
end
|
53
59
|
|
54
|
-
|
60
|
+
def impossible?
|
61
|
+
@participants.one? || invalid_hash?
|
55
62
|
end
|
56
63
|
|
57
|
-
def
|
58
|
-
|
64
|
+
def try_again?(sender, recipient)
|
65
|
+
sender[:has_assignment] || recipient[:is_assigned] || sender[:number] == recipient[:number] ||
|
66
|
+
!sender[:disallow].nil? && sender[:disallow].include?(recipient[:name])
|
59
67
|
end
|
60
68
|
|
61
|
-
def help_text
|
69
|
+
def self.help_text
|
62
70
|
<<~HEREDOC
|
63
71
|
SecretSanta, version #{VERSION}
|
64
72
|
|
@@ -72,4 +80,24 @@ module SecretSanta
|
|
72
80
|
|
73
81
|
HEREDOC
|
74
82
|
end
|
83
|
+
|
84
|
+
def self.error_message
|
85
|
+
<<~HEREDOC
|
86
|
+
Looks like something is wrong with your participants file. Make sure that it:
|
87
|
+
|
88
|
+
1. Follows the format specified in README.md
|
89
|
+
2. Contains enough participants so that everyone can be matched
|
90
|
+
3. Doesn't have too many blacklisted participants (see "disallow" array in README.md)
|
91
|
+
HEREDOC
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def invalid_hash?
|
97
|
+
@participants.each do |participant|
|
98
|
+
return true unless %i[name number].all? { |k| participant.key? k }
|
99
|
+
end
|
100
|
+
|
101
|
+
false
|
102
|
+
end
|
75
103
|
end
|
data/secretsanta.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secretsanta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty-Lucas Kelley
|
@@ -143,7 +143,6 @@ files:
|
|
143
143
|
- bin/secretsanta
|
144
144
|
- bin/setup
|
145
145
|
- lib/secretsanta.rb
|
146
|
-
- lib/secretsanta/version.rb
|
147
146
|
- secretsanta.gemspec
|
148
147
|
homepage: https://github.com/tylucaskelley/secret-santa
|
149
148
|
licenses:
|