Class: Qti::Models::Resource
- 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
- #canvas_extra_file(filename) ⇒ Object
- #canvas_metadata ⇒ Object
- #href ⇒ Object
-
#initialize(node, parent) ⇒ Resource
constructor
A new instance of Resource.
- #metadata ⇒ Object
Methods included from XPathHelpers
#rtype_predicate, #xpath_endswith, #xpath_resource
Methods included from MetaDataBase
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_metadata ⇒ Object
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 = File.join(@package_root, @canvas_meta_file) @canvas_metadata ||= Qti::Models::AssessmentMeta.from_path!() if @canvas_meta_file end |
#href ⇒ Object
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 |
#metadata ⇒ Object
26 27 28 |
# File 'lib/qti/models/resource.rb', line 26 def @metadata = (@node) end |