Class: EenieMeenie::Sorters::RoundRobin

Inherits:
Base
  • Object
show all
Defined in:
lib/eenie_meenie/sorters/round_robin.rb

Instance Method Summary collapse

Methods inherited from Base

#load_option, #load_options

Constructor Details

#initialize(*args, options) ⇒ RoundRobin

Returns a new instance of RoundRobin.



4
5
6
# File 'lib/eenie_meenie/sorters/round_robin.rb', line 4

def initialize(*args, options)
  load_options(:groups, :population, options)
end

Instance Method Details

#sortObject



8
9
10
11
12
13
14
15
16
# File 'lib/eenie_meenie/sorters/round_robin.rb', line 8

def sort
  results = {}
  @groups.each { |group| results.merge!(group => 0) }
  @population.times do |i|
    results[@groups[i % @groups.length]] += 1
  end

  groups = results
end