swissper 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d81d7fa6507c58f7f020445f7e88e23bab3c558
4
- data.tar.gz: 37f688e1ca9b4f8deda36870af6bb8f9bfbbfab3
3
+ metadata.gz: 472c0070be8d6f75e08bdacb6b93886408bda5fd
4
+ data.tar.gz: be5dd1b4d7c781faa1ba395b35a65b5d982e0e05
5
5
  SHA512:
6
- metadata.gz: 8815a39e425d0a75758f5915cfef36f9366b2c45f38668d7232d00aa7a16108093591ad60ab049546b7430f2373d281b821c627a3cde33b2601596072a16826a
7
- data.tar.gz: 96bde4fbacf0deacff2e1a29d4da8abf9990f426a1f31739c77289a3360450b0ea18123a097cce1a7f490f22a0cee054d2804226ee49a373b9f78dcf39676a31
6
+ metadata.gz: de53e20408c56dbe56d59e2d1b8a450bd76c0815f02d141869b705ded29f5f58fa26a8d80b3cc2e341debeeaebac730b2c455aab7fda1323794acb4931ddf564
7
+ data.tar.gz: 52424d4134fdeaa160d7797cbde272b7033ed2bb9461206d1c525573069534af0459b2ccb896b40b9e45669d3b95557a090bc3f0eebc2ab7792a78595ec0fef3
data/.gitignore CHANGED
@@ -8,5 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
 
11
+ *.gem
12
+
11
13
  # rspec failure tracking
12
14
  .rspec_status
data/README.md CHANGED
@@ -19,6 +19,7 @@ Or install it yourself as:
19
19
  $ gem install swissper
20
20
 
21
21
  ## Usage
22
+
22
23
  Use `Swissper.pair(players, options)` where `players` is an array of objects, and `options` is an optional hash of options.
23
24
 
24
25
  The `player` objects you pass can be any type of object you like, so long as there are no duplicates. There is a simple `Swissper::Player` class available for ease of use.
@@ -92,6 +93,29 @@ Swissper.pair(players, exclude_key: :previous_opponents)
92
93
  # Player objects should respond to `previous_opponents`
93
94
  ```
94
95
 
96
+ ## Byes
97
+
98
+ If your array of players contains an odd number, one player will be paired with the `Swissper::Bye` class.
99
+
100
+ You can prevent players from receiving byes (e.g. if they've already received one) by passing `Swissper::Bye` in the `exclude` parameter of any player.
101
+
102
+ ```ruby
103
+ snap = Swissper::Player.new
104
+ crackle = Swissper::Player.new
105
+ pop = Swissper::Player.new
106
+
107
+ snap.exclude = [Swissper::Bye]
108
+ crackle.exclude = [Swissper::Bye]
109
+
110
+ Swissper.pair([snap, crackle, pop])
111
+ # [
112
+ # [Swissper::Bye, #<Swissper::Player:0x007fb2f99cb838 @delta=0, @exclude=[]>],
113
+ # [#<Swissper::Player:0x007fb2f9accac0 @delta=0, @exclude=[Swissper::Bye]>, #<Swissper::Player:0x007fb2f91a8f98 @delta=0, @exclude=[Swissper::Bye]>]
114
+ # ]
115
+ ```
116
+
117
+ Please don't manually pass in `Swissper::Bye` in your array of players, passing in an odd-length array is the correct way to use byes.
118
+
95
119
  ## Development
96
120
 
97
121
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,4 @@
1
+ module Swissper
2
+ class Bye
3
+ end
4
+ end
@@ -1,3 +1,3 @@
1
1
  module Swissper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/swissper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'swissper/version'
2
2
  require 'swissper/player'
3
+ require 'swissper/bye'
3
4
  require 'graph_matching'
4
5
 
5
6
  module Swissper
@@ -14,7 +15,7 @@ module Swissper
14
15
  end
15
16
 
16
17
  def pair(player_data)
17
- @players = player_data.shuffle
18
+ @player_data = player_data
18
19
  graph.maximum_weighted_matching(true).edges.map do |pairing|
19
20
  [players[pairing[0]], players[pairing[1]]]
20
21
  end
@@ -22,7 +23,7 @@ module Swissper
22
23
 
23
24
  private
24
25
 
25
- attr_reader :delta_key, :exclude_key, :players
26
+ attr_reader :delta_key, :exclude_key
26
27
 
27
28
  def graph
28
29
  edges = [].tap do |e|
@@ -58,5 +59,11 @@ module Swissper
58
59
 
59
60
  []
60
61
  end
62
+
63
+ def players
64
+ @players ||= @player_data.clone.tap do |data|
65
+ data << Swissper::Bye unless data.length.even?
66
+ end.shuffle
67
+ end
61
68
  end
62
69
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swissper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John O'Brien
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graph_matching
@@ -97,8 +97,10 @@ files:
97
97
  - bin/console
98
98
  - bin/setup
99
99
  - lib/swissper.rb
100
+ - lib/swissper/bye.rb
100
101
  - lib/swissper/player.rb
101
102
  - lib/swissper/version.rb
103
+ - swissper-0.1.0.gem
102
104
  - swissper.gemspec
103
105
  homepage: https://github.com/muyjohno/swissper
104
106
  licenses:
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  version: '0'
121
123
  requirements: []
122
124
  rubyforge_project:
123
- rubygems_version: 2.4.5.1
125
+ rubygems_version: 2.6.10
124
126
  signing_key:
125
127
  specification_version: 4
126
128
  summary: A Ruby gem for pairing Swiss tournaments