Class: RelatonBib::ContributionInfo
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/contribution_info.rb
Overview
Contribution info.
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
[RelatonBib::Person, RelatonBib::Organization].
- #role ⇒ Array<RelatonBib::ContributorRole> readonly
Instance Method Summary collapse
-
#initialize(entity:, role: [{ type: "publisher" }]) ⇒ ContributionInfo
constructor
A new instance of ContributionInfo.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Methods included from RelatonBib
Constructor Details
#initialize(entity:, role: [{ type: "publisher" }]) ⇒ ContributionInfo
Returns a new instance of ContributionInfo.
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
#entity ⇒ Object (readonly)
Returns [RelatonBib::Person, RelatonBib::Organization].
77 78 79 |
# File 'lib/relaton_bib/contribution_info.rb', line 77 def entity @entity end |
#role ⇒ Array<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
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_hash ⇒ 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
87 88 89 |
# File 'lib/relaton_bib/contribution_info.rb', line 87 def to_xml(builder) entity.to_xml builder end |