Class: Csv2qti::Matching
- 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
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
-
#distractors ⇒ Object
readonly
Returns the value of attribute distractors.
Attributes inherited from Question
Instance Method Summary collapse
- #generate_cc_question ⇒ Object
-
#initialize(row) ⇒ Matching
constructor
A new instance of Matching.
-
#process_answers(val) ⇒ Object
parse out the matching answers that look like this: “A—Alpha CarbonnB—Amino GroupnC—Carboxyl GroupnD—Hydrogen AtomnE—R Group”.
- #to_qti ⇒ Object
- #type ⇒ Object
Methods inherited from Question
#add_to_assessment, #add_to_group, generate, #process_distractors, #process_stem, #to_s
Constructor Details
Instance Attribute Details
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
4 5 6 |
# File 'lib/csv2qti/question_types/matching.rb', line 4 def answers @answers end |
#distractors ⇒ Object (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_question ⇒ Object
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_qti ⇒ Object
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 |
#type ⇒ Object
17 18 19 |
# File 'lib/csv2qti/question_types/matching.rb', line 17 def type 'MATCHING' end |