Class: Ezid::Metadata Private

Inherits:
Hashie::Mash
  • Object
show all
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

Constructor Details

#initialize(data = 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.



57
58
59
60
# File 'lib/ezid/metadata.rb', line 57

def initialize(data=nil)
  super()
  update(data) if 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.



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

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.



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

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

#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.



80
81
82
# File 'lib/ezid/metadata.rb', line 80

def replace(data)
  super coerce(data)
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:



87
88
89
90
91
92
93
94
95
# File 'lib/ezid/metadata.rb', line 87

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.



97
98
99
# File 'lib/ezid/metadata.rb', line 97

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.



76
77
78
# File 'lib/ezid/metadata.rb', line 76

def update(data)
  super coerce(data)
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.



72
73
74
# File 'lib/ezid/metadata.rb', line 72

def updated
  to_time(_updated)
end