Class: RelatonBib::Person

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

Overview

Person class.

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Attributes inherited from Contributor

#contact, #uri

Instance Method Summary collapse

Methods inherited from Contributor

#url

Methods included from RelatonBib

array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash

Constructor Details

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

Returns a new instance of Person.

Parameters:



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

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

Instance Attribute Details

#affiliationArray<RelatonBib::Affilation>

Returns:



124
125
126
# File 'lib/relaton_bib/person.rb', line 124

def affiliation
  @affiliation
end

#identifierArray<RelatonBib::PersonIdentifier>

Returns:



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

def identifier
  @identifier
end

#nameRelatonBib::FullName



121
122
123
# File 'lib/relaton_bib/person.rb', line 121

def name
  @name
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


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

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

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


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

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