Class: RelatonBib::ContributorRole
- Inherits:
-
Object
- Object
- RelatonBib::ContributorRole
show all
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/contribution_info.rb
Overview
Constant Summary
collapse
- TYPES =
%w[author performer publisher editor adapter translator
distributor].freeze
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
Constructor Details
Returns a new instance of ContributorRole.
23
24
25
26
27
28
29
30
|
# File 'lib/relaton_bib/contribution_info.rb', line 23
def initialize(**args)
if args[:type] && !TYPES.include?(args[:type])
raise ArgumentError, %{Type "#{type}" is invalid.}
end
@type = args[:type]
@description = args.fetch(:description, []).map { |d| FormattedString.new content: d, format: nil }
end
|
Instance Attribute Details
15
16
17
|
# File 'lib/relaton_bib/contribution_info.rb', line 15
def description
@description
end
|
#type ⇒ Strig
18
19
20
|
# File 'lib/relaton_bib/contribution_info.rb', line 18
def type
@type
end
|
Instance Method Details
#to_hash ⇒ Hash, String
42
43
44
45
46
47
48
49
50
|
# File 'lib/relaton_bib/contribution_info.rb', line 42
def to_hash
if description&.any?
hash = { "description" => single_element_array(description) }
hash["type"] = type if type
hash
elsif type
type
end
end
|
#to_xml(builder) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/relaton_bib/contribution_info.rb', line 33
def to_xml(builder)
builder.role(type: type) do
description.each do |d|
builder.description { |desc| d.to_xml(desc) }
end
end
end
|