Class: CanvasQtiToLearnosityConverter::CalculatedQuestion

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

Instance Method Summary collapse

Methods inherited from TemplateQuestion

#extract_template, #extract_template_values, #get_template

Methods inherited from QuizQuestion

#convert, #extract_mattext, #extract_points_possible, #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



40
41
42
43
44
45
46
47
# File 'lib/canvas_qti_to_learnosity_converter/questions/calculated.rb', line 40

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

#dynamic_content_dataObject



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

def dynamic_content_data()
  values = extract_dynamic_content_data()

  columns = (0...(values.first.count - 1)).map{ |x| "val#{x}" }
  columns.push("answer")

  rows = Hash[values.map.with_index do |row, index|
    [make_identifier(), { values: row, index: index }]
  end]

  { cols: columns, rows: rows }
end

#extract_dynamic_content_dataObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/canvas_qti_to_learnosity_converter/questions/calculated.rb', line 62

def extract_dynamic_content_data()
  template = get_template()
  vars = extract_template_values(template).map do |var_name|
    @xml.css(%{item > itemproc_extension > calculated > var_sets >
      var_set > var[name="#{var_name}"]}).map { |node| node.text }
  end

  answers = @xml.css("item > itemproc_extension var_sets answer").map do |node|
    node.text
  end

  vars.push(answers).transpose
end

#extract_stimulusObject



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

def extract_stimulus()
  template = get_template()
  extract_template_values(template).each.with_index do |var_name, index|
    template.sub!("[#{var_name}]", "{{var:val#{index}}}")
  end

  template
end

#extract_validationObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/canvas_qti_to_learnosity_converter/questions/calculated.rb', line 24

def extract_validation()
  pm = @xml.css("item > itemproc_extension > calculated > answer_tolerance")
    .first.text

  {
    "scoring_type" => "exactMatch",
    "valid_response" => {
      "score" => extract_points_possible,
      "value" => [[{
        "method" => "equivValue",
        "value" => "{{var:answer}}\\pm#{pm}"
      }]]
    }
  }
end

#to_learnosityObject



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

def to_learnosity
  {
    type: "clozeformula",
    is_math: true,
    stimulus: extract_stimulus(),
    template: "{{response}}",
    validation: extract_validation(),
  }
end