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

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

Defined Under Namespace

Classes: ScoringData

Constant Summary

Constants inherited from Models::Base

Models::Base::ELEMENTS_REMAP

Instance Method Summary collapse

Methods inherited from Base

#qti_version

Methods inherited from Models::Base

#css_with_single_check, from_path!, #parse_xml, #remap_href_path, #remap_unknown_tags_transformer, #sanitize_config, #sanitize_content!, #xpath_with_single_check

Constructor Details

#initialize(item) ⇒ AssessmentItem

Returns a new instance of AssessmentItem.



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

def initialize(item)
  @doc = item
end

Instance Method Details

#identifierObject



21
22
23
# File 'lib/qti/v1/models/assessment_item.rb', line 21

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

#interaction_modelObject



39
40
41
# File 'lib/qti/v1/models/assessment_item.rb', line 39

def interaction_model
  @interaction_model ||= V1::Models::Interactions::LogicalIdentifierInteraction.new(@doc)
end

#item_bodyObject



13
14
15
16
17
18
19
# File 'lib/qti/v1/models/assessment_item.rb', line 13

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

#points_possibleObject



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

def points_possible
  @points_possible ||= begin
    @doc.at_xpath('.//decvar/@maxvalue')&.value || @doc.at_xpath('.//decvar/@defaultval')&.value
  end
end

#rcardinalityObject



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

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

#scoring_data_structsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/qti/v1/models/assessment_item.rb', line 43

def scoring_data_structs
  @scoring_data_structs ||= begin
    rcardinality = @doc.at_xpath('//response_lid/@rcardinality').value

    choice_nodes = @doc.xpath('.//respcondition')
    value_nodes = []
    # We need to find an action of Set or Add greater than 0 bc there is no correct answer tag
    choice_nodes.each do |choice_node|
      value_nodes << choice_node if choice_node.at_xpath('.//setvar').content.to_f.positive?
    end
    value_nodes.map { |value_node| ScoringData.new(value_node.at_xpath('//varequal').content, rcardinality) }
  end
end

#titleObject



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

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