lib/bolognese/readers/datacite_reader.rb in bolognese-1.0.2 vs lib/bolognese/readers/datacite_reader.rb in bolognese-1.0.3
- old
+ new
@@ -69,13 +69,23 @@
else
id = normalize_doi(meta.dig("identifier", "__content__") || options[:id], sandbox: options[:sandbox])
end
doi = doi_from_url(id)
+
resource_type_general = meta.dig("resourceType", "resourceTypeGeneral")
- additional_type = meta.fetch("resourceType", {}).fetch("__content__", nil)
- type = Bolognese::Utils::CR_TO_SO_TRANSLATIONS[additional_type.to_s.underscore.camelcase] || Bolognese::Utils::DC_TO_SO_TRANSLATIONS[resource_type_general.to_s.dasherize] || "CreativeWork"
+ resource_type = meta.dig("resourceType", "__content__")
+ type = Bolognese::Utils::CR_TO_SO_TRANSLATIONS[resource_type.to_s.underscore.camelcase] || Bolognese::Utils::DC_TO_SO_TRANSLATIONS[resource_type_general.to_s.dasherize] || "CreativeWork"
+ types = {
+ "type" => type,
+ "resource_type_general" => resource_type_general,
+ "resource_type" => resource_type,
+ "citeproc" => Bolognese::Utils::CR_TO_CP_TRANSLATIONS[resource_type.to_s.underscore.camelcase] || Bolognese::Utils::SO_TO_CP_TRANSLATIONS[type] || "article",
+ "bibtex" => Bolognese::Utils::CR_TO_BIB_TRANSLATIONS[resource_type.to_s.underscore.camelcase] || Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc",
+ "ris" => Bolognese::Utils::CR_TO_RIS_TRANSLATIONS[resource_type.to_s.underscore.camelcase] || Bolognese::Utils::DC_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN"
+ }.compact
+
title = Array.wrap(meta.dig("titles", "title")).map do |r|
if r.is_a?(String)
sanitize(r)
else
{ "title_type" => r["titleType"], "lang" => r["lang"], "text" => sanitize(r["__content__"]) }.compact
@@ -104,10 +114,11 @@
{
"date" => parse_attributes(d),
"date_type" => parse_attributes(d, content: "dateType")
}
end
+ dates << { "date" => meta.fetch("publicationYear", nil), "date_type" => "Issued" } if meta.fetch("publicationYear", nil).present? && get_date(dates, "Issued").blank?
sizes = Array.wrap(meta.dig("sizes", "size")).unwrap
formats = Array.wrap(meta.dig("formats", "format")).unwrap
funding_references = Array.wrap(meta.dig("fundingReferences", "fundingReference")).compact.map do |fr|
{
"funder_name" => fr["funderName"],
@@ -152,28 +163,22 @@
end
periodical = set_periodical(meta)
state = doi.present? ? "findable" : "not_found"
{ "id" => id,
- "type" => type,
- "additional_type" => additional_type,
- "citeproc_type" => Bolognese::Utils::CR_TO_CP_TRANSLATIONS[additional_type.to_s.underscore.camelcase] || Bolognese::Utils::SO_TO_CP_TRANSLATIONS[type] || "article",
- "bibtex_type" => Bolognese::Utils::CR_TO_BIB_TRANSLATIONS[additional_type.to_s.underscore.camelcase] || Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc",
- "ris_type" => Bolognese::Utils::CR_TO_RIS_TRANSLATIONS[additional_type.to_s.underscore.camelcase] || Bolognese::Utils::DC_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN",
- "resource_type_general" => resource_type_general,
+ "types" => types,
"doi" => doi,
"alternate_identifiers" => alternate_identifiers,
"url" => options.fetch(:url, nil),
"title" => title,
"creator" => get_authors(Array.wrap(meta.dig("creators", "creator"))),
"periodical" => periodical,
"publisher" => meta.fetch("publisher", "").strip.presence,
"service_provider" => "DataCite",
"funding_references" => funding_references,
"dates" => dates,
- "date_published" => datacite_date(dates, "Issued") || meta.fetch("publicationYear", nil),
- "date_modified" => datacite_date(dates, "Updated"),
+ "publication_year" => meta.fetch("publicationYear", nil),
"description" => description,
"rights" => rights,
"version" => meta.fetch("version", nil),
"keywords" => keywords,
"language" => meta.fetch("language", nil),
@@ -196,14 +201,9 @@
"id" => is_part_of["relatedIdentifierType"] == "DOI" ? normalize_doi(is_part_of["__content__"]) : is_part_of["__content__"],
"title" => container_title,
"issn" => is_part_of["relatedIdentifierType"] == "ISSN" ? is_part_of["__content__"] : nil
}.compact
end
- end
-
- def datacite_date(dates, date_type)
- dd = dates.find { |d| d["date_type"] == date_type } || {}
- dd.fetch("date", nil)
end
def datacite_funding_reference(meta)
Array.wrap(meta.dig("fundingReferences", "fundingReference")).compact.map do |f|
funder_id = parse_attributes(f["funderIdentifier"])