Class: RelatonBib::Contributor

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

Overview

Contributor.

Direct Known Subclasses

Organization, Person

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(url: nil, contact: []) ⇒ Contributor

Returns a new instance of Contributor.

Parameters:



182
183
184
185
# File 'lib/relaton_bib/contributor.rb', line 182

def initialize(url: nil, contact: [])
  @uri = URI url if url
  @contact = contact
end

Instance Attribute Details

#contactArray<RelatonBib::Address, RelatonBib::Contact> (readonly)



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

def contact
  @contact
end

#uriURI (readonly)

Returns:

  • (URI)


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

def uri
  @uri
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


208
209
210
211
212
213
214
215
216
217
# File 'lib/relaton_bib/contributor.rb', line 208

def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
  pref = prefix.empty? ? prefix : prefix + "."
  out = ""
  out += "#{pref}url:: #{uri}\n" if uri
  addr = contact.select { |c| c.is_a? RelatonBib::Address }
  addr.each { |ct| out += ct.to_asciibib prefix, addr.size }
  cont = contact.select { |c| c.is_a? RelatonBib::Contact }
  cont.each { |ct| out += ct.to_asciibib prefix, cont.size }
  out
end

#to_hashHash

Returns:

  • (Hash)


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

def to_hash
  hash = {}
  hash["url"] = uri.to_s if uri
  hash["contact"] = single_element_array(contact) if contact&.any?
  hash
end

#to_xml(builder) ⇒ Object



194
195
196
# File 'lib/relaton_bib/contributor.rb', line 194

def to_xml(builder)
  contact.each { |contact| contact.to_xml builder }
end

#urlString

Returns url.

Returns:

  • (String)


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

def url
  @uri.to_s
end