Class: RelatonBib::FullName
- Inherits:
-
Object
- Object
- RelatonBib::FullName
show all
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/person.rb
Overview
Constant Summary
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
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
20
21
22
|
# File 'lib/relaton_bib/person.rb', line 20
def addition
@addition
end
|
26
27
28
|
# File 'lib/relaton_bib/person.rb', line 26
def completename
@completename
end
|
11
12
13
|
# File 'lib/relaton_bib/person.rb', line 11
def forename
@forename
end
|
14
15
16
|
# File 'lib/relaton_bib/person.rb', line 14
def initial
@initial
end
|
23
24
25
|
# File 'lib/relaton_bib/person.rb', line 23
def prefix
@prefix
end
|
17
18
19
|
# File 'lib/relaton_bib/person.rb', line 17
def surname
@surname
end
|
Instance Method Details
#to_hash ⇒ Hash
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/relaton_bib/person.rb', line 63
def to_hash
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
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)
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
|