Class: RelatonBib::FullName
Overview
Constant Summary
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from RelatonBib
array, format_date, grammar_hash, parse_date, parse_yaml
Methods included from Config
#configuration, #configure
Constructor Details
#initialize(**args) ⇒ FullName
Initialize FullName instance
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/relaton_bib/full_name.rb', line 33
def initialize(**args)
unless args[:surname] || args[:completename]
raise ArgumentError, "Should be given :surname or :completename"
end
@surname = args[:surname]
@forename = args.fetch :forename, []
@initials = args[:initials].is_a?(String) ? LocalizedString.new(args[:initials]) : args[:initials]
@addition = args.fetch :addition, []
@prefix = args.fetch :prefix, []
@completename = args[:completename]
end
|
Instance Attribute Details
16
17
18
|
# File 'lib/relaton_bib/full_name.rb', line 16
def addition
@addition
end
|
13
14
15
|
# File 'lib/relaton_bib/full_name.rb', line 13
def completename
@completename
end
|
7
8
9
|
# File 'lib/relaton_bib/full_name.rb', line 7
def forename
@forename
end
|
10
11
12
|
# File 'lib/relaton_bib/full_name.rb', line 10
def initials
@initials
end
|
19
20
21
|
# File 'lib/relaton_bib/full_name.rb', line 19
def prefix
@prefix
end
|
13
14
15
|
# File 'lib/relaton_bib/full_name.rb', line 13
def surname
@surname
end
|
Instance Method Details
#to_asciibib(pref) ⇒ String
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/relaton_bib/full_name.rb', line 86
def to_asciibib(pref) prf = pref.empty? ? pref : "#{pref}."
prf += "name"
given = "#{pref}.given"
out = forename.map do |fn|
fn.to_asciibib given, forename.size
end.join
out += initials.to_asciibib "#{given}.formatted-initials" if initials
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_hash ⇒ Hash
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/relaton_bib/full_name.rb', line 70
def to_hash hash = {}
if forename.any? || initials
hash["given"] = {}
hash["given"]["forename"] = single_element_array(forename) if forename&.any?
hash["given"]["formatted_initials"] = initials.to_hash if initials
end
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(**opts) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/relaton_bib/full_name.rb', line 49
def to_xml(**opts) opts[:builder].name do |builder|
if completename
builder.completename { completename.to_xml builder }
else
pref = prefix.select { |p| p.language&.include? opts[:lang] }
pref = prefix unless pref.any?
pref.each { |p| builder.prefix { p.to_xml builder } }
frnm = forename.select { |f| f.language&.include? opts[:lang] }
frnm = forename unless frnm.any?
frnm.each { |f| f.to_xml builder }
builder.send(:"formatted-initials") { initials.to_xml builder } if initials
builder.surname { surname.to_xml builder }
addn = addition.select { |a| a.language&.include? opts[:lang] }
addn = addition unless addn.any?
addn.each { |a| builder.addition { a.to_xml builder } }
end
end
end
|