Class: Senkyoshi::Ordering

Inherits:
Question show all
Defined in:
lib/senkyoshi/models/questions/ordering.rb

Constant Summary

Constants inherited from Question

Question::ITEM_FUNCTION, Question::QUESTION_TYPE

Instance Attribute Summary

Attributes inherited from Question

#answers

Instance Method Summary collapse

Methods inherited from Question

from, #get_fraction, #iterate_item, #set_answers, #set_correct_answers, #set_feedback, #set_incorrect_answers, #set_material, #set_max_score

Methods inherited from Resource

#_search_and_replace, #cleanup, #fix_html, #matches_xid?

Constructor Details

#initializeOrdering

Returns a new instance of Ordering.



5
6
7
8
9
# File 'lib/senkyoshi/models/questions/ordering.rb', line 5

def initialize
  super
  @matches = []
  @order_answers = {}
end

Instance Method Details

#canvas_conversion(assessment, _resources = nil) ⇒ Object



27
28
29
30
# File 'lib/senkyoshi/models/questions/ordering.rb', line 27

def canvas_conversion(assessment, _resources = nil)
  @question.matches = @matches
  super
end

#iterate_xml(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/senkyoshi/models/questions/ordering.rb', line 11

def iterate_xml(data)
  super
  resprocessing = data.at("resprocessing")
  @order_answers = set_order_answers(resprocessing)
  if response_block = data.at("flow[@class=RESPONSE_BLOCK]")
    response_block.at("render_choice").children.each do |choice|
      id = choice.at("response_label").attributes["ident"].value
      question = @order_answers[id].to_s
      answer = choice.at("mat_formattedtext").text
      @matches << { id: id, question_text: question, answer_text: answer }
    end
    @matches = @matches.sort_by { |hsh| hsh[:question_text] }
  end
  self
end

#set_order_answers(resprocessing) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/senkyoshi/models/questions/ordering.rb', line 32

def set_order_answers(resprocessing)
  order_answers = {}
  correct = resprocessing.at("respcondition[title=correct]")
  correct.at("and").children.each_with_index do |varequal, index|
    id = varequal.text
    order_answers[id] = index + 1
  end
  order_answers
end