Class: Moodle2CC::CanvasCC::MatchingQuestionWriter

Inherits:
QuestionWriter show all
Defined in:
lib/moodle2cc/canvas_cc/matching_question_writer.rb

Class Method Summary collapse

Methods inherited from QuestionWriter

convert_fraction_to_score, register_writer_type, write_general_feedback, write_presentation, write_qti_metadata, write_question, write_question_item_xml, write_resprocessing, write_standard_answer_feedbacks

Class Method Details

.write_additional_nodes(item_node, question) ⇒ Object



40
41
# File 'lib/moodle2cc/canvas_cc/matching_question_writer.rb', line 40

def self.write_additional_nodes(item_node, question)
end

.write_response_conditions(processing_node, question) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/moodle2cc/canvas_cc/matching_question_writer.rb', line 27

def self.write_response_conditions(processing_node, question)
  real_matches = question.matches.select{|m| m[:question_text].length > 0}
  score = 100.0 / real_matches.length.to_i
  real_matches.each do |match|
    processing_node.respcondition do |condition_node|
      condition_node.conditionvar do |var_node|
        var_node.varequal match[:id], :respident => "response_#{match[:id]}"
      end
      condition_node.setvar "%.2f" % score, :varname => 'SCORE', :action => 'Add'
    end
  end
end

.write_responses(presentation_node, question) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/moodle2cc/canvas_cc/matching_question_writer.rb', line 7

def self.write_responses(presentation_node, question)
  question.matches.each do |match|
    presentation_node.response_lid(:ident => "response_#{match[:id]}") do |response_node|
      next unless match[:question_text].length > 0
      response_node.material do |material_node|
        material_node.mattext(match[:question_text], :texttype => 'text/plain')
      end
      response_node.render_choice do |choice_node|
        question.matches.each do |possible_match|
          choice_node.response_label(:ident => possible_match[:id]) do |label_node|
            label_node.material do |material_node|
              material_node.mattext(possible_match[:answer_text], :texttype => 'text/plain')
            end
          end
        end
      end
    end
  end
end