class Quiz

Attributes

logger[R]
options[R]
output[R]
questions[R]
renderer[R]
seed[R]
title[RW]

Public Class Methods

get_renderer(renderer) click to toggle source
# File lib/ruql/quiz.rb, line 42
def self.get_renderer(renderer)
  Object.const_get(renderer.to_s + 'Renderer') rescue nil
end
new(title, options={}) click to toggle source
# File lib/ruql/quiz.rb, line 31
def initialize(title, options={})
  @output = ''
  @questions = options[:questions] || []
  @title = title
  @options = @@default_options.merge(options)
  @seed = srand
  @logger = Logger.new(STDERR)
  @logger.level = Logger.const_get (options.delete('l') ||
    options.delete('log') || 'warn').upcase
end
quiz(*args,&block) click to toggle source
# File lib/ruql/quiz.rb, line 100
def self.quiz(*args,&block)
  quiz = Quiz.new(*args)
  quiz.instance_eval(&block)
  @@quizzes << quiz
end
quizzes() click to toggle source
# File lib/ruql/quiz.rb, line 4
def self.quizzes ; @@quizzes ;  end

Public Instance Methods

choice_answer(*args, &block) click to toggle source

this should really be done using mixins.

# File lib/ruql/quiz.rb, line 62
def choice_answer(*args, &block)
  if args.first.is_a?(Hash) # no question text
    q = MultipleChoice.new('',*args)
  else
    text = args.shift
    q = MultipleChoice.new(text, *args)
  end
  q.instance_eval(&block)
  @questions << q
end
fill_in(*args, &block) click to toggle source
# File lib/ruql/quiz.rb, line 89
def fill_in(*args, &block)
  if args.first.is_a?(Hash) # no question text
    q = FillIn.new('', *args)
  else
    text = args.shift
    q = FillIn.new(text, *args)
  end
  q.instance_eval(&block)
  @questions << q
end
num_questions() click to toggle source
# File lib/ruql/quiz.rb, line 55
def num_questions ; questions.length ; end
points() click to toggle source
# File lib/ruql/quiz.rb, line 53
def points ; questions.map(&:points).inject { |sum,points| sum + points } ; end
random_seed(num) click to toggle source
# File lib/ruql/quiz.rb, line 57
def random_seed(num)
  @seed = num.to_i
end
render_with(renderer,options={}) click to toggle source
# File lib/ruql/quiz.rb, line 46
def render_with(renderer,options={})
  srand @seed
  @renderer = Quiz.get_renderer(renderer).send(:new,self,options)
  @renderer.render_quiz
  @output = @renderer.output
end
select_multiple(*args, &block) click to toggle source
# File lib/ruql/quiz.rb, line 73
def select_multiple(*args, &block)
  if args.first.is_a?(Hash) # no question text
    q = SelectMultiple.new('',*args)
  else
    text = args.shift
    q = SelectMultiple.new(text, *args)
  end
  q.instance_eval(&block)
  @questions << q
end
truefalse(*args) click to toggle source
# File lib/ruql/quiz.rb, line 84
def truefalse(*args)
  q = TrueFalse.new(*args)
  @questions << q
end