17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/briard/readers/cff_reader.rb', line 17
def read_cff(string: nil, **options)
read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
:sandbox, :validate, :ra))
meta = string.is_a?(String) ? Psych.safe_load(string, permitted_classes: [Date]) : string
identifiers = Array.wrap(meta.fetch('identifiers', nil)).map do |r|
r = normalize_id(r) if r.is_a?(String)
if r.is_a?(String) && URI(r).host != 'doi.org'
{ 'identifierType' => 'URL', 'identifier' => r }
elsif r.is_a?(Hash)
{ 'identifierType' => get_identifier_type(r['propertyID']), 'identifier' => r['value'] }
end
end.compact.uniq
id = normalize_id(options[:doi] || meta.fetch('doi',
nil) || Array.wrap(meta.fetch('identifiers', nil)).find do |i|
i['type'] == 'doi'
end.fetch('value', nil))
url = normalize_id(meta.fetch('repository-code', nil))
creators = cff_creators(Array.wrap(meta.fetch('authors', nil)))
dates = []
if meta.fetch('date-released', nil).present?
dates << { 'date' => meta.fetch('date-released', nil).iso8601, 'dateType' => 'Issued' }
end
publication_year = meta.fetch('date-released').iso8601[0..3] if meta.fetch('date-released',
nil).present?
publisher = url.to_s.starts_with?('https://github.com') ? 'GitHub' : nil
state = meta.present? || read_options.present? ? 'findable' : 'not_found'
types = {
'resourceTypeGeneral' => 'Software',
'resourceType' => nil,
'schemaOrg' => 'SoftwareSourceCode',
'citeproc' => 'article-journal',
'bibtex' => 'misc',
'ris' => 'COMP'
}.compact
subjects = Array.wrap(meta.fetch('keywords', nil)).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum
end
titles = if meta.fetch('title', nil).present?
[{ 'title' => meta.fetch('title', nil) }]
else
[]
end
related_identifiers = Array.wrap(cff_references(meta.fetch('references', nil)))
rights_list = if meta.fetch('license', nil).present?
[hsh_to_spdx('rightsIdentifier' => meta.fetch('license'))]
end
{ 'id' => id,
'types' => types,
'identifiers' => identifiers,
'doi' => doi_from_url(id),
'url' => url,
'titles' => titles,
'creators' => creators,
'publisher' => publisher,
'related_identifiers' => related_identifiers,
'dates' => dates,
'publication_year' => publication_year,
'descriptions' => if meta.fetch('abstract', nil).present?
[{ 'description' => sanitize(meta.fetch('abstract')),
'descriptionType' => 'Abstract' }]
end,
'rights_list' => rights_list,
'version_info' => meta.fetch('version', nil),
'subjects' => subjects,
'state' => state }.merge(read_options)
end
|