Class: Qti::V1::Models::AssessmentItem

Inherits:
Base show all
Defined in:
lib/qti/v1/models/assessment_item.rb

Constant Summary

Constants inherited from Models::Base

Models::Base::ELEMENTS_REMAP

Instance Attribute Summary collapse

Attributes inherited from Models::Base

#manifest, #package_root, #path

Instance Method Summary collapse

Methods inherited from Base

#qti_version, #return_inner_content!

Methods inherited from Models::Base

#css_with_single_check, from_path!, #object_tag_transformer, #parse_html, #parse_xml, #preprocess_xml_doc, #remap_href_path, #remap_unknown_tags_transformer, #sanitize_config, #sanitize_content!, #xpath_with_single_check

Constructor Details

#initialize(item, package_root = nil) ⇒ AssessmentItem

Returns a new instance of AssessmentItem.



10
11
12
13
14
# File 'lib/qti/v1/models/assessment_item.rb', line 10

def initialize(item, package_root = nil)
  @doc = item
  @path = item.document.url
  self.package_root = package_root
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



8
9
10
# File 'lib/qti/v1/models/assessment_item.rb', line 8

def doc
  @doc
end

Instance Method Details

#decvar_maxvalueObject



66
67
68
69
# File 'lib/qti/v1/models/assessment_item.rb', line 66

def decvar_maxvalue
  @doc.at_xpath('.//xmlns:decvar/@maxvalue')&.value&.to_i ||
    @doc.at_xpath('.//xmlns:decvar/@defaultval')&.value&.to_i || 0
end

#feedbackObject



85
86
87
# File 'lib/qti/v1/models/assessment_item.rb', line 85

def feedback
  @feedback ||= interaction_model.canvas_item_feedback
end

#has_points_possible_qti_metadata?Boolean

Deprecated.

Please use #points_possible_qti_metadata? instead

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/qti/v1/models/assessment_item.rb', line 48

def has_points_possible_qti_metadata? # rubocop:disable Naming/PredicateName
  warn "DEPRECATED: '#{__method__}' is renamed to 'points_possible_qti_metadata?'."
  points_possible_qti_metadata?
end

#identifierObject



26
27
28
# File 'lib/qti/v1/models/assessment_item.rb', line 26

def identifier
  @identifier ||= @doc.attribute('ident').value
end

#interaction_modelObject



75
76
77
78
79
# File 'lib/qti/v1/models/assessment_item.rb', line 75

def interaction_model
  @interaction_model ||= begin
    V1::Models::Interactions.interaction_model(@doc, self)
  end
end

#item_bodyObject



16
17
18
19
20
21
22
23
24
# File 'lib/qti/v1/models/assessment_item.rb', line 16

def item_body
  @item_body ||= begin
    node = @doc.dup
    presentation = node.at_xpath('.//xmlns:presentation')
    mattext = presentation.at_xpath('.//xmlns:mattext')
    prompt = return_inner_content!(mattext)
    sanitize_content!(prompt)
  end
end

#points_possibleObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/qti/v1/models/assessment_item.rb', line 53

def points_possible
  @points_possible ||= begin
    if points_possible_qti_metadata?
      points_possible_label = .children.find do |node|
        node.text == 'points_possible'
      end
      points_possible_label.next.text
    else
      1
    end
  end
end

#points_possible_qti_metadata?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/qti/v1/models/assessment_item.rb', line 38

def points_possible_qti_metadata?
  if @doc.at_xpath('.//xmlns:qtimetadata').present?
    points_possible_label = .children.find { |node| node.text == 'points_possible' }
    points_possible_label.present?
  else
    false
  end
end

#qti_metadata_childrenObject



34
35
36
# File 'lib/qti/v1/models/assessment_item.rb', line 34

def 
  @doc.at_xpath('.//xmlns:qtimetadata')&.children
end

#rcardinalityObject



71
72
73
# File 'lib/qti/v1/models/assessment_item.rb', line 71

def rcardinality
  @rcardinality ||= @doc.at_xpath('.//xmlns:response_lid/@rcardinality').value
end

#scoring_data_structsObject



81
82
83
# File 'lib/qti/v1/models/assessment_item.rb', line 81

def scoring_data_structs
  @scoring_data_structs ||= interaction_model.scoring_data_structs
end

#titleObject



30
31
32
# File 'lib/qti/v1/models/assessment_item.rb', line 30

def title
  @title ||= @doc.attribute('title').value
end