Class: RelatonBib::Affiliation

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/contributor.rb

Overview

Affiliation.

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.

Parameters:



151
152
153
154
155
# File 'lib/relaton_bib/contributor.rb', line 151

def initialize(organization: nil, name: nil, description: [])
  @name = name
  @organization = organization
  @description  = description
end

Instance Attribute Details

#nameRelatonBib::LocalizedString? (readonly)

Returns:



143
144
145
# File 'lib/relaton_bib/contributor.rb', line 143

def name
  @name
end

#organizationRelatonBib::Organization (readonly)



146
147
148
# File 'lib/relaton_bib/contributor.rb', line 146

def organization
  @organization
end

Instance Method Details

#==(other) ⇒ Object



157
158
159
# File 'lib/relaton_bib/contributor.rb', line 157

def ==(other)
  name == other.name && organization == other.organization && description == other.description
end

#description(lang = nil) ⇒ Object

Get description.

Parameters:

  • lang (String, nil) (defaults to: nil)

    language if nil return all description



189
190
191
192
193
# File 'lib/relaton_bib/contributor.rb', line 189

def description(lang = nil)
  return @description unless lang

  @description.select { |d| d.language&.include? lang }
end

#description_xml(builder) ⇒ Object



178
179
180
# File 'lib/relaton_bib/contributor.rb', line 178

def description_xml(builder)
  description.each { |d| builder.description { d.to_xml builder } }
end

#name_xml(builder) ⇒ Object



174
175
176
# File 'lib/relaton_bib/contributor.rb', line 174

def name_xml(builder)
  builder.name { name.to_xml builder } if name
end

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

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

Returns:

  • (String)


212
213
214
215
216
217
218
219
220
221
# File 'lib/relaton_bib/contributor.rb', line 212

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.*" if organization
  out
end

#to_hashHash

Render affiliation as hash.

Returns:

  • (Hash)


200
201
202
203
204
205
206
207
# File 'lib/relaton_bib/contributor.rb', line 200

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

Parameters:

  • opts (Hash)

Options Hash (**opts):

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

    XML builder

  • :lang (String)

    language



164
165
166
167
168
169
170
171
172
# File 'lib/relaton_bib/contributor.rb', line 164

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