Class: Ezid::Metadata
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ezid::Metadata
- Includes:
- MetadataElements
- Defined in:
- lib/ezid/metadata.rb
Overview
EZID metadata collection for an identifier
Constant Summary collapse
- ANVL_SEPARATOR =
EZID metadata field/value separator
": "- ELEMENT_VALUE_SEPARATOR =
" | "- ESCAPE_VALUES_RE =
Characters to escape in element values on output to EZID
/[%\r\n]/- ESCAPE_NAMES_RE =
Characters to escape in element names on output to EZID
/[%:\r\n]/- UNESCAPE_RE =
Character sequence to unescape from EZID ezid.cdlib.org/doc/apidoc.html#request-response-bodies
/%\h\h/- COMMENT_RE =
A comment line
/^#.*(\r?\n)?/- LINE_CONTINUATION_RE =
A line continuation
/\r?\n\s+/- LINE_ENDING_RE =
A line ending
/\r?\n/
Constants included from MetadataElements
Ezid::MetadataElements::DATACITE_ELEMENTS, Ezid::MetadataElements::DC_ELEMENTS, Ezid::MetadataElements::ERC_ELEMENTS, Ezid::MetadataElements::RESERVED_ELEMENTS, Ezid::MetadataElements::RESERVED_READONLY_ELEMENTS, Ezid::MetadataElements::RESERVED_READWRITE_ELEMENTS, Ezid::MetadataElements::RESERVED_TIME_ELEMENTS
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Metadata
constructor
A new instance of Metadata.
-
#replace(data) ⇒ Ezid::Metadata
Replaces the collection with new metadata.
-
#to_anvl(include_readonly = true) ⇒ String
Output metadata in EZID ANVL format.
- #to_s ⇒ Object
-
#update(data) ⇒ Ezid::Metadata
Adds metadata to the collection.
Constructor Details
#initialize(data = {}) ⇒ Metadata
Returns a new instance of Metadata.
40 41 42 |
# File 'lib/ezid/metadata.rb', line 40 def initialize(data={}) super(coerce(data)) end |
Instance Method Details
#replace(data) ⇒ Ezid::Metadata
Replaces the collection with new metadata
68 69 70 71 |
# File 'lib/ezid/metadata.rb', line 68 def replace(data) __getobj__.replace(coerce(data)) self end |
#to_anvl(include_readonly = true) ⇒ String
Output metadata in EZID ANVL format
47 48 49 50 51 |
# File 'lib/ezid/metadata.rb', line 47 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
53 54 55 |
# File 'lib/ezid/metadata.rb', line 53 def to_s to_anvl end |
#update(data) ⇒ Ezid::Metadata
Adds metadata to the collection
60 61 62 63 |
# File 'lib/ezid/metadata.rb', line 60 def update(data) __getobj__.update(coerce(data)) self end |