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: []) ⇒ ContributionInfo
constructor
A new instance of ContributionInfo.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(**opts) ⇒ Object
Methods included from RelatonBib
array, format_date, grammar_hash, parse_date, parse_yaml
Methods included from Config
Constructor Details
#initialize(entity:, role: []) ⇒ ContributionInfo
Returns a new instance of ContributionInfo.
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
#entity ⇒ Object (readonly)
Returns [RelatonBib::Person, RelatonBib::Organization].
78 79 80 |
# File 'lib/relaton_bib/contribution_info.rb', line 78 def entity @entity end |
#role ⇒ Array<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
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_hash ⇒ 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
95 96 97 |
# File 'lib/relaton_bib/contribution_info.rb', line 95 def to_xml(**opts) entity.to_xml(**opts) end |