Class: Qti::Models::Resource

Inherits:
Base
  • Object
show all
Includes:
MetaDataBase, 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 included from MetaDataBase

#metadata_from_node!

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.



14
15
16
17
18
19
20
# File 'lib/qti/models/resource.rb', line 14

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



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

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



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

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



22
23
24
# File 'lib/qti/models/resource.rb', line 22

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

#metadataObject



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

def 
  @metadata = (@node)
end