lib/relaton/bibdata.rb in relaton-cli-0.1.6 vs lib/relaton/bibdata.rb in relaton-cli-0.1.7
- old
+ new
@@ -60,17 +60,32 @@
docidentifier&.match(DOC_NUMBER_REGEX) ? $2.to_i : 999999
end
def self.from_xml(source)
+ datetype = "circulated"
+
# bib.relaton_xml_path = URI.escape("#{relaton_root}/#{id_code}.xml")
revdate = source.at(ns("./date[@type = 'published']")) ||
- source.at(ns("./date[@type = 'circulated']")) || source.at(ns("./date"))
- datetype = "circulated"
- datetype = revdate["type"] if revdate
+ source.at(ns("./date[@type = 'circulated']")) ||
+ source.at(ns("./date"))
+ revdate_value = revdate&.at(ns("./on")) || revdate&.at(ns("./from"))
- new({
+ if revdate && revdate_value
+ datetype = revdate["type"]
+ revdate = begin
+ Date.parse(revdate_value.text.strip).to_s
+ rescue
+ warn "[relaton] parsing published date '#{revdate.text}' failed."
+ revdate_value.text.strip
+ end || nil
+ else
+ revdate = nil
+ end
+
+
+ options = {
uri: source.at(ns("./uri[not(@type)]"))&.text,
xml: source.at(ns("./uri[@type='xml']"))&.text,
pdf: source.at(ns("./uri[@type='pdf']"))&.text,
html: source.at(ns("./uri[@type='html']"))&.text,
rxl: source.at(ns("./uri[@type='rxl']"))&.text,
@@ -79,21 +94,23 @@
title: source.at(ns("./title"))&.text,
doctype: source.at(ns("./@type"))&.text,
stage: source.at(ns("./status"))&.text,
technical_committee: source.at(ns("./editorialgroup/technical-committee"))&.text,
abstract: source.at(ns("./abstract"))&.text,
- revdate: revdate ? Date.parse(revdate.text) : nil,
+ revdate: revdate,
language: source.at(ns("./language"))&.text,
script: source.at(ns("./script"))&.text,
edition: source.at(ns("./edition"))&.text,
copyright_from: source.at(ns("./copyright/from"))&.text,
copyright_owner: source.at(ns("./copyright/owner/organization/name"))&.text,
contributor_author_role: source.at(ns("./contributor/role[@type='author']"))&.text,
contributor_author_organization: source.at(ns("./contributor/role[@type='author']"))&.parent&.at(ns("./organization/name"))&.text,
contributor_publisher_role: source.at(ns("./contributor/role[@type='publisher']"))&.text,
contributor_publisher_organization: source.at(ns("./contributor/role[@type='publisher']"))&.parent&.at(ns("./organization/name"))&.text,
datetype: datetype
- })
+ }
+
+ new(options)
end
def to_xml
#datetype = stage&.casecmp("published") == 0 ? "published" : "circulated"