Class: StudentRandomizer
- Inherits:
-
Object
- Object
- StudentRandomizer
- Defined in:
- lib/student_randomizer.rb
Instance Method Summary collapse
- #choose_by_number(number, articles) ⇒ Object
- #choose_by_string(string, articles) ⇒ Object
- #choose_totally_random(articles) ⇒ Object
- #chosen_student(random_index) ⇒ Object
-
#initialize(mentor_group) ⇒ StudentRandomizer
constructor
A new instance of StudentRandomizer.
- #output_students(random_generator, articles) ⇒ Object
Constructor Details
#initialize(mentor_group) ⇒ StudentRandomizer
3 4 5 6 7 |
# File 'lib/student_randomizer.rb', line 3 def initialize(mentor_group) @mentor_group = mentor_group @group_size = @mentor_group.members.length @chosen_students = [] end |
Instance Method Details
#choose_by_number(number, articles) ⇒ Object
9 10 11 12 |
# File 'lib/student_randomizer.rb', line 9 def choose_by_number(number, articles) random_generator = Random.new(number) output_students(random_generator, articles) end |
#choose_by_string(string, articles) ⇒ Object
14 15 16 17 18 |
# File 'lib/student_randomizer.rb', line 14 def choose_by_string(string, articles) seed_number = string.sum random_generator = Random.new(seed_number) output_students(random_generator, articles) end |
#choose_totally_random(articles) ⇒ Object
20 21 22 23 |
# File 'lib/student_randomizer.rb', line 20 def choose_totally_random(articles) random_generator = Random.new output_students(random_generator, articles) end |
#chosen_student(random_index) ⇒ Object
41 42 43 |
# File 'lib/student_randomizer.rb', line 41 def chosen_student(random_index) @mentor_group.members[random_index] end |
#output_students(random_generator, articles) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/student_randomizer.rb', line 25 def output_students(random_generator, articles) articles.times do random_index = random_generator.rand(0...@group_size) student = chosen_student(random_index) while @chosen_students.include?(student) if @chosen_students.length == articles @chosen_students = [] end random_index = random_generator.rand(0...@group_size) student = chosen_student(random_index) end puts student.name @chosen_students << student end end |