Class: Senkyoshi::JumbledSentence

Inherits:
Question show all
Defined in:
lib/senkyoshi/models/questions/jumbled_sentence.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

#_find_directories, #_fix_path, #_matches_directory_xid?, #_search_and_replace, #cleanup, #fix_html, get_pre_data, #matches_xid?, #strip_xid

Constructor Details

#initializeJumbledSentence

Returns a new instance of JumbledSentence.



20
21
22
23
# File 'lib/senkyoshi/models/questions/jumbled_sentence.rb', line 20

def initialize
  @responses = []
  super
end

Instance Method Details

#canvas_conversion(assessment, _resources = nil) ⇒ Object



49
50
51
52
# File 'lib/senkyoshi/models/questions/jumbled_sentence.rb', line 49

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

#iterate_xml(data) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/senkyoshi/models/questions/jumbled_sentence.rb', line 25

def iterate_xml(data)
  super
  if response_block = data.at("flow[@class=RESPONSE_BLOCK]")
    choices = []
    response_block.at("flow_label").children.each do |response|
      text = response.at("mattext").text
      choices << { id: response.attributes["ident"], text: text }
    end
    set_answers(data.at("resprocessing"))
    correct = data.at("respcondition[title=correct]")
    correct.at("and").children.each do |answer_element|
      id = answer_element.text
      response_label = data.at("response_label[ident='#{id}']")
      answer_text = response_label.at("mattext").text
      answer = Answer.new(answer_text, id)
      resp_ident = answer_element.attributes["respident"].value
      answer.resp_ident = resp_ident
      @responses << { id: resp_ident, choices: choices }
      @answers.push(answer)
    end
  end
  self
end