Class: Senkyoshi::Matching
- Defined in:
- lib/senkyoshi/models/questions/matching.rb
Constant Summary collapse
- TAGS_PATTERN =
Regexp.union( /<\/?p[^>]*>/i, # <p> tags /<\/?b[^>]*>/i, # <b> tags /<\/?strong[^>]*>/i, # <strong> tags /<\/?em[^>]*>/i, # <em> tags /<\/?span[^>]*>/i, # <span> tags /<\/?font[^>]*>/i, # <font> tags /<\/?i(?!mg)[^>]*>/i, # <i> tags, no <img> / style=("|')[^"']*("|')/i, # inline styles )
Constants inherited from Question
Question::ITEM_FUNCTION, Question::QUESTION_TYPE
Instance Attribute Summary
Attributes inherited from Question
Instance Method Summary collapse
- #canvas_conversion(assessment, resources) ⇒ Object
-
#initialize ⇒ Matching
constructor
A new instance of Matching.
- #iterate_xml(data) ⇒ Object
- #set_matching_answers(resprocessing) ⇒ Object
- #strip_select_html(text) ⇒ Object
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
#initialize ⇒ Matching
Returns a new instance of Matching.
16 17 18 19 20 21 |
# File 'lib/senkyoshi/models/questions/matching.rb', line 16 def initialize super @matches = [] @matching_answers = {} @distractors = [] end |
Instance Method Details
#canvas_conversion(assessment, resources) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/senkyoshi/models/questions/matching.rb', line 61 def canvas_conversion(assessment, resources) @matches.each do |match| match[:question_text] = fix_html(match[:question_text], resources) match[:answer_text] = fix_html(match[:answer_text], resources) end @question.matches = @matches @question.distractors = @distractors super end |
#iterate_xml(data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/senkyoshi/models/questions/matching.rb', line 27 def iterate_xml(data) super resprocessing = data.at("resprocessing") @matching_answers = set_matching_answers(resprocessing) matches_array = [] answers = [] if match_block = data.at("flow[@class=RIGHT_MATCH_BLOCK]") matches_array = match_block. search("flow[@class=FORMATTED_TEXT_BLOCK]"). map { |match| strip_select_html(match.text) } end if response_block = data.at("flow[@class=RESPONSE_BLOCK]") response_block.children.each do |response| id = response.at("response_lid").attributes["ident"].value question = response.at("mat_formattedtext").text answer_id = @matching_answers[id] answer = "" flow_label = response.at("flow_label") flow_label.children.each_with_index do |label, index| if label.attributes["ident"].value == answer_id answer = matches_array[index] end end answers << answer @matches << { id: id, question_text: question, answer_text: answer } end end @distractors = matches_array.reject { |i| answers.include?(i) } self end |
#set_matching_answers(resprocessing) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/senkyoshi/models/questions/matching.rb', line 72 def set_matching_answers(resprocessing) matching_answers = {} respcondition = resprocessing.css("respcondition") respcondition.each do |condition| if condition.attributes["title"] != "incorrect" varequal = condition.at("varequal") if varequal id = varequal.attributes["respident"].value matching_answers[id] = varequal.text end end end matching_answers end |
#strip_select_html(text) ⇒ Object
23 24 25 |
# File 'lib/senkyoshi/models/questions/matching.rb', line 23 def strip_select_html(text) text.gsub(TAGS_PATTERN, "") end |