rubin 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -8
- data/Rakefile +17 -9
- data/VERSION +1 -1
- data/lib/rubin.rb +35 -29
- data/spec/rubin_spec.rb +17 -3
- data/spec/spec_helper.rb +4 -5
- metadata +9 -12
- data/spec/spec.opts +0 -1
data/README.rdoc
CHANGED
@@ -6,21 +6,27 @@ Round Robin Generator
|
|
6
6
|
|
7
7
|
require 'rubin'
|
8
8
|
|
9
|
-
teams =
|
10
|
-
teams.
|
9
|
+
teams = Rubin.new(['England', 'France', 'Italy', 'Spain'])
|
10
|
+
teams.each_matchup do |home, away, round_num|
|
11
|
+
# do something here
|
12
|
+
end
|
11
13
|
|
12
|
-
#
|
14
|
+
# Rubin#output will print out the matchups
|
15
|
+
puts teams.output # =>
|
13
16
|
Round 1
|
14
|
-
|
15
|
-
France v
|
17
|
+
England v Italy
|
18
|
+
France v France
|
19
|
+
|
16
20
|
|
17
21
|
Round 2
|
18
|
-
France v
|
19
|
-
Italy v
|
22
|
+
France v England
|
23
|
+
Italy v France
|
24
|
+
|
20
25
|
|
21
26
|
Round 3
|
22
27
|
Italy v France
|
23
|
-
|
28
|
+
England v France
|
29
|
+
|
24
30
|
|
25
31
|
== Note on Patches/Pull Requests
|
26
32
|
|
data/Rakefile
CHANGED
@@ -6,27 +6,35 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "rubin"
|
8
8
|
gem.summary = "Round Robin Generator"
|
9
|
-
gem.description = "Round Robin Generator"
|
9
|
+
gem.description = "Round Robin Generator. Woot!"
|
10
10
|
gem.email = "rit@quietdynamite.com"
|
11
11
|
gem.homepage = "http://github.com/rit/rubin"
|
12
12
|
gem.authors = ["Rit Li"]
|
13
|
-
gem.add_development_dependency "
|
13
|
+
gem.add_development_dependency "bacon", ">= 0"
|
14
14
|
end
|
15
15
|
Jeweler::GemcutterTasks.new
|
16
16
|
rescue LoadError
|
17
17
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
18
|
end
|
19
19
|
|
20
|
-
require '
|
21
|
-
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:spec) do |spec|
|
22
22
|
spec.libs << 'lib' << 'spec'
|
23
|
-
spec.
|
23
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
24
|
+
spec.verbose = true
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |spec|
|
30
|
+
spec.libs << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
task :spec => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rubin.rb
CHANGED
@@ -1,44 +1,50 @@
|
|
1
|
-
|
2
|
-
def
|
1
|
+
class Rubin < Array
|
2
|
+
def each_matchup
|
3
3
|
members = self.dup
|
4
4
|
members << nil if members.size.odd?
|
5
5
|
rounds = members.size - 1
|
6
6
|
1.upto(rounds) do |round|
|
7
|
-
members
|
8
|
-
yield [
|
7
|
+
pairing(members) do |home, away|
|
8
|
+
yield [home, away, round]
|
9
9
|
end
|
10
|
-
members
|
10
|
+
members = spin(members)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def _pairing
|
23
|
-
members = self.dup
|
24
|
-
count = members.size/2
|
25
|
-
0.upto(count-1) do |i|
|
26
|
-
yield [members[i], members[i+count]]
|
14
|
+
def output(v='v')
|
15
|
+
rounds = Hash.new { |hash, key| hash[key] = [] }
|
16
|
+
each_matchup do |home, away, round|
|
17
|
+
if home && away
|
18
|
+
rounds[round] << "#{home} #{v} #{away}"
|
19
|
+
end
|
27
20
|
end
|
28
|
-
end
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
output = []
|
23
|
+
rounds = rounds.sort_by { |round, v| round }
|
24
|
+
rounds.each do |round, pairs|
|
25
|
+
output << "Round #{round}"
|
26
|
+
pairs.each do |pair|
|
27
|
+
output << pair
|
36
28
|
end
|
37
|
-
|
29
|
+
output << "\n"
|
38
30
|
end
|
31
|
+
output.join("\n")
|
39
32
|
end
|
40
|
-
end
|
41
33
|
|
42
|
-
|
43
|
-
|
34
|
+
private
|
35
|
+
def spin(members)
|
36
|
+
# 1 4 2 1
|
37
|
+
# 2 5 => 3 4
|
38
|
+
# 3 6 5 6
|
39
|
+
#
|
40
|
+
# 6 is fixed
|
41
|
+
members.insert(members.size/2-1, members.delete_at(-2), members.shift)
|
42
|
+
end
|
43
|
+
|
44
|
+
def pairing(members)
|
45
|
+
count = members.size/2
|
46
|
+
0.upto(count-1) do |i|
|
47
|
+
yield [members[i], members[i+count]]
|
48
|
+
end
|
49
|
+
end
|
44
50
|
end
|
data/spec/rubin_spec.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Rubin" do
|
4
|
-
it "
|
3
|
+
describe "Rubin#each_matchup" do
|
4
|
+
it "should yields home, away, and round number" do
|
5
|
+
teams = Rubin.new(['England', 'France'])
|
6
|
+
teams.each_matchup do |home, away, round|
|
7
|
+
home.should == 'England'
|
8
|
+
away.should == 'France'
|
9
|
+
round.should == 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Rubin#output" do
|
15
|
+
it "should display all matchups" do
|
16
|
+
teams = Rubin.new(['England', 'France'])
|
17
|
+
teams.output.should == "Round 1\nEngland v France\n\n"
|
18
|
+
end
|
5
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bacon'
|
3
|
+
|
1
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
6
|
require 'rubin'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
8
|
+
Bacon.summary_on_exit
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rit Li
|
@@ -15,26 +15,24 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-15 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: bacon
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 3
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
33
|
-
- 9
|
34
|
-
version: 1.2.9
|
31
|
+
- 0
|
32
|
+
version: "0"
|
35
33
|
type: :development
|
36
34
|
version_requirements: *id001
|
37
|
-
description: Round Robin Generator
|
35
|
+
description: Round Robin Generator. Woot!
|
38
36
|
email: rit@quietdynamite.com
|
39
37
|
executables: []
|
40
38
|
|
@@ -52,7 +50,6 @@ files:
|
|
52
50
|
- VERSION
|
53
51
|
- lib/rubin.rb
|
54
52
|
- spec/rubin_spec.rb
|
55
|
-
- spec/spec.opts
|
56
53
|
- spec/spec_helper.rb
|
57
54
|
has_rdoc: true
|
58
55
|
homepage: http://github.com/rit/rubin
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|