Class: Ezid::Metadata Private

Inherits:
SimpleDelegator
  • 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.

" | "
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/
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.

EZID reserved metadata elements that are read-only

%w( _owner _ownergroup _shadows _shadowedby _datacenter _created _updated )

Class Method Summary collapse

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.



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

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

Class Method Details

.metadata_accessor(method, alias_as = nil) ⇒ 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.



30
31
32
33
# File 'lib/ezid/metadata.rb', line 30

def (method, alias_as=nil)
   method, alias_as
   method, alias_as
end

.metadata_profile(profile, *methods) ⇒ 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.



35
36
37
38
39
40
41
# File 'lib/ezid/metadata.rb', line 35

def (profile, *methods)
  methods.each do |method| 
    element = [profile, method].join(".")
    alias_as = [profile, method].join("_")
     element, alias_as
  end
end

.metadata_reader(method, alias_as = nil) ⇒ 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.



12
13
14
15
16
17
18
19
# File 'lib/ezid/metadata.rb', line 12

def (method, alias_as=nil)
  define_method method do
    self[method.to_s]
  end
  if alias_as
    alias_method alias_as, method
  end
end

.metadata_writer(method, alias_as = nil) ⇒ 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.



21
22
23
24
25
26
27
28
# File 'lib/ezid/metadata.rb', line 21

def (method, alias_as=nil)
  define_method "#{method}=" do |value|
    self[method.to_s] = value
  end
  if alias_as
    alias_method "#{alias_as}=".to_sym, "#{method}=".to_sym
  end 
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.



101
102
103
# File 'lib/ezid/metadata.rb', line 101

def created
  to_time _created
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:



112
113
114
115
116
117
118
119
120
# File 'lib/ezid/metadata.rb', line 112

def to_anvl(include_readonly = true)
  hsh = __getobj__.dup
  hsh.reject! { |k, v| READONLY.include?(k) } unless include_readonly
  elements = hsh.map do |name, value| 
    element = [escape(ESCAPE_NAMES_RE, name), escape(ESCAPE_VALUES_RE, value)]
    element.join(ANVL_SEPARATOR)
  end
  elements.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.



122
123
124
# File 'lib/ezid/metadata.rb', line 122

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.



105
106
107
# File 'lib/ezid/metadata.rb', line 105

def updated
  to_time _updated
end