Class: Quiz
- Inherits:
-
Object
- Object
- Quiz
- Defined in:
- lib/ruql/quiz.rb
Constant Summary collapse
- @@quizzes =
[]
- @@options =
{}
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
- .options ⇒ Object
- .quiz(title, args = {}, &block) ⇒ Object
- .quizzes ⇒ Object
- .reset ⇒ Object
- .set_options(options) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#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
- #grouped_points ⇒ Object
- #grouped_questions ⇒ Object
- #groups ⇒ Object
-
#initialize(title, 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
- #ungrouped_points ⇒ Object
- #ungrouped_questions ⇒ Object
Constructor Details
#initialize(title, options = {}) ⇒ Quiz
Returns a new instance of Quiz.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruql/quiz.rb', line 20 def initialize(title, ={}) @output = '' @questions = [:questions] || [] @title = title @options = @@options.merge() @seed = srand @logger = Logger.new(STDERR) @logger.level = (@options['-V'] || @options['--verbose']) ? Logger::INFO : Logger::WARN #@quiz_yaml = yaml end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/ruql/quiz.rb', line 10 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/ruql/quiz.rb', line 7 def @options end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/ruql/quiz.rb', line 8 def output @output end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
6 7 8 |
# File 'lib/ruql/quiz.rb', line 6 def questions @questions end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
5 6 7 |
# File 'lib/ruql/quiz.rb', line 5 def renderer @renderer end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed.
9 10 11 |
# File 'lib/ruql/quiz.rb', line 9 def seed @seed end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/ruql/quiz.rb', line 11 def title @title end |
Class Method Details
.options ⇒ Object
18 |
# File 'lib/ruql/quiz.rb', line 18 def self. ; @@options ; end |
.quiz(title, args = {}, &block) ⇒ Object
147 148 149 150 151 |
# File 'lib/ruql/quiz.rb', line 147 def self.quiz(title, args={}, &block) quiz = Quiz.new(title, args) quiz.instance_eval(&block) @@quizzes << quiz end |
.quizzes ⇒ Object
17 |
# File 'lib/ruql/quiz.rb', line 17 def self.quizzes ; @@quizzes ; end |
.reset ⇒ Object
13 14 15 16 |
# File 'lib/ruql/quiz.rb', line 13 def self.reset @@quizzes = [] @@options = {} end |
.set_options(options) ⇒ Object
45 46 47 |
# File 'lib/ruql/quiz.rb', line 45 def self.() @@options = end |
Instance Method Details
#as_json ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ruql/quiz.rb', line 31 def as_json Hash(:title => @title, :questions => @questions.map(&:as_json), :seed => @seed ) end |
#choice_answer(*args, &block) ⇒ Object
this should really be done using mixins.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruql/quiz.rb', line 83 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
110 111 112 113 114 |
# File 'lib/ruql/quiz.rb', line 110 def dropdown(*args, &block) q = Dropdown.new(*args) q.instance_eval(&block) @questions << q end |
#fill_in(*args, &block) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruql/quiz.rb', line 136 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
127 128 129 130 131 132 133 134 |
# File 'lib/ruql/quiz.rb', line 127 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 |
#grouped_points ⇒ Object
63 64 65 66 67 68 |
# File 'lib/ruql/quiz.rb', line 63 def grouped_points gq = grouped_questions groups.sum do |g| gq.detect { |q| q.question_group == g }.points end end |
#grouped_questions ⇒ Object
53 54 55 |
# File 'lib/ruql/quiz.rb', line 53 def grouped_questions questions.filter { |q| q.question_group.to_s != '' }.sort_by(&:question_group) end |
#groups ⇒ Object
57 |
# File 'lib/ruql/quiz.rb', line 57 def groups ; questions.map(&:question_group).uniq.reject { |g| g.to_s == '' } ; end |
#num_questions ⇒ Object
74 75 76 |
# File 'lib/ruql/quiz.rb', line 74 def num_questions groups.length + ungrouped_questions.length end |
#open_assessment(*args, &block) ⇒ Object
116 117 118 119 |
# File 'lib/ruql/quiz.rb', line 116 def open_assessment(*args, &block) q = get_open_assessment(*args, &block) @questions << q end |
#points ⇒ Object
70 71 72 |
# File 'lib/ruql/quiz.rb', line 70 def points ungrouped_points + grouped_points end |
#random_seed(num) ⇒ Object
78 79 80 |
# File 'lib/ruql/quiz.rb', line 78 def random_seed(num) @seed = num.to_i end |
#render_with(renderer, options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/ruql/quiz.rb', line 38 def render_with(renderer,={}) srand @seed @renderer = renderer.send(:new,self,) @renderer.render_quiz @output = @renderer.output end |
#select_multiple(*args, &block) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ruql/quiz.rb', line 94 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
121 122 123 124 125 |
# File 'lib/ruql/quiz.rb', line 121 def simple_open_assessment(*args, &block) q = get_open_assessment(*args, &block) q.add_simple_question @questions << q end |
#truefalse(*args) ⇒ Object
105 106 107 108 |
# File 'lib/ruql/quiz.rb', line 105 def truefalse(*args) q = TrueFalse.new(*args) @questions << q end |
#ungrouped_points ⇒ Object
59 60 61 |
# File 'lib/ruql/quiz.rb', line 59 def ungrouped_points ungrouped_questions.map(&:points).sum end |
#ungrouped_questions ⇒ Object
49 50 51 |
# File 'lib/ruql/quiz.rb', line 49 def ungrouped_questions questions.filter { |q| q.question_group.to_s == '' } end |