Class: Ezid::Metadata

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ezid/metadata.rb

Overview

Note:

Although this API is not private, its direct use is discouraged. Instead use the metadata element accessors through Ezid::Identifier.

EZID metadata collection for an identifier

Defined Under Namespace

Classes: Element, ElementRegistry

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

/%\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/
PROFILES =

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 =

EZID reserved metadata elements that have time values

%w( _created _updated )
RESERVED_READONLY_ELEMENTS =

EZID reserved metadata elements that are read-only

%w( _owner _ownergroup _shadows _shadowedby _datacenter _created _updated )
RESERVED_READWRITE_ELEMENTS =

EZID reserved metadata elements that may be set by clients

%w( _coowners _target _profile _status _export _crossref )
RESERVED_ELEMENTS =

All EZID reserved metadata elements

RESERVED_READONLY_ELEMENTS + RESERVED_READWRITE_ELEMENTS

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Metadata

Returns a new instance of Metadata.



133
134
135
# File 'lib/ezid/metadata.rb', line 133

def initialize(data={})
  super(coerce(data))
end

Class Method Details

.elementsObject



89
90
91
# File 'lib/ezid/metadata.rb', line 89

def self.elements
  ElementRegistry.instance
end

.initialize!Object



84
85
86
87
# File 'lib/ezid/metadata.rb', line 84

def self.initialize!
  register_elements
  define_element_accessors
end

Instance Method Details

#to_anvl(include_readonly = true) ⇒ String

Output metadata in EZID ANVL format

Returns:

  • (String)

    the ANVL output

See Also:



140
141
142
143
144
# File 'lib/ezid/metadata.rb', line 140

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_sObject



146
147
148
# File 'lib/ezid/metadata.rb', line 146

def to_s
  to_anvl
end