Module: OrcidClient::Author

Included in:
Notification, Work
Defined in:
lib/orcid_client/author.rb

Instance Method Summary collapse

Instance Method Details

#get_authors(authors) ⇒ Object

parse array of author strings into CSL format



21
22
23
# File 'lib/orcid_client/author.rb', line 21

def get_authors(authors)
  Array(authors).map { |author| get_one_author(author) }
end

#get_credit_name(author) ⇒ Object



48
49
50
# File 'lib/orcid_client/author.rb', line 48

def get_credit_name(author)
  [author['given'], author['family']].compact.join(' ').presence || author['literal']
end

#get_full_name(author) ⇒ Object



52
53
54
# File 'lib/orcid_client/author.rb', line 52

def get_full_name(author)
  [author['family'], author['given']].compact.join(', ')
end

#get_hashed_authors(authors) ⇒ Object

parse array of author hashes into CSL format



26
27
28
# File 'lib/orcid_client/author.rb', line 26

def get_hashed_authors(authors)
  Array(authors).map { |author| get_one_hashed_author(author) }
end

#get_name_identifier(author) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/orcid_client/author.rb', line 38

def get_name_identifier(author)
  name_identifier = author.fetch("nameIdentifier", nil)
  name_identifier_scheme = author.fetch("nameIdentifierScheme", "orcid").downcase
  if name_identifier.present? && name_identifier_scheme == "orcid"
    "http://orcid.org/#{name_identifier}"
  else
    nil
  end
end

#get_one_author(author) ⇒ Object

parse author string into CSL format



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/orcid_client/author.rb', line 6

def get_one_author(author)
  return "" if author.blank?

  names = Namae.parse(author)
  if names.present?
    name = names.first

    { "family" => name.family,
      "given" => name.given }.compact
  else
    { "literal" => author }
  end
end

#get_one_hashed_author(author) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/orcid_client/author.rb', line 30

def get_one_hashed_author(author)
  raw_name = author.fetch("creatorName", nil)

  author_hsh = get_one_author(raw_name)
  author_hsh["ORCID"] = get_name_identifier(author)
  author_hsh.compact
end