Sha256: 7e4f1cc89bf886f451157c9a74f088963e45392563b6577df5978b3441cebfe4

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require "canvas_qti_to_learnosity_converter/questions/question"

module CanvasQtiToLearnosityConverter
  # This is fill in the blank in the Canvas UI, but it is actually a short
  # answer type.
  class ShortAnswerQuestion < QuizQuestion
    def extract_response_id()
      @xml.css("item > presentation > response_str").attribute("ident").value
    end

    def to_learnosity
      {
        type: "shorttext",
        stimulus: extract_stimulus(),
        validation: extract_validation(),
        response_id: extract_response_id(),
      }
    end

    def extract_validation()
      correct_responses = @xml.css('item > resprocessing >
        respcondition[continue="No"] > conditionvar > varequal')
      correct_response = { "value" => correct_responses.shift.text, "score" => extract_points_possible}
      {
        "scoring_type" => "exactMatch",
        "valid_response" => correct_response,
        "alt_responses" => correct_responses.map { |res| { "value" => res.text, "score" => extract_points_possible } }
      }
    end

    def add_learnosity_assets(assets, path)
      learnosity = to_learnosity
      CanvasQtiToLearnosityConverter.add_files_to_assets(
        assets,
        path + [:stimulus],
        learnosity[:stimulus]
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
canvas_qti_to_learnosity_converter-2.5.0 lib/canvas_qti_to_learnosity_converter/questions/short_answer.rb
canvas_qti_to_learnosity_converter-2.4.1 lib/canvas_qti_to_learnosity_converter/questions/short_answer.rb
canvas_qti_to_learnosity_converter-2.4.0 lib/canvas_qti_to_learnosity_converter/questions/short_answer.rb