Class: RelatonBib::ContributorRole

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/contribution_info.rb

Overview

Contributor’s role.

Constant Summary collapse

TYPES =
%w[author performer publisher editor adapter translator
distributor].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ContributorRole

Returns a new instance of ContributorRole.

Parameters:

  • type (String)

    allowed types “author”, “editor”, “cartographer”, “publisher”

  • description (Array<String>)


21
22
23
24
25
26
27
28
# File 'lib/relaton_bib/contribution_info.rb', line 21

def initialize(*args)
  @type = args.fetch 0
  if type && !TYPES.include?(type)
    raise ArgumentError, %{Type "#{type}" is invalid.}
  end

  @description = args.fetch(1, []).map { |d| FormattedString.new content: d, format: nil }
end

Instance Attribute Details

#descriptionArray<RelatonBib::FormattedString> (readonly)

Returns:



13
14
15
# File 'lib/relaton_bib/contribution_info.rb', line 13

def description
  @description
end

#typeContributorRoleType (readonly)

Returns:

  • (ContributorRoleType)


16
17
18
# File 'lib/relaton_bib/contribution_info.rb', line 16

def type
  @type
end

Instance Method Details

#to_xml(builder) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/relaton_bib/contribution_info.rb', line 30

def to_xml(builder)
  builder.role(type: type) do
    description.each do |d|
      builder.description { |desc| d.to_xml(desc) }
    end
  end
end