Class: CanvasQtiToLearnosityConverter::FillTheBlanksQuestion

Inherits:
TemplateQuestion show all
Defined in:
lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb

Instance Method Summary collapse

Methods inherited from TemplateQuestion

#extract_template, #extract_template_values, #get_template

Methods inherited from QuizQuestion

#convert, #dynamic_content_data, #extract_mattext, #extract_points_possible, #extract_stimulus, #initialize, #make_identifier, #process_assets!

Constructor Details

This class inherits a constructor from CanvasQtiToLearnosityConverter::QuizQuestion

Instance Method Details

#add_learnosity_assets(assets, path, learnosity) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb', line 14

def add_learnosity_assets(assets, path, learnosity)
  process_assets!(
    assets,
    path,
    learnosity[:template]
  )
  learnosity
end

#create_responses(blank_responses, depth, result, current_response) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb', line 51

def create_responses(blank_responses, depth, result, current_response)
  if depth == blank_responses.count
    result.push({ "score" => extract_points_possible, "value" => current_response })
    return
  end

  blank_responses[depth].each do |possible_response|
    create_responses(blank_responses, depth + 1, result, current_response + [possible_response])
  end
end

#extract_validationObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb', line 23

def extract_validation()
  template = get_template()

  responses = extract_template_values(template).map do |name|
    result = @xml.css(%{item > presentation >
      response_lid[ident="response_#{name}"] > render_choice material >
      mattext}).map do |node|
      extract_mattext(node)
    end

    if result.empty?
      nil
    else
      result
    end
  end.compact

  all_responses = []
  create_responses(responses, 0, all_responses, [])

  {
    "scoring_type" => "partialMatchV2",
    "rounding" => "none",
    "valid_response" => all_responses.shift,
    "alt_responses" => all_responses
  }
end

#to_learnosityObject



5
6
7
8
9
10
11
12
# File 'lib/canvas_qti_to_learnosity_converter/questions/fill_the_blanks.rb', line 5

def to_learnosity
  {
    type: "clozetext",
    stimulus: "",
    template: extract_template(),
    validation: extract_validation(),
  }
end