Class: CLI::Quizzer
- Inherits:
-
Object
- Object
- CLI::Quizzer
- Defined in:
- lib/forgetful/cli/quizzer.rb
Instance Attribute Summary collapse
-
#questionaire ⇒ Object
readonly
Returns the value of attribute questionaire.
Instance Method Summary collapse
-
#initialize(questionaire) ⇒ Quizzer
constructor
A new instance of Quizzer.
- #quiz ⇒ Object
Constructor Details
#initialize(questionaire) ⇒ Quizzer
Returns a new instance of Quizzer.
5 6 7 |
# File 'lib/forgetful/cli/quizzer.rb', line 5 def initialize(questionaire) @questionaire = questionaire end |
Instance Attribute Details
#questionaire ⇒ Object (readonly)
Returns the value of attribute questionaire.
3 4 5 |
# File 'lib/forgetful/cli/quizzer.rb', line 3 def questionaire @questionaire end |
Instance Method Details
#quiz ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/forgetful/cli/quizzer.rb', line 9 def quiz results = [] questions = questionaire.questions.sort_by { rand } begin questions.each_with_index do |question, i| q = ask(question, i+1, questions.size) results << [question[:id], q] end rescue EOFError # tolerate Ctrl-D, skips the rest of the quiz end questionaire.grade(results) end |