Class: Generator::GroupsOfNStudents
- Inherits:
-
Object
- Object
- Generator::GroupsOfNStudents
- Defined in:
- lib/learn_together/generator.rb
Instance Attribute Summary collapse
-
#final_groups ⇒ Object
Returns the value of attribute final_groups.
-
#groups_of ⇒ Object
Returns the value of attribute groups_of.
-
#number_of_groups ⇒ Object
Returns the value of attribute number_of_groups.
-
#sort_type ⇒ Object
Returns the value of attribute sort_type.
-
#students ⇒ Object
Returns the value of attribute students.
Instance Method Summary collapse
- #check_student_distribution ⇒ Object
- #form_progress_based_groups ⇒ Object
- #form_random_groups ⇒ Object
-
#initialize(students:, groups_of:, sort_type:) ⇒ GroupsOfNStudents
constructor
A new instance of GroupsOfNStudents.
- #leftover_students ⇒ Object
- #leftover_students? ⇒ Boolean
- #make_groups ⇒ Object
- #sort_by_progress? ⇒ Boolean
- #sort_by_random? ⇒ Boolean
Constructor Details
#initialize(students:, groups_of:, sort_type:) ⇒ GroupsOfNStudents
Returns a new instance of GroupsOfNStudents.
32 33 34 35 36 37 |
# File 'lib/learn_together/generator.rb', line 32 def initialize(students:, groups_of:, sort_type:) @students = students @groups_of = groups_of @sort_type = sort_type @final_groups = [] end |
Instance Attribute Details
#final_groups ⇒ Object
Returns the value of attribute final_groups.
30 31 32 |
# File 'lib/learn_together/generator.rb', line 30 def final_groups @final_groups end |
#groups_of ⇒ Object
Returns the value of attribute groups_of.
30 31 32 |
# File 'lib/learn_together/generator.rb', line 30 def groups_of @groups_of end |
#number_of_groups ⇒ Object
Returns the value of attribute number_of_groups.
30 31 32 |
# File 'lib/learn_together/generator.rb', line 30 def number_of_groups @number_of_groups end |
#sort_type ⇒ Object
Returns the value of attribute sort_type.
30 31 32 |
# File 'lib/learn_together/generator.rb', line 30 def sort_type @sort_type end |
#students ⇒ Object
Returns the value of attribute students.
30 31 32 |
# File 'lib/learn_together/generator.rb', line 30 def students @students end |
Instance Method Details
#check_student_distribution ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/learn_together/generator.rb', line 68 def check_student_distribution if leftover_students? leftover_val = students.length % groups_of.to_i if leftover_val == 1 student = final_groups.pop.first final_groups.last << student elsif leftover_val == groups_of.to_i / 2 final_groups.pop.each_with_index do |student, i| final_groups["-#{i + 1}".to_i] << student end end else end end |
#form_progress_based_groups ⇒ Object
63 64 65 66 |
# File 'lib/learn_together/generator.rb', line 63 def form_progress_based_groups students.sort_by {|s| s.completed_lesson_count_for_active_track}.each_slice(groups_of.to_i) { |students| final_groups << students } check_student_distribution end |
#form_random_groups ⇒ Object
58 59 60 61 |
# File 'lib/learn_together/generator.rb', line 58 def form_random_groups students.shuffle.each_slice(groups_of.to_i) { |students| final_groups << students } check_student_distribution end |
#leftover_students ⇒ Object
87 88 89 |
# File 'lib/learn_together/generator.rb', line 87 def leftover_students students.length % groups_of.to_i <= (groups_of.to_i - 2) || students.length % groups_of.to_i == 1 end |
#leftover_students? ⇒ Boolean
83 84 85 |
# File 'lib/learn_together/generator.rb', line 83 def leftover_students? students.length % groups_of.to_i > 0 end |
#make_groups ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/learn_together/generator.rb', line 40 def make_groups if sort_by_random? form_random_groups elsif sort_by_progress? form_progress_based_groups end final_groups end |
#sort_by_progress? ⇒ Boolean
54 55 56 |
# File 'lib/learn_together/generator.rb', line 54 def sort_by_progress? sort_type == "progress" end |
#sort_by_random? ⇒ Boolean
50 51 52 |
# File 'lib/learn_together/generator.rb', line 50 def sort_by_random? sort_type == "random" end |