class Question
Attributes
answers[RW]
name[RW]
points[RW]
question_comment[RW]
question_group[RW]
question_text[RW]
randomize[RW]
uid[RW]
Public Class Methods
new(*args)
click to toggle source
# File lib/ruql/question.rb, line 4 def initialize(*args) options = if args[-1].kind_of?(Hash) then args[-1] else {} end @answers = options[:answers] || [] @points = [options[:points].to_i, 1].max @raw = options[:raw] @name = options[:name] @question_tags = [] @question_group = '' @question_comment = '' end
Public Instance Methods
answer(text, opts={})
click to toggle source
# File lib/ruql/question.rb, line 38 def answer(text, opts={}) @answers << Answer.new(text, correct=true, opts[:explanation]) end
as_json()
click to toggle source
# File lib/ruql/question.rb, line 15 def as_json Hash( :question_text => @question_text, :question_tags => @question_tags.compact, :question_group => @question_group, :answers => @answers.map(&:as_json), :question_type => self.class.to_s, :raw => !!@raw, :name => @name, :points => @points ).compact end
comment(str = '')
click to toggle source
# File lib/ruql/question.rb, line 59 def comment(str = '') @question_comment = str.to_s end
correct_answer()
click to toggle source
# File lib/ruql/question.rb, line 63 def correct_answer ; @answers.detect(&:correct?) ; end
correct_answers()
click to toggle source
# File lib/ruql/question.rb, line 65 def correct_answers ; @answers.collect(&:correct?) ; end
distractor(text, opts={})
click to toggle source
# File lib/ruql/question.rb, line 42 def distractor(text, opts={}) @answers << Answer.new(text, correct=false, opts[:explanation]) end
explanation(text)
click to toggle source
# File lib/ruql/question.rb, line 34 def explanation(text) @answers.each { |answer| answer.explanation ||= text } end
group(str)
click to toggle source
# File lib/ruql/question.rb, line 46 def group(str) @question_group = str end
raw?()
click to toggle source
# File lib/ruql/question.rb, line 30 def raw? ; !!@raw ; end
text(s)
click to toggle source
# File lib/ruql/question.rb, line 32 def text(s) ; @question_text = s ; end