Module: Bolognese::DataciteUtils
- Included in:
- Metadata
- Defined in:
- lib/bolognese/datacite_utils.rb
Instance Method Summary collapse
-
#datacite_errors ⇒ Object
def datacite datacite_xml end.
- #datacite_xml ⇒ Object
- #insert_alternate_identifiers(xml) ⇒ Object
- #insert_contributors(xml) ⇒ Object
- #insert_creators(xml) ⇒ Object
- #insert_date(xml, date, date_type) ⇒ Object
- #insert_dates(xml) ⇒ Object
- #insert_descriptions(xml) ⇒ Object
- #insert_funding_reference(xml, funding_reference) ⇒ Object
- #insert_funding_references(xml) ⇒ Object
- #insert_identifier(xml) ⇒ Object
- #insert_person(xml, person, type) ⇒ Object
- #insert_publication_year(xml) ⇒ Object
- #insert_publisher(xml) ⇒ Object
- #insert_related_identifiers(xml) ⇒ Object
- #insert_resource_type(xml) ⇒ Object
- #insert_rights_list(xml) ⇒ Object
- #insert_subjects(xml) ⇒ Object
- #insert_title(xml) ⇒ Object
- #insert_titles(xml) ⇒ Object
- #insert_version(xml) ⇒ Object
- #insert_work(xml) ⇒ Object
- #rel_identifier ⇒ Object
- #resource_type ⇒ Object
- #root_attributes ⇒ Object
- #schema ⇒ Object
Instance Method Details
#datacite_errors ⇒ Object
def datacite
datacite_xml
end
21 22 23 24 25 |
# File 'lib/bolognese/datacite_utils.rb', line 21 def datacite_errors schema.validate(Nokogiri::XML(datacite, nil, 'UTF-8')).map { |error| error.to_s }.unwrap rescue Nokogiri::XML::SyntaxError => e e. end |
#datacite_xml ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/bolognese/datacite_utils.rb', line 9 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 |
#insert_alternate_identifiers(xml) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/bolognese/datacite_utils.rb', line 110 def insert_alternate_identifiers(xml) return xml unless alternate_name.present? xml.alternateIdentifiers do Array.wrap(alternate_name).each do |alt| xml.alternateIdentifier(alt["name"], 'alternateIdentifierType' => alt["type"]) end end end |
#insert_contributors(xml) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bolognese/datacite_utils.rb', line 59 def insert_contributors(xml) return xml unless editor.present? xml.contributors do Array.wrap(editor).each do |contributor| xml.contributor("contributorType" => "Editor") do insert_person(xml, contributor, "contributor") end end end end |
#insert_creators(xml) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bolognese/datacite_utils.rb', line 49 def insert_creators(xml) xml.creators do Array.wrap().each do |creator| xml.creator do insert_person(xml, creator, "creator") end end end end |
#insert_date(xml, date, date_type) ⇒ Object
128 129 130 |
# File 'lib/bolognese/datacite_utils.rb', line 128 def insert_date(xml, date, date_type) xml.date(date, 'dateType' => date_type) end |
#insert_dates(xml) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/bolognese/datacite_utils.rb', line 120 def insert_dates(xml) xml.dates do insert_date(xml, date_created, 'Created') if date_created.present? insert_date(xml, date_published, 'Issued') if date_published.present? insert_date(xml, date_modified, 'Updated') if date_modified.present? end end |
#insert_descriptions(xml) ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'lib/bolognese/datacite_utils.rb', line 196 def insert_descriptions(xml) return xml unless description.present? xml.descriptions do Array.wrap(description).each do |des| xml.description(des["text"], 'descriptionType' => des["type"] || "Abstract") end end end |
#insert_funding_reference(xml, funding_reference) ⇒ Object
144 145 146 147 |
# File 'lib/bolognese/datacite_utils.rb', line 144 def insert_funding_reference(xml, funding_reference) xml.funderName(funding_reference["name"]) if funding_reference["name"].present? xml.funderIdentifier(funding_reference["id"], "funderIdentifierType" => "Crossref Funder ID") if funding_reference["id"].present? end |
#insert_funding_references(xml) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/bolognese/datacite_utils.rb', line 132 def insert_funding_references(xml) return xml unless Array.wrap(funding).present? xml.fundingReferences do Array.wrap(funding).each do |funding_reference| xml.fundingReference do insert_funding_reference(xml, funding_reference) end end end end |
#insert_identifier(xml) ⇒ Object
45 46 47 |
# File 'lib/bolognese/datacite_utils.rb', line 45 def insert_identifier(xml) xml.identifier(doi, 'identifierType' => "DOI") end |
#insert_person(xml, person, type) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/bolognese/datacite_utils.rb', line 71 def insert_person(xml, person, type) person_name = person["familyName"].present? ? [person["familyName"], person["givenName"]].compact.join(", ") : person["name"] xml.send(type + "Name", person_name) xml.givenName(person["givenName"]) if person["givenName"].present? xml.familyName(person["familyName"]) if person["familyName"].present? xml.nameIdentifier(person["id"], 'schemeURI' => 'http://orcid.org/', 'nameIdentifierScheme' => 'ORCID') if person["id"].present? end |
#insert_publication_year(xml) ⇒ Object
94 95 96 |
# File 'lib/bolognese/datacite_utils.rb', line 94 def insert_publication_year(xml) xml.publicationYear(publication_year) end |
#insert_publisher(xml) ⇒ Object
90 91 92 |
# File 'lib/bolognese/datacite_utils.rb', line 90 def insert_publisher(xml) xml.publisher(publisher) end |
#insert_related_identifiers(xml) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/bolognese/datacite_utils.rb', line 173 def (xml) return xml unless rel_identifier.present? xml. do rel_identifier.each do || attributes = { 'relatedIdentifierType' => ["related_identifier_type"], 'relationType' => ["relation_type"] }.compact xml.(["__content__"], attributes) end end end |
#insert_resource_type(xml) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/bolognese/datacite_utils.rb', line 103 def insert_resource_type(xml) return xml unless type.present? xml.resourceType(resource_type["__content__"], 'resourceTypeGeneral' => resource_type["resource_type_general"]) end |
#insert_rights_list(xml) ⇒ Object
186 187 188 189 190 191 192 193 194 |
# File 'lib/bolognese/datacite_utils.rb', line 186 def insert_rights_list(xml) return xml unless license.present? xml.rightsList do Array.wrap(license).each do |lic| xml.rights(lic["name"], 'rightsURI' => lic["id"]) end end end |
#insert_subjects(xml) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/bolognese/datacite_utils.rb', line 149 def insert_subjects(xml) return xml unless keywords.present? xml.subjects do keywords.each do |subject| xml.subject(subject) end end end |
#insert_title(xml) ⇒ Object
86 87 88 |
# File 'lib/bolognese/datacite_utils.rb', line 86 def insert_title(xml) xml.title(title) end |
#insert_titles(xml) ⇒ Object
80 81 82 83 84 |
# File 'lib/bolognese/datacite_utils.rb', line 80 def insert_titles(xml) xml.titles do insert_title(xml) end end |
#insert_version(xml) ⇒ Object
159 160 161 162 163 |
# File 'lib/bolognese/datacite_utils.rb', line 159 def insert_version(xml) return xml unless version.present? xml.version(version) end |
#insert_work(xml) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bolognese/datacite_utils.rb', line 27 def insert_work(xml) insert_identifier(xml) insert_creators(xml) insert_titles(xml) insert_publisher(xml) insert_publication_year(xml) insert_resource_type(xml) insert_alternate_identifiers(xml) insert_subjects(xml) insert_contributors(xml) insert_funding_references(xml) insert_dates(xml) (xml) insert_version(xml) insert_rights_list(xml) insert_descriptions(xml) end |
#rel_identifier ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/bolognese/datacite_utils.rb', line 165 def rel_identifier Array.wrap().map do |r| { "__content__" => r["id"] || r["issn"], "related_identifier_type" => r["issn"].present? ? "ISSN" : validate_url(r["id"]), "relation_type" => r["relationType"] }.compact end end |
#resource_type ⇒ Object
98 99 100 101 |
# File 'lib/bolognese/datacite_utils.rb', line 98 def resource_type { "resource_type_general" => Metadata::SO_TO_DC_TRANSLATIONS[type] || "Other", "__content__" => additional_type || type } end |
#root_attributes ⇒ Object
206 207 208 209 210 |
# File 'lib/bolognese/datacite_utils.rb', line 206 def root_attributes { :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', :'xsi:schemaLocation' => 'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd', :'xmlns' => 'http://datacite.org/schema/kernel-4' } end |
#schema ⇒ Object
3 4 5 6 7 |
# File 'lib/bolognese/datacite_utils.rb', line 3 def schema kernel = schema_version.split("/").last || "kernel-4.0" filepath = File.("../../../resources/#{kernel}/metadata.xsd", __FILE__) Nokogiri::XML::Schema(open(filepath)) end |