Class: Ddr::Models::Structure

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ddr/models/structure.rb

Overview

Wraps a Nokogiri (XML) ‘mets’ Document

Constant Summary collapse

TYPE_DEFAULT =
'default'.freeze
USE_EXTRACTED_TEXT =

Based on the PCDM Extension ‘Use’ ontology – github.com/duraspace/pcdm/blob/master/pcdm-ext/use.rdf

'ExtractedText'.freeze
USE_INTERMEDIATE_FILE =
'IntermediateFile'.freeze
USE_ORIGINAL_FILE =
'OriginalFile'.freeze
USE_PRESERVATION_MASTER_FILE =
'PreservationMasterFile'.freeze
USE_SERVICE_FILE =
'ServiceFile'.freeze
USE_THUMBNAIL_IMAGE =
'ThumbnailImage'.freeze
USE_TRANSCRIPT =
'Transcript'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.xml_templateObject



174
175
176
177
178
179
180
# File 'lib/ddr/models/structure.rb', line 174

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

Instance Method Details

#add_agent(parent:, id: nil, role:, otherrole: nil, type: nil, othertype: nil, name: nil) ⇒ Object



71
72
73
74
75
76
# File 'lib/ddr/models/structure.rb', line 71

def add_agent(parent:, id:nil, role:, otherrole:nil, type:nil, othertype:nil, name:nil)
  agent = Ddr::Models::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) ⇒ Object



109
110
111
112
113
114
# File 'lib/ddr/models/structure.rb', line 109

def add_div(parent:, id:nil, label:nil, order:nil, orderlabel: nil, type:nil)
  div = Ddr::Models::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: SecureRandom.uuid, use: nil) ⇒ Object



90
91
92
93
94
# File 'lib/ddr/models/structure.rb', line 90

def add_file(parent:, id:SecureRandom.uuid, use:nil)
  file = Ddr::Models::Structures::File.build(id: id, use: use, document: as_xml_document)
  parent.add_child(file)
  file
end

#add_filegrp(parent:, id: nil, use: nil) ⇒ Object



84
85
86
87
88
# File 'lib/ddr/models/structure.rb', line 84

def add_filegrp(parent:, id:nil, use:nil)
  filegrp = Ddr::Models::Structures::FileGrp.build(id: id, use: use, document: as_xml_document)
  parent.add_child(filegrp)
  filegrp
end

#add_filesec(id: nil) ⇒ Object



78
79
80
81
82
# File 'lib/ddr/models/structure.rb', line 78

def add_filesec(id:nil)
  filesec = Ddr::Models::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:) ⇒ Object



96
97
98
99
100
101
# File 'lib/ddr/models/structure.rb', line 96

def add_flocat(parent:, id:nil, loctype:'ARK', otherloctype: nil, use:nil, href:)
  flocat = Ddr::Models::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:) ⇒ Object



116
117
118
119
120
# File 'lib/ddr/models/structure.rb', line 116

def add_fptr(parent:, id: nil, fileid:)
  fptr = Ddr::Models::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) ⇒ Object



64
65
66
67
68
69
# File 'lib/ddr/models/structure.rb', line 64

def add_metshdr(id:nil, createdate:nil, lastmoddate:nil, recordstatus:nil)
  metshdr = Ddr::Models::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:) ⇒ Object



122
123
124
125
126
127
# File 'lib/ddr/models/structure.rb', line 122

def add_mptr(parent:, id: nil, loctype:'ARK', otherloctype: nil, href:)
  mptr = Ddr::Models::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:) ⇒ Object



103
104
105
106
107
# File 'lib/ddr/models/structure.rb', line 103

def add_structmap(id:nil, label:nil, type:)
  structmap = Ddr::Models::Structures::StructMap.build(id: id, label: label, type: type, document: as_xml_document)
  root.add_child(structmap)
  structmap
end

#as_xml_documentObject



60
61
62
# File 'lib/ddr/models/structure.rb', line 60

def as_xml_document
  __getobj__
end

#creatorObject



43
44
45
46
# File 'lib/ddr/models/structure.rb', line 43

def creator
  @creator ||= metshdr.empty? ? nil
                              : Ddr::Models::Structures::MetsHdr.new(metsHdr_node).agents.first.name
end

#dereferenced_structureObject



52
53
54
55
56
57
58
# File 'lib/ddr/models/structure.rb', line 52

def dereferenced_structure
  deref_struct = {}
  structmaps.each do |sm|
    deref_struct[sm.type] = sm.dereferenced_hash
  end
  deref_struct
end

#filesObject



22
23
24
# File 'lib/ddr/models/structure.rb', line 22

def files
  @files ||= collect_files
end

#filesecObject



18
19
20
# File 'lib/ddr/models/structure.rb', line 18

def filesec
  @filesec ||= Ddr::Models::Structures::FileSec.new(fileSec_node)
end

#metshdrObject



39
40
41
# File 'lib/ddr/models/structure.rb', line 39

def metshdr
  @metshdr ||=  Ddr::Models::Structures::MetsHdr.new(metsHdr_node)
end

#repository_maintained?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ddr/models/structure.rb', line 48

def repository_maintained?
  creator == Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT
end

#structmap(type = nil) ⇒ Object



30
31
32
33
# File 'lib/ddr/models/structure.rb', line 30

def structmap(type=nil)
  sm = type ? structMap_node(type) : structMap_nodes.first
  @structmap ||= Ddr::Models::Structures::StructMap.new(sm)
end

#structmapsObject



35
36
37
# File 'lib/ddr/models/structure.rb', line 35

def structmaps
  @structmaps ||= structMap_nodes.map { |sm| Ddr::Models::Structures::StructMap.new(sm) }
end

#usesObject



26
27
28
# File 'lib/ddr/models/structure.rb', line 26

def uses
  @uses ||= collect_uses
end