lib/ezid/metadata.rb in ezid-client-0.7.0 vs lib/ezid/metadata.rb in ezid-client-0.8.0

- old
+ new

@@ -27,21 +27,21 @@ # Character sequence to unescape from EZID # @see http://ezid.cdlib.org/doc/apidoc.html#request-response-bodies UNESCAPE_RE = /%\h\h/ # A comment line - COMMENT_RE = /^#.*(\r?\n)?/ + COMMENT_RE = /^#.*(\r?\n)?/ # A line continuation LINE_CONTINUATION_RE = /\r?\n\s+/ # A line ending LINE_ENDING_RE = /\r?\n/ - + # A metadata element Element = Struct.new(:name, :writer) - + # Metadata profiles PROFILES = { "dc" => %w( creator title publisher date type ).freeze, "datacite" => %w( creator title publisher publicationyear resourcetype ).freeze, "erc" => %w( who what when ).freeze, @@ -97,11 +97,11 @@ end def self.define_element_accessors elements.each do |accessor, element| define_method(accessor) { reader(element.name) } - + if element.writer define_method("#{accessor}=") { |value| writer(element.name, value) } end end end @@ -125,11 +125,11 @@ accessor = ((element == "_crossref") ? element : element.sub("_", "")).to_sym register_element(accessor, element, writer: RESERVED_READWRITE_ELEMENTS.include?(element)) end end - private_class_method :register_element, :register_elements, :register_reserved_elements, + private_class_method :register_element, :register_elements, :register_reserved_elements, :register_profile_elements, :define_element_accessors def initialize(data={}) super(coerce(data)) end @@ -200,10 +200,10 @@ # @param value [String] the value to unescape # @return [String] the unescaped value def unescape(value) value.gsub(UNESCAPE_RE) { |m| URI.decode_www_form_component(m) } end - + # Coerce a string of metadata (e.g., from EZID host) into a Hash # @note EZID host does not send comments or line continuations. # @param data [String] the string to coerce # @return [Hash] the hash of coerced data def coerce_string(data)