Class: QuickExam::Record

Inherits:
Object show all
Defined in:
lib/quick_exam/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(question: '', answers: [], correct_indexes: []) ⇒ Record

Returns a new instance of Record.



5
6
7
8
9
# File 'lib/quick_exam/record.rb', line 5

def initialize(question: '', answers: [], correct_indexes: [])
  @question = question
  @answers = answers
  @correct_indexes = correct_indexes
end

Instance Attribute Details

#answersObject

Returns the value of attribute answers.



3
4
5
# File 'lib/quick_exam/record.rb', line 3

def answers
  @answers
end

#correct_indexesObject

Returns the value of attribute correct_indexes.



3
4
5
# File 'lib/quick_exam/record.rb', line 3

def correct_indexes
  @correct_indexes
end

#questionObject

Returns the value of attribute question.



3
4
5
# File 'lib/quick_exam/record.rb', line 3

def question
  @question
end

Instance Method Details

#answers_with_hashObject



11
12
13
# File 'lib/quick_exam/record.rb', line 11

def answers_with_hash
  answers.map.with_index.to_h.invert
end

#shuffle_answersObject



15
16
17
18
19
# 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