Module: Commonmeta::Writers::CffWriter
- Included in:
- MetadataUtils
- Defined in:
- lib/commonmeta/writers/cff_writer.rb
Instance Method Summary collapse
Instance Method Details
#cff ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/commonmeta/writers/cff_writer.rb', line 6 def cff # return nil unless valid? || show_errors # only use CFF for software return nil unless %w[Software Collection].include?(type) title = parse_attributes(titles, content: 'title', first: true) hsh = { 'cff-version' => '1.2.0', 'message' => "If you use #{title} in your research, please cite it using the following metadata", 'doi' => normalize_doi(id), 'repository-code' => url, 'title' => title, 'authors' => write_cff_creators(creators), 'abstract' => parse_attributes(descriptions, content: 'description', first: true), 'version' => version, 'keywords' => if subjects.present? Array.wrap(subjects).map do |k| parse_attributes(k, content: 'subject', first: true) end end, 'date-released' => date['published'], 'license' => license.to_h['id'], 'references' => { 'identifiers' => Array.wrap(references).map do |r| write_cff_reference(r) end } }.compact hsh.to_yaml end |
#write_cff_creators(creators) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/commonmeta/writers/cff_writer.rb', line 37 def write_cff_creators(creators) Array.wrap(creators).map do |a| if a['givenName'].present? || a['id'].present? { 'given-names' => a['givenName'], 'family-names' => a['familyName'], 'orcid' => a['id'], 'affiliation' => parse_attributes(a['affiliation'], content: 'name', first: true) }.compact else { 'name' => a['name'] } end end end |
#write_cff_reference(reference) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/commonmeta/writers/cff_writer.rb', line 51 def write_cff_reference(reference) return nil if reference.blank? url = reference['url'] doi = reference['doi'] value = doi.present? ? doi_from_url(doi) : url type = doi.present? ? 'doi' : 'url' { 'type' => type, 'value' => value }.compact end |