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

Constructor Details

#initialize(organization:, name: nil, description: []) ⇒ Affiliation

Returns a new instance of Affiliation.

Parameters:



135
136
137
138
139
# File 'lib/relaton_bib/contributor.rb', line 135

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

Instance Attribute Details

#descriptionArray<RelatonBib::FormattedString> (readonly)



127
128
129
# File 'lib/relaton_bib/contributor.rb', line 127

def description
  @description
end

#nameRelatonBib::LocalizedString? (readonly)

Returns:



124
125
126
# File 'lib/relaton_bib/contributor.rb', line 124

def name
  @name
end

#organizationRelatonBib::Organization (readonly)



130
131
132
# File 'lib/relaton_bib/contributor.rb', line 130

def organization
  @organization
end

Instance Method Details

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

Parameters:

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

Returns:

  • (String)


167
168
169
170
171
172
173
174
175
176
# File 'lib/relaton_bib/contributor.rb', line 167

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_hashHash

Returns:

  • (Hash)


155
156
157
158
159
160
161
162
# File 'lib/relaton_bib/contributor.rb', line 155

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



144
145
146
147
148
149
150
151
152
# File 'lib/relaton_bib/contributor.rb', line 144

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