Class: EdXmlRenderer
- Inherits:
-
Object
- Object
- EdXmlRenderer
- Defined in:
- lib/ruql/renderers/edxml_renderer.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(quiz, options = {}) ⇒ EdXmlRenderer
constructor
A new instance of EdXmlRenderer.
- #render(thing) ⇒ Object
- #render_fill_in(question) ⇒ Object
- #render_multiple_choice(question) ⇒ Object
- #render_quiz ⇒ Object
Constructor Details
#initialize(quiz, options = {}) ⇒ EdXmlRenderer
Returns a new instance of EdXmlRenderer.
5 6 7 8 9 10 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 5 def initialize(quiz,={}) @only_question = .delete('n') || .delete('name') @output = '' @b = Builder::XmlMarkup.new(:target => @output, :indent => 2) @quiz = quiz end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
4 5 6 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 4 def output @output end |
Instance Method Details
#render(thing) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 12 def render(thing) case thing when MultipleChoice,SelectMultiple,TrueFalse then render_multiple_choice(thing) when FillIn then render_fill_in(thing) else raise "Unknown question type: #{thing}" end end |
#render_fill_in(question) ⇒ Object
32 33 34 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 32 def render_fill_in(question) raise "Not yet implemented for edXML" end |
#render_multiple_choice(question) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 36 def render_multiple_choice(question) @b.problem do # if question text has explicit newlines, use them to separate <p>'s if question.raw? @b.p { |p| p << question.question_text } else question.question_text.lines.map(&:chomp).each do |line| if question.raw? then @b.p { |p| p << line } else @b.p(line) end end end @b.multiplechoiceresponse do @b.choicegroup :type => 'MultipleChoice' do question.answers.each do |answer| if question.raw? @b.choice(:correct => answer.correct?) do |choice| choice << answer.answer_text choice << "\n" end else @b.choice answer.answer_text, :correct => answer.correct? end end end end @b.solution do @b.div :class => 'detailed_solution' do @b.p 'Explanation' if question.raw? @b.p { |p| p << question.correct_answer.explanation } else @b.p question.correct_answer.explanation end end end end end |
#render_quiz ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruql/renderers/edxml_renderer.rb', line 21 def render_quiz # entire quiz can be in one question group, as long as we specify # that ALL question from the group must be used to make the quiz. question_list = if @only_question then @quiz.questions.select { |q| q.name == @only_question } else @quiz.questions end question_list.each { |question| render(question) } @output end |