lib/bolognese/datacite_utils.rb in bolognese-0.4.3 vs lib/bolognese/datacite_utils.rb in bolognese-0.5

- old
+ new

@@ -1,19 +1,27 @@ module Bolognese module DataciteUtils SO_TO_DC_TRANSLATIONS = { - "VideoObject" => "Audiovisual", + "Article" => "Text", + "AudioObject" => "Sound", + "Blog" => "Text", + "BlogPosting" => "Text", "Collection" => "Collection", + "CreativeWork" => "Other", + "DataCatalog" => "Dataset", "Dataset" => "Dataset", "Event" => "Event", "ImageObject" => "Image", + "Movie" => "Audiovisual", + "PublicationIssue" => "Text", + "ScholarlyArticle" => "Text", "Service" => "Service", "SoftwareSourceCode" => "Software", - "AudioObject" => "Sound", - "ScholarlyArticle" => "Text", - "CreativeWork" => "Other" + "VideoObject" => "Audiovisual", + "WebPage" => "Text", + "WebSite" => "Text" } LICENSE_NAMES = { "http://creativecommons.org/publicdomain/zero/1.0/" => "Public Domain (CC0 1.0)", "http://creativecommons.org/licenses/by/3.0/" => "Creative Commons Attribution 3.0 (CC-BY 3.0)", @@ -112,17 +120,23 @@ def insert_publisher(xml) xml.publisher(container_title) end def insert_publication_year(xml) - xml.publicationYear(date_published[0..3]) + xml.publicationYear(date_published && date_published[0..3]) end + def resource_type + { "resource_type_general" => SO_TO_DC_TRANSLATIONS[type] || "Other", + "text" => additional_type || type } + end + def insert_resource_type(xml) return xml unless type.present? - xml.resourceType(additional_type, 'resourceTypeGeneral' => SO_TO_DC_TRANSLATIONS[type]) + xml.resourceType(resource_type["text"], + 'resourceTypeGeneral' => resource_type["resource_type_general"]) end def insert_alternate_identifiers(xml) return xml unless alternate_name.present? @@ -158,31 +172,20 @@ xml.version(version) end def rel_identifiers - ipo = Array.wrap(is_part_of).map do |i| - { - "text" => i["@id"], - "related_identifier_type" => validate_url(i["@id"]), - "relation_type" => "IsPartOf" } - end.select { |i| i["related_identifier_type"].present? } + rel_identifier(rel_ids: is_part_of, relation_type: "IsPartOf") + + rel_identifier(rel_ids: has_part, relation_type: "HasPart") + + rel_identifier(rel_ids: citation, relation_type: "References") + end - hp = Array.wrap(has_part).map do |i| - { - "text" => i["@id"], + def rel_identifier(rel_ids: nil, relation_type: nil) + Array.wrap(rel_ids).map do |i| + { "text" => i["@id"], "related_identifier_type" => validate_url(i["@id"]), - "relation_type" => "HasPart" } + "relation_type" => relation_type } end.select { |i| i["related_identifier_type"].present? } - - c = Array.wrap(citation).map do |i| - { - "text" => i["@id"], - "related_identifier_type" => validate_url(i["@id"]), - "relation_type" => "References" } - end.select { |i| i["related_identifier_type"].present? } - - ipo + hp + c end def insert_related_identifiers(xml) return xml unless rel_identifiers.present?