Class: RelatonBib::FullName

Inherits:
Object show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/person.rb

Overview

Person’s full name

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(**args) ⇒ FullName

Returns a new instance of FullName.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/relaton_bib/person.rb', line 34

def initialize(**args)
  unless args[:surname] || args[:completename]
    raise ArgumentError, "Should be given :surname or :completename"
  end

  @surname      = args[:surname]
  @forename     = args.fetch :forename, []
  @initial      = args.fetch :initial, []
  @addition     = args.fetch :addition, []
  @prefix       = args.fetch :prefix, []
  @completename = args[:completename]
end

Instance Attribute Details

#additionArray<RelatonBib::LocalizedString>



20
21
22
# File 'lib/relaton_bib/person.rb', line 20

def addition
  @addition
end

#completenameRelatonBib::LocalizedString (readonly)



26
27
28
# File 'lib/relaton_bib/person.rb', line 26

def completename
  @completename
end

#forenameArray<RelatonBib::LocalizedString>



11
12
13
# File 'lib/relaton_bib/person.rb', line 11

def forename
  @forename
end

#initialArray<RelatonBib::LocalizedString>



14
15
16
# File 'lib/relaton_bib/person.rb', line 14

def initial
  @initial
end

#prefixArray<RelatonBib::LocalizedString>



23
24
25
# File 'lib/relaton_bib/person.rb', line 23

def prefix
  @prefix
end

#surnameRelatonBib::LocalizedString



17
18
19
# File 'lib/relaton_bib/person.rb', line 17

def surname
  @surname
end

Instance Method Details

#to_asciibib(pref) ⇒ String

Parameters:

  • pref (String)

Returns:

  • (String)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/relaton_bib/person.rb', line 76

def to_asciibib(pref) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
  prf = pref.empty? ? pref : pref + "."
  prf += "name."
  out = forename.map do |fn|
    fn.to_asciibib "#{prf}forename", forename.size
  end.join
  initial.each { |i| out += i.to_asciibib "#{prf}initial", initial.size }
  out += surname.to_asciibib "#{prf}surname" if surname
  addition.each do |ad|
    out += ad.to_asciibib "#{prf}addition", addition.size
  end
  prefix.each { |pr| out += pr.to_asciibib "#{prf}prefix", prefix.size }
  out += completename.to_asciibib "#{prf}completename" if completename
  out
end

#to_hashHash

Returns:

  • (Hash)


63
64
65
66
67
68
69
70
71
72
# File 'lib/relaton_bib/person.rb', line 63

def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  hash = {}
  hash["forename"] = single_element_array(forename) if forename&.any?
  hash["initial"] = single_element_array(initial) if initial&.any?
  hash["surname"] = surname.to_hash if surname
  hash["addition"] = single_element_array(addition) if addition&.any?
  hash["prefix"] = single_element_array(prefix) if prefix&.any?
  hash["completename"] = completename.to_hash if completename
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/relaton_bib/person.rb', line 48

def to_xml(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  builder.name do
    if completename
      builder.completename { completename.to_xml builder }
    else
      prefix.each { |p| builder.prefix { p.to_xml builder } }
      forename.each { |f| builder.forename { f.to_xml builder } }
      initial.each { |i| builder.initial { i.to_xml builder } }
      builder.surname { surname.to_xml builder }
      addition.each { |a| builder.addition { a.to_xml builder } }
    end
  end
end