Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/ruql/quiz.rb
Constant Summary collapse
- @@quizzes =
[]
- @@yaml_file =
nil
- @@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
- .get_renderer(renderer) ⇒ Object
- .quiz(*args, &block) ⇒ Object
- .quizzes ⇒ Object
- .set_yaml_file(file) ⇒ Object
Instance Method Summary collapse
-
#choice_answer(*args, &block) ⇒ Object
this should really be done using mixins.
- #dropdown(*args, &block) ⇒ Object
- #fill_in(*args, &block) ⇒ Object
- #get_open_assessment(*args, &block) ⇒ Object
-
#initialize(title, yaml, options = {}) ⇒ Quiz
constructor
A new instance of Quiz.
- #num_questions ⇒ Object
- #open_assessment(*args, &block) ⇒ Object
- #points ⇒ Object
- #random_seed(num) ⇒ Object
- #render_with(renderer, options = {}) ⇒ Object
- #select_multiple(*args, &block) ⇒ Object
- #simple_open_assessment(*args, &block) ⇒ Object
- #truefalse(*args) ⇒ Object
Constructor Details
#initialize(title, yaml, options = {}) ⇒ Quiz
Returns a new instance of Quiz.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruql/quiz.rb', line 32 def initialize(title, yaml, ={}) @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 @quiz_yaml = yaml end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
29 30 31 |
# File 'lib/ruql/quiz.rb', line 29 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/ruql/quiz.rb', line 26 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
27 28 29 |
# File 'lib/ruql/quiz.rb', line 27 def output @output end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
25 26 27 |
# File 'lib/ruql/quiz.rb', line 25 def questions @questions end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
24 25 26 |
# File 'lib/ruql/quiz.rb', line 24 def renderer @renderer end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
28 29 30 |
# File 'lib/ruql/quiz.rb', line 28 def seed @seed end |
#title ⇒ Object
Returns the value of attribute title.
30 31 32 |
# File 'lib/ruql/quiz.rb', line 30 def title @title end |
Class Method Details
.get_renderer(renderer) ⇒ Object
44 45 46 |
# File 'lib/ruql/quiz.rb', line 44 def self.get_renderer(renderer) Object.const_get(renderer.to_s + 'Renderer') rescue nil end |
.quiz(*args, &block) ⇒ Object
132 133 134 135 136 |
# File 'lib/ruql/quiz.rb', line 132 def self.quiz(*args, &block) quiz = Quiz.new(*args, (@@yaml_file.shift if @@yaml_file)) quiz.instance_eval(&block) @@quizzes << quiz end |
.quizzes ⇒ Object
5 |
# File 'lib/ruql/quiz.rb', line 5 def self.quizzes ; @@quizzes ; end |
.set_yaml_file(file) ⇒ Object
55 56 57 |
# File 'lib/ruql/quiz.rb', line 55 def self.set_yaml_file(file) @@yaml_file = file && YAML::load_file(file) end |
Instance Method Details
#choice_answer(*args, &block) ⇒ Object
this should really be done using mixins.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ruql/quiz.rb', line 68 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 |
#dropdown(*args, &block) ⇒ Object
95 96 97 98 99 |
# File 'lib/ruql/quiz.rb', line 95 def dropdown(*args, &block) q = Dropdown.new(*args) q.instance_eval(&block) @questions << q end |
#fill_in(*args, &block) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ruql/quiz.rb', line 121 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 |
#get_open_assessment(*args, &block) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/ruql/quiz.rb', line 112 def get_open_assessment(*args, &block) y = @quiz_yaml.shift raise "Cannot continue - You must have a yaml block for each peer evaluation question" if y.nil? yaml = y[1][0] q = OpenAssessment.new(*args, yaml) q.instance_eval(&block) q end |
#num_questions ⇒ Object
61 |
# File 'lib/ruql/quiz.rb', line 61 def num_questions ; questions.length ; end |
#open_assessment(*args, &block) ⇒ Object
101 102 103 104 |
# File 'lib/ruql/quiz.rb', line 101 def open_assessment(*args, &block) q = get_open_assessment(*args, &block) @questions << q end |
#points ⇒ Object
59 |
# File 'lib/ruql/quiz.rb', line 59 def points ; questions.map(&:points).inject { |sum,points| sum + points } ; end |
#random_seed(num) ⇒ Object
63 64 65 |
# File 'lib/ruql/quiz.rb', line 63 def random_seed(num) @seed = num.to_i end |
#render_with(renderer, options = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ruql/quiz.rb', line 48 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
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruql/quiz.rb', line 79 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 |
#simple_open_assessment(*args, &block) ⇒ Object
106 107 108 109 110 |
# File 'lib/ruql/quiz.rb', line 106 def simple_open_assessment(*args, &block) q = get_open_assessment(*args, &block) q.add_simple_question @questions << q end |