Module: Bolognese::AuthorUtils
- Included in:
- Metadata
- Defined in:
- lib/bolognese/author_utils.rb
Instance Method Summary collapse
- #authors_as_string(authors) ⇒ Object
- #cleanup_author(author) ⇒ Object
-
#get_authors(authors) ⇒ Object
parse array of author strings into CSL format.
-
#get_name_identifier(author) ⇒ Object
parse nameIdentifier from DataCite.
- #get_one_author(author) ⇒ Object
- #is_personal_name?(author) ⇒ Boolean
Instance Method Details
#authors_as_string(authors) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/bolognese/author_utils.rb', line 99 def () Array.wrap().map do |a| if a["familyName"].present? [a["familyName"], a["givenName"]].join(", ") elsif a["type"] == "Person" a["name"] elsif a["name"].present? "{" + a["name"] + "}" end end.join(" and ").presence end |
#cleanup_author(author) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bolognese/author_utils.rb', line 56 def () # detect pattern "Smith J.", but not "Smith, John K." = .gsub(/[[:space:]]([A-Z]\.)?(-?[A-Z]\.)$/, ', \1\2') unless .include?(",") # remove spaces around hyphens = .gsub(" - ", "-") # remove text in parentheses = .sub(/\s*\(.+\)\s*/, '') # titleize strings # remove non-standard space characters .my_titleize .gsub(/[[:space:]]/, ' ') end |
#get_authors(authors) ⇒ Object
parse array of author strings into CSL format
83 84 85 |
# File 'lib/bolognese/author_utils.rb', line 83 def () Array.wrap().map { || () }.unwrap end |
#get_name_identifier(author) ⇒ Object
parse nameIdentifier from DataCite
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bolognese/author_utils.rb', line 88 def get_name_identifier() name_identifier_scheme_uri = .dig("nameIdentifier", "schemeURI") || "http://orcid.org/" name_identifier_scheme_uri << '/' unless name_identifier_scheme_uri.end_with?('/') name_identifier = .dig("nameIdentifier", "__content__") name_identifier = validate_orcid(name_identifier) if name_identifier_scheme_uri == "http://orcid.org/" return nil if name_identifier.blank? || name_identifier_scheme_uri.blank? name_identifier_scheme_uri + name_identifier end |
#get_one_author(author) ⇒ Object
5 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bolognese/author_utils.rb', line 5 def () type = .fetch("type", nil) && .fetch("type").titleize id = .fetch("id", nil).presence || get_name_identifier() name = .fetch("creatorName", nil) || .fetch("contributorName", nil) || .fetch("name", nil) if name.include?("; ") = name.split("; ").map do |name| { "type" => .fetch("type", nil), "id" => .fetch("id", nil), "name" => name }.compact end return () end name = (name) given_name = .fetch("givenName", nil) family_name = .fetch("familyName", nil) = { "type" => type || "Person", "id" => id, "name" => name, "givenName" => given_name, "familyName" => family_name }.compact return if family_name.present? if is_personal_name?() names = Namae.parse(name) parsed_name = names.first if parsed_name.present? given_name = parsed_name.given family_name = parsed_name.family name = [given_name, family_name].join(" ") else given_name = nil family_name = nil end { "type" => "Person", "id" => id, "name" => name, "givenName" => given_name, "familyName" => family_name }.compact else { "type" => type, "name" => name }.compact end end |
#is_personal_name?(author) ⇒ Boolean
72 73 74 75 76 77 78 79 80 |
# File 'lib/bolognese/author_utils.rb', line 72 def is_personal_name?() return false if .fetch("type", "").downcase == "organization" return true if .fetch("id", "").start_with?("http://orcid.org") || .fetch("familyName", "").present? || (.fetch("name", "").include?(",") && .fetch("name", "").exclude?(";")) || name_detector.name_exists?(.fetch("name", "").split(" ").first) false end |