Class: Ezid::Metadata Private
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- 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.
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.
EZID metadata field value separator
" | "
- 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/
- COOWNERS =
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
"_coowners".freeze
- CREATED =
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.
"_created".freeze
- DATACENTER =
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.
"_datacenter".freeze
- EXPORT =
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.
"_export".freeze
- OWNER =
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.
"_owner".freeze
- OWNERGROUP =
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.
"_ownergroup".freeze
- PROFILE =
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.
"_profile".freeze
- SHADOWEDBY =
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.
"_shadowedby".freeze
- SHADOWS =
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.
"_shadows".freeze
- STATUS =
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.
"_status".freeze
- TARGET =
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.
"_target".freeze
- UPDATED =
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.
"_updated".freeze
- RESERVED =
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.
[ COOWNERS, CREATED, DATACENTER, EXPORT, OWNER, OWNERGROUP, PROFILE, SHADOWEDBY, SHADOWS, STATUS, TARGET, UPDATED ].freeze
- READONLY =
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.
[ CREATED, DATACENTER, OWNER, OWNERGROUP, SHADOWEDBY, SHADOWS, UPDATED ].freeze
Instance Method Summary collapse
- #created ⇒ Object private
- #elements ⇒ Object private
-
#initialize(data = nil, default = nil) ⇒ Metadata
constructor
private
A new instance of Metadata.
- #replace(data) ⇒ Object private
-
#to_anvl(include_readonly = true) ⇒ String
private
Output metadata in EZID ANVL format.
- #to_s ⇒ Object private
- #update(data) ⇒ Object private
- #updated ⇒ Object private
Constructor Details
#initialize(data = nil, default = nil) ⇒ 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.
62 63 64 65 66 67 68 |
# File 'lib/ezid/metadata.rb', line 62 def initialize(data=nil, default=nil) unless default.nil? raise ::NotImplementedError, "ezid-client does not support default metadata values." end super() update(data) if data end |
Instance Method Details
#created ⇒ 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.
76 77 78 |
# File 'lib/ezid/metadata.rb', line 76 def created to_time(_created) end |
#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.
70 71 72 73 74 |
# File 'lib/ezid/metadata.rb', line 70 def elements warn "[DEPRECATION] `Ezid::Metadata#elements` is deprecated and will be removed in ezid-client 2.0." \ " Use the `Ezid::Metadata` instance itself instead. (called from #{caller.first})" self end |
#replace(data) ⇒ 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.
88 89 90 91 92 93 94 95 |
# File 'lib/ezid/metadata.rb', line 88 def replace(data) hsh = coerce(data) # Perform additional profile transforms MetadataTransformDatacite.inverse(hsh) if hsh["_profile"] == "datacite" super hsh 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
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ezid/metadata.rb', line 100 def to_anvl(include_readonly = true) hsh = to_h hsh.reject! { |k, v| READONLY.include?(k) } unless include_readonly # Perform additional profile transforms MetadataTransformDatacite.transform(hsh) if profile == "datacite" lines = hsh.map do |name, value| element = [escape(ESCAPE_NAMES_RE, name), escape(ESCAPE_VALUES_RE, value)] element.join(ANVL_SEPARATOR) end lines.join("\n").force_encoding(Encoding::UTF_8) 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.
114 115 116 |
# File 'lib/ezid/metadata.rb', line 114 def to_s to_anvl end |
#update(data) ⇒ 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.
84 85 86 |
# File 'lib/ezid/metadata.rb', line 84 def update(data) super coerce(data) end |
#updated ⇒ 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.
80 81 82 |
# File 'lib/ezid/metadata.rb', line 80 def updated to_time(_updated) end |