Module: EasyRr

Defined in:
lib/easy_rr.rb,
lib/easy_rr/version.rb

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.matches(participants, *facingMatches) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/easy_rr.rb', line 4

def self.matches(participants,*facingMatches)

	if participants.class != Array
participants = participants.to_a
	end

  fMatches = !facingMatches[0].nil? ? facingMatches[0] : 1

  if participants.size%2 != 0
  	participants.push nil
  end

  length = participants.size
  last_e = participants.pop

  matches = ( ( ( fMatches*length )/2 ) + fMatches ).times.map do
    participants.rotate!
    [[participants.first, last_e]] + (1...(length / 2)).map { |j| [participants[j], participants[length - 1 - j]] }
  end

  unless last_e.nil?
  	participants.push last_e
  end
  
  return matches
end