Class: Generator::NNumberOfGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_together/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(students:, number_of_groups:) ⇒ NNumberOfGroups

Returns a new instance of NNumberOfGroups.



95
96
97
98
99
# File 'lib/learn_together/generator.rb', line 95

def initialize(students:, number_of_groups:)
  @students = students
  @number_of_groups = number_of_groups
  @final_groups = []
end

Instance Attribute Details

#final_groupsObject

Returns the value of attribute final_groups.



93
94
95
# File 'lib/learn_together/generator.rb', line 93

def final_groups
  @final_groups
end

#number_of_groupsObject

Returns the value of attribute number_of_groups.



93
94
95
# File 'lib/learn_together/generator.rb', line 93

def number_of_groups
  @number_of_groups
end

#studentsObject

Returns the value of attribute students.



93
94
95
# File 'lib/learn_together/generator.rb', line 93

def students
  @students
end

#students_per_groupObject

Returns the value of attribute students_per_group.



93
94
95
# File 'lib/learn_together/generator.rb', line 93

def students_per_group
  @students_per_group
end

Instance Method Details

#adjust_distributionObject



117
118
119
120
121
122
123
# File 'lib/learn_together/generator.rb', line 117

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_groupsObject



101
102
103
104
105
# File 'lib/learn_together/generator.rb', line 101

def make_groups
  make_initial_distribution
  adjust_distribution
  final_groups
end

#make_initial_distributionObject



111
112
113
114
115
# File 'lib/learn_together/generator.rb', line 111

def make_initial_distribution
  students.each_slice(students_per_group) do |slice|
    final_groups  << slice
  end
end