Class: Ezid::Metadata Private

Inherits:
Hashie::Mash
  • Object
show all
Includes:
ReservedMetadata
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/
RESERVED_ALIASES =

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.

%w(
  coowners datacenter export owner ownergroup
  profile shadowedby shadows status target
).freeze

Constants included from ReservedMetadata

ReservedMetadata::COOWNERS, ReservedMetadata::CREATED, ReservedMetadata::DATACENTER, ReservedMetadata::EXPORT, ReservedMetadata::OWNER, ReservedMetadata::OWNERGROUP, ReservedMetadata::PROFILE, ReservedMetadata::READONLY, ReservedMetadata::SHADOWEDBY, ReservedMetadata::SHADOWS, ReservedMetadata::STATUS, ReservedMetadata::TARGET, ReservedMetadata::UPDATED

Instance Method Summary collapse

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.



38
39
40
# File 'lib/ezid/metadata.rb', line 38

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

Instance Method Details

#createdObject

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.



48
49
50
# File 'lib/ezid/metadata.rb', line 48

def created
  to_time(_created)
end

#elementsObject

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.



42
43
44
45
46
# File 'lib/ezid/metadata.rb', line 42

def elements
  warn "[DEPRECATION] `elements` is deprecated and will be removed in ezid-client 2.0." \
       " Use the Ezid::Metadata instance itself instead."
  self
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

Returns:

  • (String)

    the ANVL output

See Also:



59
60
61
62
63
64
65
66
67
# File 'lib/ezid/metadata.rb', line 59

def to_anvl(include_readonly = true)
  hsh = to_h
  hsh.reject! { |k, v| READONLY.include?(k) } unless include_readonly
  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_sObject

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.



69
70
71
# File 'lib/ezid/metadata.rb', line 69

def to_s
  to_anvl
end

#updatedObject

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.



52
53
54
# File 'lib/ezid/metadata.rb', line 52

def updated
  to_time(_updated)
end