Class: RelatonBib::ContributionInfo

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

Overview

Contribution info.

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(entity:, role: []) ⇒ ContributionInfo

Returns a new instance of ContributionInfo.

Parameters:



85
86
87
88
89
90
91
# File 'lib/relaton_bib/contribution_info.rb', line 85

def initialize(entity:, role: [])
  if role.empty?
    role << { type: entity.is_a?(Person) ? "author" : "publisher" }
  end
  @entity = entity
  @role   = role.map { |r| ContributorRole.new(**r) }
end

Instance Attribute Details

#entityObject (readonly)

Returns [RelatonBib::Person, RelatonBib::Organization].

Returns:

  • RelatonBib::Person, RelatonBib::Organization


81
82
83
# File 'lib/relaton_bib/contribution_info.rb', line 81

def entity
  @entity
end

#roleArray<RelatonBib::ContributorRole> (readonly)



77
78
79
# File 'lib/relaton_bib/contribution_info.rb', line 77

def role
  @role
end

Instance Method Details

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

Parameters:

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

    number of contributors

Returns:

  • (String)


110
111
112
113
114
115
116
# File 'lib/relaton_bib/contribution_info.rb', line 110

def to_asciibib(prefix = "", count = 1)
  pref = prefix.split(".").first
  out = count > 1 ? "#{pref}::\n" : ""
  out += entity.to_asciibib prefix
  role.each { |r| out += r.to_asciibib pref, role.size }
  out
end

#to_hashHash

Returns:

  • (Hash)


101
102
103
104
105
# File 'lib/relaton_bib/contribution_info.rb', line 101

def to_hash
  hash = entity.to_hash
  hash["role"] = single_element_array(role) if role&.any?
  hash
end

#to_xml(**opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (**opts):

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

    XML builder

  • :lang (String, Symbol)

    language



96
97
98
# File 'lib/relaton_bib/contribution_info.rb', line 96

def to_xml(**opts)
  entity.to_xml **opts
end