Class: QuickExam::Record
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#correct_indexes ⇒ Object
Returns the value of attribute correct_indexes.
-
#question ⇒ Object
Returns the value of attribute question.
Instance Method Summary collapse
- #answers_with_hash ⇒ Object
-
#initialize(question: '', answers: [], correct_indexes: []) ⇒ Record
constructor
A new instance of Record.
- #shuffle_answers ⇒ Object
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
#answers ⇒ Object
Returns the value of attribute answers.
3 4 5 |
# File 'lib/quick_exam/record.rb', line 3 def answers @answers end |
#correct_indexes ⇒ Object
Returns the value of attribute correct_indexes.
3 4 5 |
# File 'lib/quick_exam/record.rb', line 3 def correct_indexes @correct_indexes end |
#question ⇒ Object
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_hash ⇒ Object
11 12 13 |
# File 'lib/quick_exam/record.rb', line 11 def answers_with_hash answers.map.with_index.to_h.invert end |
#shuffle_answers ⇒ Object
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 |