class QuickExam::Record
Attributes
answers[RW]
correct_indexes[RW]
question[RW]
Public Class Methods
new(question: '', answers: [], correct_indexes: [])
click to toggle source
# File lib/quick_exam/record.rb, line 5 def initialize(question: '', answers: [], correct_indexes: []) @question = question @answers = answers @correct_indexes = correct_indexes end
Public Instance Methods
answers_with_hash()
click to toggle source
# File lib/quick_exam/record.rb, line 11 def answers_with_hash answers.map.with_index.to_h.invert end
shuffle_answers()
click to toggle source
# File lib/quick_exam/record.rb, line 15 def shuffle_answers ans = answers_with_hash.sort{|a, b| rand(40) <=> rand(40) }.to_h self.answers = ans.values self.correct_indexes = specific_index_correct_answer(ans) end
Private Instance Methods
specific_index_correct_answer(data_hash)
click to toggle source
# File lib/quick_exam/record.rb, line 23 def specific_index_correct_answer(data_hash) correct_indexes.each_with_object([]) do |i, indexes| indexes << data_hash.find_index { |key, _| key == i } end.sort end