Class: RelatonBib::ContributionInfo
Overview
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.
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
78
79
80
|
# File 'lib/relaton_bib/contribution_info.rb', line 78
def entity
@entity
end
|
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
|