class NerdQuiz::Scorecard
Constants
- RIGHT
- WRONG
Attributes
answers[R]
Public Class Methods
new(possible=NerdQuiz::DEFAULT_NUMBER_OF_QUESTIONS)
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 8 def initialize(possible=NerdQuiz::DEFAULT_NUMBER_OF_QUESTIONS) @answers = [].fill(nil, 0, possible) end
Public Instance Methods
incomplete?()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 16 def incomplete? !next_question.nil? end
next_question()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 12 def next_question @answers.index(nil) end
right_answer!()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 20 def right_answer! update RIGHT end
score()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 28 def score "#{correct}/#{total}" end
wrong_answer!()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 24 def wrong_answer! update WRONG end
Private Instance Methods
correct()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 37 def correct @answers.select{|i| i == RIGHT}.length end
total()
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 41 def total @total ||= @answers.length end
update(answer)
click to toggle source
# File lib/nerd_quiz/scorecard.rb, line 33 def update(answer) @answers[next_question] = answer end