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

parse_date

Constructor Details

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

Returns a new instance of Person.

Parameters:



179
180
181
182
183
184
185
# File 'lib/relaton_bib/person.rb', line 179

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

Instance Attribute Details

#affiliationArray<RelatonBib::Affiliation>



169
170
171
# File 'lib/relaton_bib/person.rb', line 169

def affiliation
  @affiliation
end

#identifierArray<RelatonBib::PersonIdentifier>



172
173
174
# File 'lib/relaton_bib/person.rb', line 172

def identifier
  @identifier
end

#nameRelatonBib::FullName



166
167
168
# File 'lib/relaton_bib/person.rb', line 166

def name
  @name
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


212
213
214
215
216
217
218
219
220
# File 'lib/relaton_bib/person.rb', line 212

def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
  pref = prefix.sub /\*$/, "person"
  out = count > 1 ? "#{pref}::\n" : ""
  out += name.to_asciibib pref
  affiliation.each { |af| out += af.to_asciibib pref, affiliation.size }
  identifier.each { |id| out += id.to_asciibib pref, identifier.size }
  out += super pref
  out
end

#to_hashHash

Returns:

  • (Hash)


200
201
202
203
204
205
206
207
# File 'lib/relaton_bib/person.rb', line 200

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

#to_xml(**opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :lang (String, Symbol)

    language



190
191
192
193
194
195
196
197
# File 'lib/relaton_bib/person.rb', line 190

def to_xml(**opts)
  opts[:builder].person do |builder|
    name.to_xml **opts
    affiliation.each { |a| a.to_xml **opts }
    identifier.each { |id| id.to_xml builder }
    contact.each { |contact| contact.to_xml builder }
  end
end