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
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/relaton_bib/full_name.rb', line 26
def initialize(**args) unless args[:surname] || args[:completename]
raise ArgumentError, "Should be given :surname or :completename"
end
@surname = args[:surname]
@abbreviation = args[:abbreviation]
@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
13
14
15
|
# File 'lib/relaton_bib/full_name.rb', line 13
def abbreviation
@abbreviation
end
|
10
11
12
|
# File 'lib/relaton_bib/full_name.rb', line 10
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
|
10
11
12
|
# File 'lib/relaton_bib/full_name.rb', line 10
def prefix
@prefix
end
|
13
14
15
|
# File 'lib/relaton_bib/full_name.rb', line 13
def surname
@surname
end
|
Instance Method Details
#==(other) ⇒ Object
40
41
42
43
|
# File 'lib/relaton_bib/full_name.rb', line 40
def ==(other)
surname == other.surname && abbreviation == other.abbreviation && completename == other.completename &&
forename == other.forename && initials == other.initials && addition == other.addition && prefix == other.prefix
end
|
#to_asciibib(pref) ⇒ String
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/relaton_bib/full_name.rb', line 87
def to_asciibib(pref) prf = pref.empty? ? pref : "#{pref}."
prf += "name"
out = ""
out += abbreviation.to_asciibib "#{prf}.abbreviation" if abbreviation
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
83
|
# File 'lib/relaton_bib/full_name.rb', line 70
def to_hash hash = {}
hash["abbreviation"] = abbreviation.to_hash if abbreviation
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
48
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 48
def to_xml(**opts) opts[:builder].name do |builder|
builder.abbreviation { abbreviation.to_xml builder } if abbreviation
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
|