Class: Qti::V1::Models::StimulusItem

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

Instance Attribute Summary

Attributes inherited from Models::Base

#doc, #manifest, #package_root, #path, #resource

Instance Method Summary collapse

Methods inherited from Base

#qti_version, #return_inner_content!, #sanitize_attributes, #sanitize_attributes_by_node

Methods inherited from Models::Base

#css_with_single_check, from_path!, #parse_html, #parse_xml, #preprocess_xml_doc, #raise_unsupported, #remap_href_path, #sanitize_content!, #xpath_with_single_check

Constructor Details

#initialize(ref_node) ⇒ StimulusItem

Returns a new instance of StimulusItem.



5
6
7
# File 'lib/qti/v1/models/stimulus_item.rb', line 5

def initialize(ref_node)
  @node = ref_node
end

Instance Method Details

#bodyObject



21
22
23
24
25
26
27
# File 'lib/qti/v1/models/stimulus_item.rb', line 21

def body
  @body ||= begin
    presentation = @node.at_xpath('.//xmlns:presentation')
    return nil if presentation.blank?
    sanitize_content!(presentation.at_xpath('.//xmlns:mattext')&.text)
  end
end

#identifierObject



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

def identifier
  @identifier ||= @node.attributes['ident']&.value
end

#instructionsObject



17
18
19
# File 'lib/qti/v1/models/stimulus_item.rb', line 17

def instructions
  @instructions ||= @node.attributes['instructions']&.value
end

#orientationObject



57
58
59
60
61
62
63
# File 'lib/qti/v1/models/stimulus_item.rb', line 57

def orientation
  @orientation ||= begin
    presentation = @node.at_xpath('.//xmlns:presentation')
    return 'left' if presentation.blank?
    presentation.at_xpath('.//xmlns:material')&.attributes&.[]('orientation')&.value || 'left'
  end
end

#qti_metadata_childrenObject



33
34
35
# File 'lib/qti/v1/models/stimulus_item.rb', line 33

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

#source_urlObject



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

def source_url
  @source_url ||= begin
    if source_url_qti_metadata?
      source_url_label = .children.find do |node|
        node.text == 'source_url'
      end
      source_url_label&.next&.text
    end
  end
end

#source_url_qti_metadata?Boolean

Returns:

  • (Boolean)


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

def source_url_qti_metadata?
  if @node.at_xpath('.//xmlns:qtimetadata').present?
    source_url_label = .children.find { |node| node.text == 'source_url' }
    source_url_label.present?
  else
    false
  end
end

#stimulus_typeObject



29
30
31
# File 'lib/qti/v1/models/stimulus_item.rb', line 29

def stimulus_type
  'text'
end

#titleObject



13
14
15
# File 'lib/qti/v1/models/stimulus_item.rb', line 13

def title
  @title ||= @node.attributes['title']&.value
end