Class: Stash::Wrapper::StashWrapper
- Inherits:
-
Object
- Object
- Stash::Wrapper::StashWrapper
- 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_wrappernamespace 'http://dash.cdlib.org/stash_wrapper/'- NAMESPACE_PREFIX =
The
stprefix for thestash_wrappernamespace 'st'
Class Method Summary collapse
Instance Method Summary collapse
- #embargo ⇒ Object
- #embargo_end_date ⇒ Object
- #embargo_type ⇒ Object
- #id_value ⇒ Object
-
#initialize(identifier:, version:, license:, embargo: nil, inventory: nil, descriptive_elements:) ⇒ StashWrapper
constructor
Creates a new StashWrapper.
- #inventory ⇒ Object
- #license ⇒ Object
- #license_name ⇒ Object
- #license_uri ⇒ Object
-
#pre_save(options = { mapping: :_default }) ⇒ Object
Overrides
XML::Mapping#pre_saveto set the XML namespace and schema location. -
#save_to_xml(options = { mapping: :_default }) ⇒ Object
Overrides
XML::Mapping#save_to_xmlto set the XML namespace prefix on allstash_wrapperelements. - #version ⇒ Object
- #version_date ⇒ Object
- #version_number ⇒ Object
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.
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: , 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 stash_administrative. end |
#embargo_end_date ⇒ Object
85 86 87 |
# File 'lib/stash/wrapper/stash_wrapper.rb', line 85 def .end_date end |
#embargo_type ⇒ Object
81 82 83 |
# File 'lib/stash/wrapper/stash_wrapper.rb', line 81 def .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( = { mapping: :_default }) xml = super() 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( = { mapping: :_default }) elem = super() 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 |