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

parse_date

Constructor Details

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

Returns a new instance of Affiliation.

Parameters:



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

#descriptionArray<RelatonBib::FormattedString> (readonly)



118
119
120
# File 'lib/relaton_bib/contributor.rb', line 118

def description
  @description
end

#nameRelatonBib::LocalizedString, NilClass (readonly)

Returns:



115
116
117
# File 'lib/relaton_bib/contributor.rb', line 115

def name
  @name
end

#organizationRelatonBib::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

Parameters:

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

Returns:

  • (String)


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

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

#to_hashHash

Returns:

  • (Hash)


142
143
144
145
146
147
148
149
# File 'lib/relaton_bib/contributor.rb', line 142

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(builder) ⇒ Object



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

def to_xml(builder)
  builder.affiliation do
    builder.name { name.to_xml builder } if name
    description.each { |d| builder.description { d.to_xml builder } }
    organization.to_xml builder
  end
end