Class: RelatonBib::Person
- Inherits:
-
Contributor
- Object
- Contributor
- RelatonBib::Person
- Defined in:
- lib/relaton_bib/person.rb
Overview
Person class.
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #affiliation ⇒ Array<RelatonBib::Affiliation>
- #identifier ⇒ Array<RelatonBib::PersonIdentifier>
- #name ⇒ RelatonBib::FullName
Attributes inherited from Contributor
Instance Method Summary collapse
-
#initialize(name:, affiliation: [], contact: [], identifier: [], url: nil) ⇒ Person
constructor
A new instance of Person.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(**opts) ⇒ Object
Methods inherited from Contributor
Methods included from RelatonBib
Constructor Details
#initialize(name:, affiliation: [], contact: [], identifier: [], url: nil) ⇒ Person
Returns a new instance of Person.
178 179 180 181 182 183 184 |
# File 'lib/relaton_bib/person.rb', line 178 def initialize(name:, affiliation: [], contact: [], identifier: [], url: nil) super(contact: contact, url: url) @name = name @affiliation = affiliation @identifier = identifier end |
Instance Attribute Details
#affiliation ⇒ Array<RelatonBib::Affiliation>
168 169 170 |
# File 'lib/relaton_bib/person.rb', line 168 def affiliation @affiliation end |
#identifier ⇒ Array<RelatonBib::PersonIdentifier>
171 172 173 |
# File 'lib/relaton_bib/person.rb', line 171 def identifier @identifier end |
#name ⇒ RelatonBib::FullName
165 166 167 |
# File 'lib/relaton_bib/person.rb', line 165 def name @name end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
211 212 213 214 215 216 217 218 219 |
# File 'lib/relaton_bib/person.rb', line 211 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_hash ⇒ Hash
199 200 201 202 203 204 205 206 |
# File 'lib/relaton_bib/person.rb', line 199 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
189 190 191 192 193 194 195 196 |
# File 'lib/relaton_bib/person.rb', line 189 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 |