Class: Theoj::Author
- Inherits:
-
Object
- Object
- Theoj::Author
- Defined in:
- lib/theoj/author.rb
Constant Summary collapse
- AUTHOR_FOOTNOTE_REGEX =
/^[^\^]*/
Instance Attribute Summary collapse
-
#affiliation ⇒ Object
Returns the value of attribute affiliation.
-
#name ⇒ Object
Returns the value of attribute name.
-
#orcid ⇒ Object
Returns the value of attribute orcid.
Instance Method Summary collapse
- #citation_last_name ⇒ Object
- #given_name ⇒ Object
-
#initialize(name, orcid, index, affiliations_hash) ⇒ Author
constructor
Initialized with authors & affiliations block in the YAML header from an Open Journal paper e.g.
- #initials ⇒ Object
- #last_name ⇒ Object
- #middle_name ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name, orcid, index, affiliations_hash) ⇒ Author
Initialized with authors & affiliations block in the YAML header from an Open Journal paper e.g. https://joss.readthedocs.io/en/latest/submitting.html#example-paper-and-bibliography
13 14 15 16 17 |
# File 'lib/theoj/author.rb', line 13 def initialize(name, orcid, index, affiliations_hash) parse_name name @orcid = validate_orcid orcid @affiliation = build_affiliation_string(index, affiliations_hash) end |
Instance Attribute Details
#affiliation ⇒ Object
Returns the value of attribute affiliation.
7 8 9 |
# File 'lib/theoj/author.rb', line 7 def affiliation @affiliation end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/theoj/author.rb', line 5 def name @name end |
#orcid ⇒ Object
Returns the value of attribute orcid.
6 7 8 |
# File 'lib/theoj/author.rb', line 6 def orcid @orcid end |
Instance Method Details
#citation_last_name ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/theoj/author.rb', line 42 def citation_last_name return @literal_name unless @literal_name.to_s.strip.empty? name_parts = [@non_dropping_particle, @surname, @suffix].map do |part| part.to_s.strip end.reject(&:empty?) return @surname if name_parts.empty? name_parts.join(" ") end |
#given_name ⇒ Object
19 20 21 22 23 |
# File 'lib/theoj/author.rb', line 19 def given_name return nil if @given_names.to_s.strip.empty? @given_names.to_s.split(/\s+/).first end |
#initials ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/theoj/author.rb', line 54 def initials initials_parts = [] first_name = given_name.to_s initials_parts << "#{first_name[0]}." unless first_name.empty? middle_for_initials = @middle_names.to_s.strip.empty? ? @dropping_particle : @middle_names unless middle_for_initials.to_s.strip.empty? initials_parts.concat(middle_for_initials.split(/\s+/).map { |v| "#{v[0]}." }) end initials_parts.compact.join(" ") end |
#last_name ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/theoj/author.rb', line 31 def last_name particle = @non_dropping_particle.to_s.strip.empty? ? @dropping_particle : @non_dropping_particle name_parts = [particle, @surname, @suffix].map do |part| part.to_s.strip end.reject(&:empty?) fallback = @surname || @literal_name name_parts.empty? ? fallback : name_parts.join(" ") end |
#middle_name ⇒ Object
25 26 27 28 29 |
# File 'lib/theoj/author.rb', line 25 def middle_name return nil if @middle_names.to_s.strip.empty? @middle_names end |
#to_h ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/theoj/author.rb', line 67 def to_h { given_name: given_name, middle_name: middle_name, last_name: last_name, orcid: orcid, affiliation: affiliation } end |