Class: Csv2qti::Matching

Inherits:
Question show all
Defined in:
lib/csv2qti/question_types/matching.rb

Constant Summary

Constants inherited from Question

Question::CORRECT, Question::DISTRACTOR_1, Question::DISTRACTOR_2, Question::LICENSE, Question::STEM, Question::TYPE

Instance Attribute Summary collapse

Attributes inherited from Question

#license, #stem

Instance Method Summary collapse

Methods inherited from Question

#add_to_assessment, #add_to_group, generate, #process_distractors, #process_stem, #to_s

Constructor Details

#initialize(row) ⇒ Matching

Returns a new instance of Matching.



6
7
8
9
# File 'lib/csv2qti/question_types/matching.rb', line 6

def initialize(row)
  super(row)
  @answers = process_answers(row[CORRECT])
end

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



4
5
6
# File 'lib/csv2qti/question_types/matching.rb', line 4

def answers
  @answers
end

#distractorsObject (readonly)

Returns the value of attribute distractors.



4
5
6
# File 'lib/csv2qti/question_types/matching.rb', line 4

def distractors
  @distractors
end

Instance Method Details

#generate_cc_questionObject



21
22
23
24
25
26
27
28
29
# File 'lib/csv2qti/question_types/matching.rb', line 21

def generate_cc_question
  question = CanvasCc::CanvasCC::Models::Question.create('matching_question')
  question.identifier = rand(10000)
  question.material = stem
  #question.distractors = %w(distractor1 distractor2)
  question.matches = @answers.map {|a| make_answer(a)}

  question
end

#process_answers(val) ⇒ Object

parse out the matching answers that look like this: “A—Alpha CarbonnB—Amino GroupnC—Carboxyl GroupnD—Hydrogen AtomnE—R Group”



13
14
15
# File 'lib/csv2qti/question_types/matching.rb', line 13

def process_answers(val)
  val.split("\n").map{|m|m.split("")}
end

#to_qtiObject



31
32
33
34
35
# File 'lib/csv2qti/question_types/matching.rb', line 31

def to_qti
  Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |node|
   CanvasCc::CanvasCC::MatchingQuestionWriter.write_question(node, generate_cc_question)
  end.doc.to_xml
end

#typeObject



17
18
19
# File 'lib/csv2qti/question_types/matching.rb', line 17

def type
  'MATCHING'
end