Class: Generator::NNumberOfGroups
- Inherits:
-
Object
- Object
- Generator::NNumberOfGroups
- Defined in:
- lib/learn_party/generator.rb
Instance Attribute Summary collapse
-
#final_groups ⇒ Object
Returns the value of attribute final_groups.
-
#number_of_groups ⇒ Object
Returns the value of attribute number_of_groups.
-
#students ⇒ Object
Returns the value of attribute students.
-
#students_per_group ⇒ Object
Returns the value of attribute students_per_group.
Instance Method Summary collapse
- #adjust_distribution ⇒ Object
-
#initialize(students:, number_of_groups:) ⇒ NNumberOfGroups
constructor
A new instance of NNumberOfGroups.
- #make_groups ⇒ Object
- #make_initial_distribution ⇒ Object
Constructor Details
#initialize(students:, number_of_groups:) ⇒ NNumberOfGroups
Returns a new instance of NNumberOfGroups.
94 95 96 97 98 |
# 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 |
Instance Attribute Details
#final_groups ⇒ Object
Returns the value of attribute final_groups.
92 93 94 |
# File 'lib/learn_party/generator.rb', line 92 def final_groups @final_groups end |
#number_of_groups ⇒ Object
Returns the value of attribute number_of_groups.
92 93 94 |
# File 'lib/learn_party/generator.rb', line 92 def number_of_groups @number_of_groups end |
#students ⇒ Object
Returns the value of attribute students.
92 93 94 |
# File 'lib/learn_party/generator.rb', line 92 def students @students end |
#students_per_group ⇒ Object
Returns the value of attribute students_per_group.
92 93 94 |
# File 'lib/learn_party/generator.rb', line 92 def students_per_group @students_per_group end |
Instance Method Details
#adjust_distribution ⇒ Object
116 117 118 119 120 121 122 |
# 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 ⇒ Object
100 101 102 103 104 |
# File 'lib/learn_party/generator.rb', line 100 def make_groups make_initial_distribution adjust_distribution final_groups end |
#make_initial_distribution ⇒ Object
110 111 112 113 114 |
# 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 |