Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/ruql/quiz.rb
Constant Summary collapse
- @@quizzes =
[]
- @@default_options =
{ :open_time => Time.now, :soft_close_time => Time.now + 24*60*60, :hard_close_time => Time.now + 24*60*60, :maximum_submissions => 1, :duration => 3600, :retry_delay => 600, :parameters => { :show_explanations => { :question => 'before_soft_close_time', :option => 'before_soft_close_time', :score => 'before_soft_close_time', } }, :maximum_score => 1, }
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#questions ⇒ Object
readonly
Returns the value of attribute questions.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#choice_answer(*args, &block) ⇒ Object
this should really be done using mixins.
- #fill_in(*args, &block) ⇒ Object
-
#initialize(title, options = {}) ⇒ Quiz
constructor
A new instance of Quiz.
- #num_questions ⇒ Object
- #points ⇒ Object
- #random_seed(num) ⇒ Object
- #render_with(renderer, options = {}) ⇒ Object
- #select_multiple(*args, &block) ⇒ Object
- #truefalse(*args) ⇒ Object
Constructor Details
#initialize(title, options = {}) ⇒ Quiz
Returns a new instance of Quiz.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruql/quiz.rb', line 31 def initialize(title, ={}) @output = '' @questions = [:questions] || [] @title = title @options = @@default_options.merge() @seed = srand @logger = Logger.new(STDERR) @logger.level = Logger.const_get (.delete('l') || .delete('log') || 'warn').upcase end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/ruql/quiz.rb', line 28 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/ruql/quiz.rb', line 25 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
26 27 28 |
# File 'lib/ruql/quiz.rb', line 26 def output @output end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
24 25 26 |
# File 'lib/ruql/quiz.rb', line 24 def questions @questions end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
23 24 25 |
# File 'lib/ruql/quiz.rb', line 23 def renderer @renderer end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
27 28 29 |
# File 'lib/ruql/quiz.rb', line 27 def seed @seed end |
#title ⇒ Object
Returns the value of attribute title.
29 30 31 |
# File 'lib/ruql/quiz.rb', line 29 def title @title end |
Class Method Details
.get_renderer(renderer) ⇒ Object
42 43 44 |
# File 'lib/ruql/quiz.rb', line 42 def self.get_renderer(renderer) Object.const_get(renderer.to_s + 'Renderer') rescue nil end |
.quiz(*args, &block) ⇒ Object
100 101 102 103 104 |
# File 'lib/ruql/quiz.rb', line 100 def self.quiz(*args,&block) quiz = Quiz.new(*args) quiz.instance_eval(&block) @@quizzes << quiz end |
.quizzes ⇒ Object
4 |
# File 'lib/ruql/quiz.rb', line 4 def self.quizzes ; @@quizzes ; end |
Instance Method Details
#choice_answer(*args, &block) ⇒ Object
this should really be done using mixins.
62 63 64 65 66 67 68 69 70 71 |
# 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) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# 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 ⇒ Object
55 |
# File 'lib/ruql/quiz.rb', line 55 def num_questions ; questions.length ; end |
#points ⇒ Object
53 |
# File 'lib/ruql/quiz.rb', line 53 def points ; questions.map(&:points).inject { |sum,points| sum + points } ; end |
#random_seed(num) ⇒ Object
57 58 59 |
# File 'lib/ruql/quiz.rb', line 57 def random_seed(num) @seed = num.to_i end |
#render_with(renderer, options = {}) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ruql/quiz.rb', line 46 def render_with(renderer,={}) srand @seed @renderer = Quiz.get_renderer(renderer).send(:new,self,) @renderer.render_quiz @output = @renderer.output end |
#select_multiple(*args, &block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# 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 |