Sha256: 40f355479e9598b9892d85b251cbf4ec4b1f3203d408cab58d3fd80bb2d8458f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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)
      process_assets!(
        assets,
        path,
        learnosity[:stimulus]
      )
      learnosity
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_qti_to_learnosity_converter-3.0.0 lib/canvas_qti_to_learnosity_converter/questions/short_answer.rb