Class: RelatonBib::Affiliation
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/contributor.rb
Overview
Affiliation.
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #description ⇒ Array<RelatonBib::FormattedString> readonly
- #name ⇒ RelatonBib::LocalizedString, NilClass readonly
- #organization ⇒ RelatonBib::Organization readonly
Instance Method Summary collapse
-
#initialize(organization:, name: nil, description: []) ⇒ Affiliation
constructor
A new instance of Affiliation.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(**opts) ⇒ Object
Methods included from RelatonBib
Constructor Details
#initialize(organization:, name: nil, description: []) ⇒ Affiliation
Returns a new instance of Affiliation.
126 127 128 129 130 |
# File 'lib/relaton_bib/contributor.rb', line 126 def initialize(organization:, name: nil, description: []) @name = name @organization = organization @description = description end |
Instance Attribute Details
#description ⇒ Array<RelatonBib::FormattedString> (readonly)
118 119 120 |
# File 'lib/relaton_bib/contributor.rb', line 118 def description @description end |
#name ⇒ RelatonBib::LocalizedString, NilClass (readonly)
115 116 117 |
# File 'lib/relaton_bib/contributor.rb', line 115 def name @name end |
#organization ⇒ RelatonBib::Organization (readonly)
121 122 123 |
# File 'lib/relaton_bib/contributor.rb', line 121 def organization @organization end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/relaton_bib/contributor.rb', line 158 def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize pref = prefix.empty? ? prefix : "#{prefix}." out = count > 1 ? "#{pref}affiliation::\n" : "" out += name.to_asciibib "#{pref}affiliation.name" if name description.each do |d| out += d.to_asciibib "#{pref}affiliation.description", description.size end out += organization.to_asciibib "#{pref}affiliation.*" out end |
#to_hash ⇒ Hash
146 147 148 149 150 151 152 153 |
# File 'lib/relaton_bib/contributor.rb', line 146 def to_hash hash = organization.to_hash hash["name"] = name.to_hash if name if description&.any? hash["description"] = single_element_array(description) end hash end |
#to_xml(**opts) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/relaton_bib/contributor.rb', line 135 def to_xml(**opts) # rubocop:disable Metrics/AbcSize opts[:builder].affiliation do |builder| builder.name { name.to_xml builder } if name desc = description.select { |d| d.language&.include? opts[:lang] } desc = description unless desc.any? desc.each { |d| builder.description { d.to_xml builder } } organization.to_xml(**opts) end end |