Class: Ddr::Structure

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ddr/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

Instance Method Summary collapse

Instance Method Details

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



45
46
47
48
49
50
# File 'lib/ddr/structure.rb', line 45

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) ⇒ Object



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

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_metshdr(id: nil, createdate: nil, lastmoddate: nil, recordstatus: nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/ddr/structure.rb', line 38

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:) ⇒ Object



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

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:) ⇒ Object



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

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_documentObject



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

def as_xml_document
  __getobj__
end

#creatorObject



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

def creator
  metshdr.agents.first&.name
end

#dereferenced_structureObject



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

def dereferenced_structure
  Hash[structmaps.map { |sm| [sm.type, sm.dereferenced_hash] }]
end

#metshdrObject



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

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

#repository_maintained?Boolean

Returns:

  • (Boolean)


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

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

#structmapsObject



14
15
16
# File 'lib/ddr/structure.rb', line 14

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