Class: Stash::Wrapper::StashWrapper

Inherits:
Object
  • Object
show all
Includes:
XML::Mapping
Defined in:
lib/stash/wrapper/stash_wrapper.rb

Overview

Mapping for the root <st:stash_wrapper> element

Constant Summary collapse

NAMESPACE =

The stash_wrapper namespace

'http://dash.cdlib.org/stash_wrapper/'
NAMESPACE_PREFIX =

The st prefix for the stash_wrapper namespace

'st'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, version:, license:, embargo: nil, inventory: nil, descriptive_elements:) ⇒ StashWrapper

Creates a new Stash::Wrapper::StashWrapper. As a convenience, constructs an internal Stash::Wrapper::StashAdministrative directly from the supplied administrative elements.

Parameters:

  • identifier (Identifier) —

    the identifier

  • version (Version) —

    the version

  • license (License) —

    the license

  • embargo (Embargo, nil) (defaults to: nil) —

    the embargo information. If no Embargo is supplied, it will default to an embargo of type EmbargoType::NONE with the current date as start and end.

  • inventory (Inventory, nil) (defaults to: nil) —

    the (optional) file inventory

  • descriptive_elements (Array<REXML::Element>) —

    the encapsulated XML metadata



38
39
40
41
42
43
44
45
46
47
# File 'lib/stash/wrapper/stash_wrapper.rb', line 38

def initialize(identifier:, version:, license:, embargo: nil, inventory: nil, descriptive_elements:) # rubocop:disable Metrics/ParameterLists
  self.identifier = identifier
  self.stash_administrative = StashAdministrative.new(
    version: version,
    license: license,
    embargo: embargo,
    inventory: inventory
  )
  self.stash_descriptive = descriptive_elements
end

Class Method Details

.parse_xml(xml_str) ⇒ Object



113
114
115
116
# File 'lib/stash/wrapper/stash_wrapper.rb', line 113

def self.parse_xml(xml_str)
  xml = REXML::Document.new(xml_str).root
  load_from_xml(xml)
end

Instance Method Details

#embargo ⇒ Object



77
78
79
# File 'lib/stash/wrapper/stash_wrapper.rb', line 77

def embargo
  stash_administrative.embargo
end

#embargo_end_date ⇒ Object



85
86
87
# File 'lib/stash/wrapper/stash_wrapper.rb', line 85

def embargo_end_date
  embargo.end_date
end

#embargo_type ⇒ Object



81
82
83
# File 'lib/stash/wrapper/stash_wrapper.rb', line 81

def embargo_type
  embargo.type
end

#id_value ⇒ Object



49
50
51
# File 'lib/stash/wrapper/stash_wrapper.rb', line 49

def id_value
  identifier.value
end

#inventory ⇒ Object



89
90
91
# File 'lib/stash/wrapper/stash_wrapper.rb', line 89

def inventory
  stash_administrative.inventory
end

#license ⇒ Object



65
66
67
# File 'lib/stash/wrapper/stash_wrapper.rb', line 65

def license
  stash_administrative.license
end

#license_name ⇒ Object



69
70
71
# File 'lib/stash/wrapper/stash_wrapper.rb', line 69

def license_name
  license.name
end

#license_uri ⇒ Object



73
74
75
# File 'lib/stash/wrapper/stash_wrapper.rb', line 73

def license_uri
  license.uri
end

#pre_save(options = { mapping: :_default }) ⇒ Object

Overrides XML::Mapping#pre_save to set the XML namespace and schema location.



94
95
96
97
98
99
100
# File 'lib/stash/wrapper/stash_wrapper.rb', line 94

def pre_save(options = { mapping: :_default })
  xml = super(options)
  xml.add_namespace(NAMESPACE)
  xml.add_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
  xml.add_attribute('xsi:schemaLocation', 'http://dash.cdlib.org/stash_wrapper/ http://dash.cdlib.org/stash_wrapper/stash_wrapper.xsd')
  xml
end

#save_to_xml(options = { mapping: :_default }) ⇒ Object

Overrides XML::Mapping#save_to_xml to set the XML namespace prefix on all stash_wrapper elements. (The elements in descriptive_elements should retain their existing namespaces and prefixes, if any.)



105
106
107
108
109
110
111
# File 'lib/stash/wrapper/stash_wrapper.rb', line 105

def save_to_xml(options = { mapping: :_default })
  elem = super(options)
  set_prefix(prefix: NAMESPACE_PREFIX, elem: elem)
  elem.add_namespace(nil) # clear the no-prefix namespace
  elem.add_namespace(NAMESPACE_PREFIX, NAMESPACE)
  elem
end

#version ⇒ Object



53
54
55
# File 'lib/stash/wrapper/stash_wrapper.rb', line 53

def version
  stash_administrative.version
end

#version_date ⇒ Object



61
62
63
# File 'lib/stash/wrapper/stash_wrapper.rb', line 61

def version_date
  version.date
end

#version_number ⇒ Object



57
58
59
# File 'lib/stash/wrapper/stash_wrapper.rb', line 57

def version_number
  version.version_number
end