Class: Rubin
- Inherits:
-
Array
- Object
- Array
- Rubin
- Defined in:
- lib/rubin.rb
Instance Method Summary collapse
Instance Method Details
#each_matchup ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/rubin.rb', line 2 def each_matchup members = self.dup members << nil if members.size.odd? rounds = members.size - 1 1.upto(rounds) do |round| pairing(members) do |home, away| yield [home, away, round] end members = spin(members) end end |
#output(v = 'v') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubin.rb', line 14 def output(v='v') rounds = Hash.new { |hash, key| hash[key] = [] } each_matchup do |home, away, round| if home && away rounds[round] << "#{home} #{v} #{away}" end end output = [] rounds = rounds.sort_by { |round, v| round } rounds.each do |round, pairs| output << "Round #{round}" pairs.each do |pair| output << pair end output << "\n" end output.join("\n") end |