Class: Ezid::Metadata Private
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ezid::Metadata
- Defined in:
- lib/ezid/metadata.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
EZID metadata collection for an identifier.
Defined Under Namespace
Classes: Element
Constant Summary collapse
- ANVL_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
EZID metadata field/value separator
": "
- ELEMENT_VALUE_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
" | "
- ESCAPE_VALUES_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Characters to escape in element values on output to EZID
/[%\r\n]/
- ESCAPE_NAMES_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Characters to escape in element names on output to EZID
/[%:\r\n]/
- UNESCAPE_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Character sequence to unescape from EZID
/%\h\h/
- COMMENT_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A comment line
/^#.*(\r?\n)?/
- LINE_CONTINUATION_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A line continuation
/\r?\n\s+/
- LINE_ENDING_RE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A line ending
/\r?\n/
- PROFILES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Metadata profiles
{ "dc" => %w( creator title publisher date type ).freeze, "datacite" => %w( creator title publisher publicationyear resourcetype ).freeze, "erc" => %w( who what when ).freeze, "crossref" => [].freeze }.freeze
- RESERVED_TIME_ELEMENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
EZID reserved metadata elements that have time values
%w( _created _updated )
- RESERVED_READONLY_ELEMENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
EZID reserved metadata elements that are read-only
%w( _owner _ownergroup _shadows _shadowedby _datacenter _created _updated )
- RESERVED_READWRITE_ELEMENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
EZID reserved metadata elements that may be set by clients
%w( _coowners _target _profile _status _export _crossref )
- RESERVED_ELEMENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
All EZID reserved metadata elements
RESERVED_READONLY_ELEMENTS + RESERVED_READWRITE_ELEMENTS
Class Method Summary collapse
- .initialize! ⇒ Object private
- .register_element(accessor, opts = {}) ⇒ Object private
- .register_profile_element(profile, element) ⇒ Object private
- .registered_elements ⇒ Object private
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Metadata
constructor
private
A new instance of Metadata.
- #registered_elements ⇒ Object private
-
#to_anvl(include_readonly = true) ⇒ String
private
Output metadata in EZID ANVL format.
- #to_s ⇒ Object private
Constructor Details
#initialize(data = {}) ⇒ Metadata
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Metadata.
135 136 137 |
# File 'lib/ezid/metadata.rb', line 135 def initialize(data={}) super(coerce(data)) end |
Class Method Details
.initialize! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/ezid/metadata.rb', line 64 def self.initialize! register_elements end |
.register_element(accessor, opts = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 80 81 82 83 84 85 |
# File 'lib/ezid/metadata.rb', line 77 def self.register_element(accessor, opts={}) if element = registered_elements[accessor.to_sym] raise Error, "Element \"#{element.name}\" is registered under the accessor :#{accessor}." end element = Element.new(opts.fetch(:name, accessor.to_s)) element.reader = define_reader(accessor, element.name) element.writer = define_writer(accessor, element.name) if opts.fetch(:writer, true) registered_elements[accessor.to_sym] = element end |
.register_profile_element(profile, element) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 |
# File 'lib/ezid/metadata.rb', line 94 def self.register_profile_element(profile, element) register_element("#{profile}_#{element}", name: "#{profile}.#{element}") end |
.registered_elements ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/ezid/metadata.rb', line 68 def self.registered_elements @@registered_elements ||= {} end |
Instance Method Details
#registered_elements ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 |
# File 'lib/ezid/metadata.rb', line 152 def registered_elements self.class.registered_elements end |
#to_anvl(include_readonly = true) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Output metadata in EZID ANVL format
142 143 144 145 146 |
# File 'lib/ezid/metadata.rb', line 142 def to_anvl(include_readonly = true) elements = __getobj__.dup # copy, don't modify! elements.reject! { |k, v| RESERVED_READONLY_ELEMENTS.include?(k) } unless include_readonly escape_elements(elements).map { |e| e.join(ANVL_SEPARATOR) }.join("\n") end |
#to_s ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 |
# File 'lib/ezid/metadata.rb', line 148 def to_s to_anvl end |