Class: RelatonBib::FullName

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

Overview

Person’s full name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ FullName

Returns a new instance of FullName.

Parameters:



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

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

  @surname      = args[:surname]
  @forenames    = args.fetch :forenames, []
  @initials     = args.fetch :initials, []
  @additions    = args.fetch :additions, []
  @prefix       = args.fetch :prefix, []
  @completename = args[:completename]
end

Instance Attribute Details

#additionsArray<RelatonBib::LocalizedString>

Returns:



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

def additions
  @additions
end

#completenameRelatonBib::LocalizedString (readonly)



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

def completename
  @completename
end

#forenamesArray<RelatonBib::LocalizedString>

Returns:



9
10
11
# File 'lib/relaton_bib/person.rb', line 9

def forenames
  @forenames
end

#initialsArray<RelatonBib::LocalizedString>

Returns:



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

def initials
  @initials
end

#prefixArray<RelatonBib::LocalizedString>

Returns:



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

def prefix
  @prefix
end

#surnameRelatonBib::LocalizedString



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

def surname
  @surname
end

Instance Method Details

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


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

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 } } 
      initials.each { |i| builder.initial { i.to_xml builder } }
      additions.each { |a| builder.addition { a.to_xml builder } }
      builder.surname { surname.to_xml builder }
      forenames.each { |f| builder.forename { f.to_xml builder } }
    end
  end
end