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, format_date, parse_date, parse_yaml

Constructor Details

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

Returns a new instance of Person.

Parameters:



80
81
82
83
84
85
86
# File 'lib/relaton_bib/person.rb', line 80

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>



70
71
72
# File 'lib/relaton_bib/person.rb', line 70

def affiliation
  @affiliation
end

#identifierArray<RelatonBib::PersonIdentifier>



73
74
75
# File 'lib/relaton_bib/person.rb', line 73

def identifier
  @identifier
end

#nameRelatonBib::FullName



67
68
69
# File 'lib/relaton_bib/person.rb', line 67

def name
  @name
end

Instance Method Details

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

Parameters:

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

Returns:

  • (String)


113
114
115
116
117
118
119
120
121
# File 'lib/relaton_bib/person.rb', line 113

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)


101
102
103
104
105
106
107
108
# File 'lib/relaton_bib/person.rb', line 101

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



91
92
93
94
95
96
97
98
# File 'lib/relaton_bib/person.rb', line 91

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