class Generator::NNumberOfGroups

Attributes

final_groups[RW]
number_of_groups[RW]
students[RW]
students_per_group[RW]

Public Class Methods

new(students:, number_of_groups:) click to toggle source
# File lib/learn_party/generator.rb, line 94
def initialize(students:, number_of_groups:)
  @students = students
  @number_of_groups = number_of_groups
  @final_groups = []
end

Public Instance Methods

adjust_distribution() click to toggle source
# File lib/learn_party/generator.rb, line 116
def adjust_distribution
  if final_groups.last.size < students_per_group && final_groups.length > number_of_groups
    final_groups.pop.each_with_index do |remaining_student, i|
      final_groups[i] << remaining_student
    end
  end
end
make_groups() click to toggle source
# File lib/learn_party/generator.rb, line 100
def make_groups
  make_initial_distribution
  adjust_distribution
  final_groups
end
make_initial_distribution() click to toggle source
# File lib/learn_party/generator.rb, line 110
def make_initial_distribution
  students.each_slice(students_per_group) do |slice|
    final_groups  << slice
  end
end