lib/bolognese/datacite_utils.rb in bolognese-0.9.36 vs lib/bolognese/datacite_utils.rb in bolognese-0.9.37

- old
+ new

@@ -1,27 +1,22 @@ module Bolognese module DataciteUtils - def schema - kernel = schema_version.split("/").last || "kernel-4.0" - filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__) - Nokogiri::XML::Schema(open(filepath)) - end - def datacite_xml @datacite_xml ||= Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.resource(root_attributes) do insert_work(xml) end end.to_xml end - # def datacite - # datacite_xml - # end + def datacite_errors(xml: nil, schema_version: nil) + schema_version ||= "http://datacite.org/schema/kernel-4" + kernel = schema_version.to_s.split("/").last + filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__) + schema = Nokogiri::XML::Schema(open(filepath)) - def datacite_errors - schema.validate(Nokogiri::XML(datacite, nil, 'UTF-8')).map { |error| error.to_s }.unwrap + schema.validate(Nokogiri::XML(xml, nil, 'UTF-8')).map { |error| error.to_s }.unwrap rescue Nokogiri::XML::SyntaxError => e e.message end def insert_work(xml) @@ -86,10 +81,10 @@ def insert_title(xml) xml.title(title) end def insert_publisher(xml) - xml.publisher(publisher) + xml.publisher(publisher || container_title) end def insert_publication_year(xml) xml.publicationYear(publication_year) end