class Senkyoshi::Question

Constants

ITEM_FUNCTION
QUESTION_TYPE

Attributes

answers[R]

Public Class Methods

from(item) click to toggle source
# File lib/senkyoshi/models/question.rb, line 63
def self.from(item)
  type = item.at("bbmd_questiontype").children.text
  item_class = Senkyoshi.const_get ITEM_FUNCTION[type]
  question = item_class.new
  question.iterate_xml(item)
end
new() click to toggle source
# File lib/senkyoshi/models/question.rb, line 70
def initialize
  @original_identifier = ""
  @question = nil
  @question_type = ""
  @points_possible = ""
  @title = "Question"
  @material = ""
  @answers = []
  @general_feedback = ""
  @general_correct_feedback = ""
  @general_incorrect_feedback = ""
  @blackboard_type = ""
  @correct_answers = {}
  @incorrect_answers = {}
  @max_score = 1
end

Public Instance Methods

canvas_conversion(_, resources) click to toggle source
# File lib/senkyoshi/models/question.rb, line 99
def canvas_conversion(_, resources)
  @question.identifier = Senkyoshi.create_random_hex
  @question.title = @title
  @question.original_identifier = @original_identifier
  @question.points_possible = @points_possible
  @question.material = fix_html(@material, resources)
  @question.general_feedback = fix_html(@general_feedback, resources)
  @general_correct_feedback =
    fix_html(@general_correct_feedback, resources)
  @question.general_correct_feedback = @general_correct_feedback
  @general_incorrect_feedback =
    fix_html(@general_incorrect_feedback, resources)
  @question.general_incorrect_feedback = @general_incorrect_feedback
  @question.answers = []
  @answers.each do |answer|
    @question = answer.canvas_conversion(@question, resources)
  end
  @question
end
get_fraction(answer_text) click to toggle source
# File lib/senkyoshi/models/question.rb, line 119
def get_fraction(answer_text)
  if @correct_answers && answer_text.to_s == @correct_answers["name"].to_s
    @correct_answers["fraction"].to_f
  else
    @incorrect_answers["fraction"].to_f
  end
end
iterate_item(data) click to toggle source
# File lib/senkyoshi/models/question.rb, line 165
def iterate_item(data)
  @general_correct_feedback = set_feedback(data, "correct")
  @general_incorrect_feedback = set_feedback(data, "incorrect")
  @material = set_material(data)
  resprocessing = data.at("resprocessing")
  @max_score = set_max_score(resprocessing)
end
iterate_xml(data) click to toggle source
# File lib/senkyoshi/models/question.rb, line 87
def iterate_xml(data)
  @original_identifier = data.at("bbmd_asi_object_id").text
  @blackboard_type = data.at("bbmd_questiontype").text
  @question_type = QUESTION_TYPE[@blackboard_type]
  @question = CanvasCc::CanvasCC::Models::Question.create(@question_type)
  @points_possible = data.at("qmd_absolutescore_max").text
  title = data.attributes["title"]
  @title = title ? title.value : ""
  iterate_item(data)
  self
end
set_answers(resprocessing) click to toggle source
# File lib/senkyoshi/models/question.rb, line 127
def set_answers(resprocessing)
  set_correct_answers(resprocessing)
  set_incorrect_answers(resprocessing)
end
set_correct_answers(resprocessing) click to toggle source
# File lib/senkyoshi/models/question.rb, line 132
def set_correct_answers(resprocessing)
  correct = resprocessing.at("respcondition[title=correct]")
  if correct
    if correct.at("varequal")
      @correct_answers["name"] = correct.at("varequal").text
    end
    score = correct.at("setvar") ? correct.at("setvar").text : 0
    score_number = score == "SCORE.max" ? @max_score.to_f : score.to_f
    if score_number > 0
      @correct_answers["fraction"] = score_number.to_f / @max_score.to_f
    else
      # mark as correct when there is no score for the answer
      @correct_answers["fraction"] = 1
    end
  end
end
set_feedback(data, type) click to toggle source
# File lib/senkyoshi/models/question.rb, line 173
def set_feedback(data, type)
  feedback = data.at("itemfeedback[ident=#{type}]")
  if feedback && feedback.at("mat_formattedtext")
    feedback.at("mat_formattedtext").text
  else
    ""
  end
end
set_incorrect_answers(resprocessing) click to toggle source
# File lib/senkyoshi/models/question.rb, line 149
def set_incorrect_answers(resprocessing)
  incorrect = resprocessing.at("respcondition[title=incorrect]")
  if incorrect
    if incorrect.at("varequal")
      @incorrect_answers["name"] = incorrect.at("varequal").text
    end
    score = incorrect.at("setvar") ? incorrect.at("setvar").text : 0
    score_number = score == "SCORE.max" ? @max_score.to_f : score.to_f
    if score_number > 0
      @incorrect_answers["fraction"] = score_number.to_f / @max_score.to_f
    else
      @incorrect_answers["fraction"] = 0
    end
  end
end
set_material(data) click to toggle source
# File lib/senkyoshi/models/question.rb, line 182
def set_material(data)
  if (question_block = data.at("flow[@class=QUESTION_BLOCK]"))
    question_block.at("mat_formattedtext").text
  else
    ""
  end
end
set_max_score(resprocessing) click to toggle source
# File lib/senkyoshi/models/question.rb, line 190
def set_max_score(resprocessing)
  no_score = "0.0"
  outcomes = resprocessing.at("outcomes")
  if outcomes && !outcomes.at("decvar").nil?
    if outcomes.at("decvar").attributes["maxvalue"]
      outcomes.at("decvar").attributes["maxvalue"].value
    else
      no_score
    end
  else
    no_score
  end
end