Class: Qti::Models::Resource

Inherits:
Base
  • Object
show all
Includes:
XPathHelpers
Defined in:
lib/qti/models/resource.rb

Instance Attribute Summary

Attributes inherited from Base

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

Instance Method Summary collapse

Methods included from XPathHelpers

#rtype_predicate, #xpath_endswith, #xpath_resource

Methods inherited from 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(node, parent) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
13
14
# File 'lib/qti/models/resource.rb', line 8

def initialize(node, parent)
  @node = node
  @parent = parent
  @resource_type = node.attr('type')
  @identifier = node.attr('identifier')
  copy_paths_from_item(parent)
end

Instance Method Details

#canvas_extra_file(filename) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/qti/models/resource.rb', line 31

def canvas_extra_file(filename)
  dep_id = dependency_id
  rsc = @parent.resource_node(
    "[@identifier='#{dep_id}']/xmlns:file[#{xpath_endswith('@href', filename)}]/@href"
  )
  rsc&.content
end

#canvas_metadataObject



24
25
26
27
28
29
# File 'lib/qti/models/resource.rb', line 24

def 
  @canvas_meta_file ||= canvas_extra_file('assessment_meta.xml')
  return unless @canvas_meta_file
  meta_file = File.join(@package_root, @canvas_meta_file)
  @canvas_metadata ||= Qti::Models::AssessmentMeta.from_path!(meta_file) if @canvas_meta_file
end

#hrefObject



16
17
18
# File 'lib/qti/models/resource.rb', line 16

def href
  @href ||= @node.attr('href') || @node.xpath('xmlns:file/@href')&.first&.content
end

#metadataObject



20
21
22
# File 'lib/qti/models/resource.rb', line 20

def 
  @metadata ||= MetaData.new(@node)
end