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

Methods included from Config

#configuration, #configure

Constructor Details

#initialize(name:, **args) ⇒ Person

Returns a new instance of Person.

Parameters:



84
85
86
87
88
89
90
91
# File 'lib/relaton_bib/person.rb', line 84

def initialize(name:, **args)
  contact = args[:contact] || []
  super(contact: contact, url: args[:url])
  @name        = name
  @credential  = args[:credential] || []
  @affiliation = args[:affiliation] || []
  @identifier = args[:identifier] || []
end

Instance Attribute Details

#affiliationArray<RelatonBib::Affiliation>



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

def affiliation
  @affiliation
end

#credentialArray<String> (readonly)

Returns:



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

def credential
  @credential
end

#identifierArray<RelatonBib::PersonIdentifier>



76
77
78
# File 'lib/relaton_bib/person.rb', line 76

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)


118
119
120
121
122
123
124
125
126
127
# File 'lib/relaton_bib/person.rb', line 118

def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
  pref = prefix.sub(/\*$/, "person")
  out = count > 1 ? "#{pref}::\n" : ""
  out += name.to_asciibib pref
  credential.each { |c| out += "#{pref}.credential:: #{c}\n" }
  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)


107
108
109
110
111
112
113
# File 'lib/relaton_bib/person.rb', line 107

def to_hash # rubocop:disable Metrics/AbcSize
  hash = { "name" => name.to_hash }
  hash["credential"] = credential if credential.any?
  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(**opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (**opts):

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

    XML builder

  • :lang (String, Symbol)

    language



96
97
98
99
100
101
102
103
104
# File 'lib/relaton_bib/person.rb', line 96

def to_xml(**opts) # rubocop:disable Metrics/AbcSize
  opts[:builder].person do |builder|
    name.to_xml(**opts)
    credential.each { |c| builder.credential c }
    affiliation.each { |a| a.to_xml(**opts) }
    identifier.each { |id| id.to_xml builder }
    contact.each { |contact| contact.to_xml builder }
  end
end