Class: RelatonBib::Affiliation
Overview
Constant Summary
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from RelatonBib
array, format_date, grammar_hash, parse_date, parse_yaml
Methods included from Config
#configuration, #configure
Constructor Details
#initialize(organization: nil, name: nil, description: []) ⇒ Affiliation
Returns a new instance of Affiliation.
132
133
134
135
136
|
# File 'lib/relaton_bib/contributor.rb', line 132
def initialize(organization: nil, name: nil, description: [])
@name = name
@organization = organization
@description = description
end
|
Instance Attribute Details
124
125
126
|
# File 'lib/relaton_bib/contributor.rb', line 124
def name
@name
end
|
127
128
129
|
# File 'lib/relaton_bib/contributor.rb', line 127
def organization
@organization
end
|
Instance Method Details
#description(lang = nil) ⇒ Object
166
167
168
169
170
|
# File 'lib/relaton_bib/contributor.rb', line 166
def description(lang = nil)
return @description unless lang
@description.select { |d| d.language&.include? lang }
end
|
#description_xml(builder) ⇒ Object
155
156
157
|
# File 'lib/relaton_bib/contributor.rb', line 155
def description_xml(builder)
description.each { |d| builder.description { d.to_xml builder } }
end
|
#name_xml(builder) ⇒ Object
151
152
153
|
# File 'lib/relaton_bib/contributor.rb', line 151
def name_xml(builder)
builder.name { name.to_xml builder } if name
end
|
#to_asciibib(prefix = "", count = 1) ⇒ String
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/relaton_bib/contributor.rb', line 189
def to_asciibib(prefix = "", count = 1) 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.*" if organization
out
end
|
#to_hash ⇒ Hash
Render affiliation as hash.
177
178
179
180
181
182
183
184
|
# File 'lib/relaton_bib/contributor.rb', line 177
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
141
142
143
144
145
146
147
148
149
|
# File 'lib/relaton_bib/contributor.rb', line 141
def to_xml(**opts)
return unless organization || name || description&.any?
opts[:builder].affiliation do |builder|
name_xml builder
description_xml builder
organization&.to_xml(**opts)
end
end
|