class Ddr::Structure
Wraps a Nokogiri (XML) 'mets' Document
Constants
- EXTERNALLY_PROVIDED
Indicates whether the structure is externally provided or maintained by the repository itself (i.e., is the default structure for the object).
- REPOSITORY_MAINTAINED
- TYPE_DEFAULT
- USE_EXTRACTED_TEXT
Based on the PCDM Extension 'Use' ontology – github.com/duraspace/pcdm/blob/master/pcdm-ext/use.rdf
- USE_INTERMEDIATE_FILE
- USE_ORIGINAL_FILE
- USE_PRESERVATION_MASTER_FILE
- USE_SERVICE_FILE
- USE_THUMBNAIL_IMAGE
- USE_TRANSCRIPT
Private Class Methods
xml_template()
click to toggle source
# File lib/ddr/structure.rb, line 180 def self.xml_template Nokogiri::XML( '<mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" />' ) do |config| config.noblanks end end
Public Instance Methods
add_agent(parent:, id:nil, role:, otherrole:nil, type:nil, othertype:nil, name:nil)
click to toggle source
# File lib/ddr/structure.rb, line 76 def add_agent(parent:, id:nil, role:, otherrole:nil, type:nil, othertype:nil, name:nil) agent = Ddr::Structures::Agent.build(id: id, role: role, otherrole: otherrole, type: type, othertype: othertype, name: name, document: as_xml_document) parent.add_child(agent) agent end
add_div(parent:, id:nil, label:nil, order:nil, orderlabel: nil, type:nil)
click to toggle source
# File lib/ddr/structure.rb, line 115 def add_div(parent:, id:nil, label:nil, order:nil, orderlabel: nil, type:nil) div = Ddr::Structures::Div.build(id: id, label: label, order:order, orderlabel: orderlabel, type: type, document: as_xml_document) parent.add_child(div) div end
add_file(parent:, id: "id_" + SecureRandom.uuid, use:nil)
click to toggle source
# File lib/ddr/structure.rb, line 96 def add_file(parent:, id: "id_" + SecureRandom.uuid, use:nil) file = Ddr::Structures::File.build(id: id, use: use, document: as_xml_document) parent.add_child(file) file end
add_filegrp(parent:, id:nil, use:nil)
click to toggle source
# File lib/ddr/structure.rb, line 90 def add_filegrp(parent:, id:nil, use:nil) filegrp = Ddr::Structures::FileGrp.build(id: id, use: use, document: as_xml_document) parent.add_child(filegrp) filegrp end
add_filesec(id:nil)
click to toggle source
# File lib/ddr/structure.rb, line 83 def add_filesec(id:nil) filesec = Ddr::Structures::FileSec.build(id: id, document: as_xml_document) root.add_child(filesec) filesec end
add_flocat(parent:, id:nil, loctype:'ARK', otherloctype: nil, use:nil, href:)
click to toggle source
# File lib/ddr/structure.rb, line 102 def add_flocat(parent:, id:nil, loctype:'ARK', otherloctype: nil, use:nil, href:) flocat = Ddr::Structures::FLocat.build(id: id, loctype: loctype, otherloctype: otherloctype, use: use, href: href, document: as_xml_document) parent.add_child(flocat) flocat end
add_fptr(parent:, id: nil, fileid:)
click to toggle source
# File lib/ddr/structure.rb, line 122 def add_fptr(parent:, id: nil, fileid:) fptr = Ddr::Structures::Fptr.build(id: id, fileid: fileid, document: as_xml_document) parent.add_child(fptr) fptr end
add_metshdr(id:nil, createdate:nil, lastmoddate:nil, recordstatus:nil)
click to toggle source
# File lib/ddr/structure.rb, line 69 def add_metshdr(id:nil, createdate:nil, lastmoddate:nil, recordstatus:nil) metshdr = Ddr::Structures::MetsHdr.build(id: id, createdate: createdate, lastmoddate: lastmoddate, recordstatus: recordstatus, document: as_xml_document) root.add_child(metshdr) metshdr end
add_mptr(parent:, id: nil, loctype:'ARK', otherloctype: nil, href:)
click to toggle source
# File lib/ddr/structure.rb, line 128 def add_mptr(parent:, id: nil, loctype:'ARK', otherloctype: nil, href:) mptr = Ddr::Structures::Mptr.build(id: id, loctype: loctype, otherloctype: otherloctype, href: href, document: as_xml_document) parent.add_child(mptr) mptr end
add_structmap(id:nil, label:nil, type:)
click to toggle source
# File lib/ddr/structure.rb, line 109 def add_structmap(id:nil, label:nil, type:) structmap = Ddr::Structures::StructMap.build(id: id, label: label, type: type, document: as_xml_document) root.add_child(structmap) structmap end
as_xml_document()
click to toggle source
# File lib/ddr/structure.rb, line 65 def as_xml_document __getobj__ end
creator()
click to toggle source
# File lib/ddr/structure.rb, line 48 def creator @creator ||= metshdr.empty? ? nil : Ddr::Structures::MetsHdr.new(metsHdr_node).agents.first.name end
dereferenced_structure()
click to toggle source
# File lib/ddr/structure.rb, line 57 def dereferenced_structure deref_struct = {} structmaps.each do |sm| deref_struct[sm.type] = sm.dereferenced_hash end deref_struct end
files()
click to toggle source
# File lib/ddr/structure.rb, line 27 def files @files ||= collect_files end
filesec()
click to toggle source
# File lib/ddr/structure.rb, line 23 def filesec @filesec ||= Ddr::Structures::FileSec.new(fileSec_node) end
metshdr()
click to toggle source
# File lib/ddr/structure.rb, line 44 def metshdr @metshdr ||= Ddr::Structures::MetsHdr.new(metsHdr_node) end
repository_maintained?()
click to toggle source
# File lib/ddr/structure.rb, line 53 def repository_maintained? creator == Ddr::Structures::Agent::NAME_REPOSITORY_DEFAULT end
structmap(type=nil)
click to toggle source
# File lib/ddr/structure.rb, line 35 def structmap(type=nil) sm = type ? structMap_node(type) : structMap_nodes.first @structmap ||= Ddr::Structures::StructMap.new(sm) end
structmaps()
click to toggle source
# File lib/ddr/structure.rb, line 40 def structmaps @structmaps ||= structMap_nodes.map { |sm| Ddr::Structures::StructMap.new(sm) } end
uses()
click to toggle source
# File lib/ddr/structure.rb, line 31 def uses @uses ||= collect_uses end
Private Instance Methods
collect_files()
click to toggle source
# File lib/ddr/structure.rb, line 161 def collect_files files = {} file_nodes.each do |file_node| file = Ddr::Structures::File.new(file_node) files[file.id] = file end files end
collect_uses()
click to toggle source
# File lib/ddr/structure.rb, line 170 def collect_uses uses = {} flocat_nodes.each do |flocat_node| flocat = Ddr::Structures::FLocat.new(flocat_node) uses[flocat.effective_use] ||= [] uses[flocat.effective_use] << flocat end uses end
fileSec_node()
click to toggle source
# File lib/ddr/structure.rb, line 137 def fileSec_node xpath("//xmlns:fileSec").first end
file_nodes()
click to toggle source
# File lib/ddr/structure.rb, line 153 def file_nodes xpath("//xmlns:file") end
flocat_nodes()
click to toggle source
# File lib/ddr/structure.rb, line 157 def flocat_nodes xpath("//xmlns:FLocat") end
metsHdr_node()
click to toggle source
# File lib/ddr/structure.rb, line 149 def metsHdr_node xpath("//xmlns:metsHdr") end
structMap_node(type)
click to toggle source
# File lib/ddr/structure.rb, line 145 def structMap_node(type) xpath("//xmlns:structMap[@TYPE='#{type}']").first end
structMap_nodes()
click to toggle source
# File lib/ddr/structure.rb, line 141 def structMap_nodes xpath("//xmlns:structMap") end