class QuickExam::RecordCollection
Attributes
records[R]
Public Class Methods
new(records = [])
click to toggle source
# File lib/quick_exam/record_collection.rb, line 5 def initialize(records = []) @records = records end
Public Instance Methods
mixes(count, shuffle_question: true, shuffle_answer: false, same_answer: false)
click to toggle source
# File lib/quick_exam/record_collection.rb, line 9 def mixes(count, shuffle_question: true, shuffle_answer: false, same_answer: false) @records = self @same_answer = same_answer return records if count.zero? count.times.each_with_object([]) do |_, memo| new_records = records.dup new_records.shuffle! if shuffle_question shuffle_answers(new_records) if shuffle_answer memo << new_records end end
Private Instance Methods
shuffle_answers(array_records)
click to toggle source
# File lib/quick_exam/record_collection.rb, line 23 def shuffle_answers(array_records) array_records.each_with_index do |obj, i| # Todo: The same answer for all questionnaires # obj.dup => difference, otherwise n_obj = @same_answer ? obj : obj.dup n_obj.shuffle_answers array_records[i] = n_obj end end