class Scores
Attributes
scores[RW]
Public Class Methods
new(quiz, assesment)
click to toggle source
# File lib/quizzer.rb, line 141 def initialize(quiz, assesment) @scores = Hash.new assesment.items.each do |i_id, i| s = Score.new(i_id) quiz.questions.each do |q_id, q| case q.type when 'truefalse' then if q.correct == i.answers[q_id].value s.value += q.value_ok else s.value += q.value_failed end when 'multichoice' then s.value += q.alternatives[i.answers[q_id].value].value else raise 'Incomplete question' end end @scores[i_id] = s end end
Public Instance Methods
serialize()
click to toggle source
# File lib/quizzer.rb, line 172 def serialize() output = { "scores" => Array.new } @scores.each do |s_id, s| output["scores"].push({ "studentId" => s_id, "value" => s.value }) end JSON.pretty_generate(output) end
test(another)
click to toggle source
# File lib/quizzer.rb, line 163 def test(another) s_test = Hash.new another["scores"].each do |s| s_test[s["studentId"]] = Score.new(s["studentId"], s["value"]) end @scores == s_test end