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

EXTERNALLY_PROVIDED =

Indicates whether the structure is externally provided or maintained by the repository itself (i.e., is the default structure for the object).

'provided'.freeze
REPOSITORY_MAINTAINED =
'repository'.freeze
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

Instance Method Summary collapse

Instance Method Details

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



127
128
129
130
131
132
# File 'lib/ddr/models/structure.rb', line 127

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



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

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



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

def as_xml_document
  __getobj__
end

#creatorObject



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

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

#dereferenced_structureObject



57
58
59
60
61
62
63
# File 'lib/ddr/models/structure.rb', line 57

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

#filesObject



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

def files
  @files ||= collect_files
end

#filesecObject



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

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

#metshdrObject



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

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

#repository_maintained?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ddr/models/structure.rb', line 53

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

#structmap(type = nil) ⇒ Object



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

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

#structmapsObject



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

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

#usesObject



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

def uses
  @uses ||= collect_uses
end