Module: Briard::Writers::CffWriter

Included in:
MetadataUtils
Defined in:
lib/briard/writers/cff_writer.rb

Instance Method Summary collapse

Instance Method Details

#cffObject



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
# File 'lib/briard/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?(types['resourceTypeGeneral'])

  title = parse_attributes(titles, content: 'title', first: true)

  hsh = {
    'cff-version' => '1.2.0',
    'message' => "If you use #{title} in your work, please cite it using the following metadata",
    'doi' => normalize_doi(doi),
    'repository-code' => url,
    'title' => parse_attributes(titles, content: 'title', first: true),
    'authors' => write_cff_creators(creators),
    'abstract' => parse_attributes(descriptions, content: 'description', first: true),
    'version' => version_info,
    'keywords' => if subjects.present?
                    Array.wrap(subjects).map do |k|
                      parse_attributes(k, content: 'subject', first: true)
                    end
                  end,
    'date-released' => get_date(dates, 'Issued') || publication_year,
    'license' => Array.wrap(rights_list).map { |l| l['rightsIdentifier'] }.compact.unwrap,
    'references' => write_references(related_identifiers)
  }.compact
  hsh.to_yaml
end

#write_cff_creators(creators) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/briard/writers/cff_writer.rb', line 35

def write_cff_creators(creators)
  Array.wrap(creators).map do |a|
    if a['givenName'].present? || a['nameIdentifiers'].present?
      { 'given-names' => a['givenName'],
        'family-names' => a['familyName'],
        'orcid' => parse_attributes(a['nameIdentifiers'], content: 'nameIdentifier',
                                                          first: true),
        'affiliation' => parse_attributes(a['affiliation'], content: 'name',
                                                            first: true) }.compact
    else
      { 'name' => a['name'] }
    end
  end
end

#write_references(related_identifiers) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/briard/writers/cff_writer.rb', line 50

def write_references(related_identifiers)
  return nil if related_identifiers.blank?

  { 'identifiers' =>
  Array.wrap(related_identifiers).map do |r|
    {
      'type' => r['relatedIdentifierType'].downcase,
      'value' => r['relatedIdentifierType'] == 'DOI' ? doi_from_url(r['relatedIdentifier']) : r['relatedIdentifier']
    }
  end }
end