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

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

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

Returns a new instance of Contributor.

Parameters:



236
237
238
239
# File 'lib/relaton_bib/contributor.rb', line 236

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

Instance Attribute Details

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



232
233
234
# File 'lib/relaton_bib/contributor.rb', line 232

def contact
  @contact
end

#uriURI (readonly)

Returns:

  • (URI)


229
230
231
# File 'lib/relaton_bib/contributor.rb', line 229

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



241
242
243
# File 'lib/relaton_bib/contributor.rb', line 241

def ==(other)
  uri == other.uri && contact == other.contact
end

#to_asciibib(prefix = "") ⇒ String

Parameters:

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

Returns:

  • (String)


266
267
268
269
270
271
272
273
274
275
# File 'lib/relaton_bib/contributor.rb', line 266

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)


257
258
259
260
261
262
# File 'lib/relaton_bib/contributor.rb', line 257

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



252
253
254
# File 'lib/relaton_bib/contributor.rb', line 252

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

#urlString

Returns url.

Returns:

  • (String)


247
248
249
# File 'lib/relaton_bib/contributor.rb', line 247

def url
  @uri.to_s
end