Class: RelatonBib::Person

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

Overview

Person class.

Instance Attribute Summary collapse

Attributes inherited from Contributor

#contact, #uri

Instance Method Summary collapse

Methods inherited from Contributor

#url

Constructor Details

#initialize(name:, affiliation: [], contact: [], identifier: []) ⇒ Person

Returns a new instance of Person.

Parameters:



140
141
142
143
144
145
# File 'lib/relaton_bib/person.rb', line 140

def initialize(name:, affiliation: [], contact: [], identifier: [])
  super(contact: contact)
  @name        = name
  @affiliation = affiliation
  @identifier = identifier
end

Instance Attribute Details

#affiliationArray<RelatonBib::Affilation>

Returns:



131
132
133
# File 'lib/relaton_bib/person.rb', line 131

def affiliation
  @affiliation
end

#identifierArray<RelatonBib::PersonIdentifier>

Returns:



134
135
136
# File 'lib/relaton_bib/person.rb', line 134

def identifier
  @identifier
end

#nameRelatonBib::FullName



128
129
130
# File 'lib/relaton_bib/person.rb', line 128

def name
  @name
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


158
159
160
161
162
163
# File 'lib/relaton_bib/person.rb', line 158

def to_hash
  hash = { name: name.to_hash }
  hash[:affiliation] = affiliation.map(&:to_hash) if affiliation&.any?
  hash[:identifier] = identifier.map(&:to_hash) if identifier&.any?
  { person: hash.merge(super) }
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


148
149
150
151
152
153
154
155
# File 'lib/relaton_bib/person.rb', line 148

def to_xml(builder)
  builder.person do
    name.to_xml builder
    affiliation.each { |a| a.to_xml builder }
    identifier.each { |id| id.to_xml builder }
    contact.each { |contact| contact.to_xml builder }
  end
end