lib/ezid/metadata.rb in ezid-client-1.7.1 vs lib/ezid/metadata.rb in ezid-client-1.8.0
- old
+ new
@@ -1,6 +1,7 @@
require "hashie"
+require_relative "metadata_transforms/datacite"
module Ezid
#
# EZID metadata collection for an identifier.
#
@@ -83,18 +84,27 @@
def update(data)
super coerce(data)
end
def replace(data)
- super coerce(data)
+ hsh = coerce(data)
+
+ # Perform additional profile transforms
+ MetadataTransformDatacite.inverse(hsh) if hsh["_profile"] == "datacite"
+
+ super hsh
end
# Output metadata in EZID ANVL format
# @see http://ezid.cdlib.org/doc/apidoc.html#request-response-bodies
# @return [String] the ANVL output
def to_anvl(include_readonly = true)
hsh = to_h
hsh.reject! { |k, v| READONLY.include?(k) } unless include_readonly
+
+ # Perform additional profile transforms
+ MetadataTransformDatacite.transform(hsh) if profile == "datacite"
+
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)