class StudentRandomizer

Public Class Methods

new(mentor_group) click to toggle source
# File lib/student_randomizer.rb, line 3
def initialize(mentor_group)
  @mentor_group = mentor_group
  @group_size = @mentor_group.members.length
  @chosen_students = []
end

Public Instance Methods

choose_by_number(number, articles) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/student_randomizer.rb, line 41
def chosen_student(random_index)
  @mentor_group.members[random_index]
end
output_students(random_generator, articles) click to toggle source
# 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