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: [{ type: "publisher" }]) ⇒ ContributionInfo

Returns a new instance of ContributionInfo.

Parameters:



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

def initialize(entity:, role: [{ type: "publisher" }])
  @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


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

def entity
  @entity
end

#roleArray<RelatonBib::ContributorRole> (readonly)



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

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)


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

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)


92
93
94
95
96
# File 'lib/relaton_bib/contribution_info.rb', line 92

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

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


87
88
89
# File 'lib/relaton_bib/contribution_info.rb', line 87

def to_xml(builder)
  entity.to_xml builder
end