Class: Theoj::Author

Inherits:
Object
  • Object
show all
Defined in:
lib/theoj/author.rb

Constant Summary collapse

AUTHOR_FOOTNOTE_REGEX =
/^[^\^]*/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#affiliationObject

Returns the value of attribute affiliation.



7
8
9
# File 'lib/theoj/author.rb', line 7

def affiliation
  @affiliation
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/theoj/author.rb', line 5

def name
  @name
end

#orcidObject

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_nameObject



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_nameObject



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

#initialsObject



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_nameObject



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_nameObject



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_hObject



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