lib/bolognese/datacite_utils.rb in bolognese-1.0.3 vs lib/bolognese/datacite_utils.rb in bolognese-1.0.4

- old
+ new

@@ -74,18 +74,24 @@ xml.nameIdentifier(person["id"], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if person["id"].present? end def insert_titles(xml) xml.titles do - insert_title(xml) + Array.wrap(title).each do |tit| + if tit.is_a?(Hash) + t = tit + else + t = {} + t["text"] = tit + end + + attributes = { 'lang' => t["lang"], 'titleType' => t["title_type"] }.compact + xml.title(t["text"], attributes) + end end end - def insert_title(xml) - xml.title(title) - end - def insert_publisher(xml) xml.publisher(publisher || periodical && periodical["title"]) end def insert_publication_year(xml) @@ -144,11 +150,24 @@ def insert_subjects(xml) return xml unless keywords.present? xml.subjects do keywords.each do |subject| - xml.subject(subject) + if subject.is_a?(String) then + # If we've been read from somewhere that it was just a string output that + xml.subject(subject) + else + # Otherwise we'll assume a hash and therefore find/add attributes as appropriate + subject_node = xml.subject(subject['text']) + if subject["subject_scheme"].present? then + subject_node['subjectScheme'] = subject["subject_scheme"] + end + + if subject["scheme_uri"].present? then + subject_node['schemeURI'] = subject["scheme_uri"] + end + end end end end def insert_version(xml) @@ -182,11 +201,13 @@ l = {} l["name"] = lic l["id"] = normalize_id(lic) end - xml.rights(l["name"], { 'rightsURI' => l["id"] }.compact) + attributes = { 'rightsURI' => l["id"] }.compact + + xml.rights(l["name"], attributes) end end end def insert_descriptions(xml) @@ -204,10 +225,12 @@ d = {} d["text"] = des d["type"] = "Abstract" end - xml.description(d["text"], 'descriptionType' => d["type"] || "Abstract") + attributes = { 'lang' => d["lang"], 'descriptionType' => d["type"] || "Abstract" }.compact + + xml.description(d["text"], attributes) end end end def root_attributes