rubolph 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26d7f5705fd5f780010057dd8cb12e6ff8e941ea
4
+ data.tar.gz: 8d3e6e0e6a64afa4f159f0059a638bf49a09abff
5
+ SHA512:
6
+ metadata.gz: 0c4d8aa4c83fae076e53c26b14a736d4110d3318fcea35c23a432429695313a484cd8d317c4ec18b5e43cfc035c1dfc02e0715e927d08b5f60006e2c3c2f14aa
7
+ data.tar.gz: 200f954c61a32a3b2aef5892e1f3491bef39faa39511a3788f11641fa132540c8fda4b9f076059b28ab45faa8fbecba4f4041eead75cbaab582829760c579905
data/lib/rubolph.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubolph/version'
2
+ require 'rubolph/picker'
3
+ require 'rubolph/packager'
@@ -0,0 +1,17 @@
1
+ module Rubolph
2
+ class Packager
3
+
4
+ def initialize(results)
5
+ @results = results
6
+ end
7
+
8
+ def package
9
+ @results.each do |giver, receiver|
10
+ open("./output/#{giver}.txt", 'w') do |f|
11
+ f.puts "Hello #{giver.capitalize}. For Christmas 2015, you're buying a present for #{receiver.capitalize}."
12
+ end
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module Rubolph
2
+ class Picker
3
+
4
+ def initialize(participants, exclusions={})
5
+ @participants = participants
6
+ @exclusions = exclusions
7
+ @results = {}
8
+ end
9
+
10
+
11
+ def pick
12
+ @iteration = 0
13
+ loop do
14
+ @results = { }
15
+ receivers = @participants.shuffle
16
+ @participants.each do |giver|
17
+ @results[giver] = receivers.delete(receivers.sample)
18
+ end
19
+
20
+ valid = true
21
+ @results.each do |giver, receiver|
22
+ if giver == receiver || @exclusions[giver] == receiver
23
+ valid = false
24
+ break
25
+ end
26
+ end
27
+ break if valid
28
+
29
+ @iteration += 1 and handle_irreconcilable
30
+ end
31
+ @results
32
+ end
33
+
34
+ private
35
+ def handle_irreconcilable
36
+ if @iteration > 10000
37
+ raise ArgumentError.new 'Unable to reconcile participants with exclusions!'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Rubolph
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubolph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Liggat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fuubar
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A rubygem to assist in picking secret santa assignments
112
+ email:
113
+ - dave@liggat.org
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/rubolph.rb
119
+ - lib/rubolph/packager.rb
120
+ - lib/rubolph/picker.rb
121
+ - lib/rubolph/version.rb
122
+ homepage: https://liggat.org
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A gem for generating secret santa assignments
146
+ test_files: []