Class: Senkyoshi::MultipleAnswer
- Defined in:
- lib/senkyoshi/models/questions/multiple_answer.rb
Constant Summary
Constants inherited from Question
Question::ITEM_FUNCTION, Question::QUESTION_TYPE
Instance Attribute Summary
Attributes inherited from Question
Instance Method Summary collapse
- #iterate_xml(data) ⇒ Object
- #set_answers(resprocessing) ⇒ Object
- #set_correct_answer(resprocessing) ⇒ Object
- #set_incorrect_answer(resprocessing) ⇒ Object
Methods inherited from Question
#canvas_conversion, from, #get_fraction, #initialize, #iterate_item, #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
This class inherits a constructor from Senkyoshi::Question
Instance Method Details
#iterate_xml(data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/senkyoshi/models/questions/multiple_answer.rb', line 20 def iterate_xml(data) super if response_block = data.at("flow[@class=RESPONSE_BLOCK]") set_answers(data.at("resprocessing")) response_block.at("render_choice").children.each do |choice| id = choice.at("response_label").attributes["ident"].value @answer_text = choice.at("mat_formattedtext").text answer = Answer.new(@answer_text, id) answer.fraction = get_fraction(id) @answers.push(answer) end end self end |
#set_answers(resprocessing) ⇒ Object
35 36 37 38 |
# File 'lib/senkyoshi/models/questions/multiple_answer.rb', line 35 def set_answers(resprocessing) @correct_answers = set_correct_answer(resprocessing) @incorrect_answers = set_incorrect_answer(resprocessing) end |
#set_correct_answer(resprocessing) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/senkyoshi/models/questions/multiple_answer.rb', line 40 def set_correct_answer(resprocessing) correct_answers = {} correct = resprocessing.at("respcondition[title=correct]") if correct correct.at("and").children.each do |answer| if answer.name == "varequal" id = answer.text correct_answers[id] = {} correct_answers[id]["name"] = id if correct.at("setvar") score = correct.at("setvar").text score_number = score == "SCORE.max" ? @max_score.to_f : score.to_f correct_answers[id]["fraction"] = score_number else correct_answers[id]["fraction"] = 0 end end end end correct_answers end |
#set_incorrect_answer(resprocessing) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/senkyoshi/models/questions/multiple_answer.rb', line 62 def set_incorrect_answer(resprocessing) incorrect = resprocessing.at("respcondition[ident=incorrect]") incorrect_answers = {} if incorrect && incorrect.at("setvar") incorrect_answers["fraction"] = incorrect.at("setvar").text else incorrect_answers["fraction"] = 0 end incorrect_answers end |