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

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

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

Returns a new instance of ContributionInfo.

Parameters:

Options Hash (role:):

  • :type (String)
  • :description (Array<String>)


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

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


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

def entity
  @entity
end

#roleArray<RelatonBib::ContributorRole> (readonly)



74
75
76
# File 'lib/relaton_bib/contribution_info.rb', line 74

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)


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

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)


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

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



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

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