Sha256: 1a99602f89f9a2b8581f6c81d065374dabc11aa89290fc01a3f8df3a67e80f35

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'iso_bib_item/person'

# Isobib module
module IsoBibItem
  # Contributor's role.
  class ContributorRole
    # @return [Array<IsoBibItem::FormattedString>]
    attr_reader :description

    # @return [ContributorRoleType]
    attr_reader :type

    # @param type [String] allowed types "author", "editor",
    #   "cartographer", "publisher"
    # @param description [Array<String>]
    def initialize(*args)
      @type = args.fetch 0
      @description = args.fetch(1, []).map { |d| FormattedString.new content: d, type: nil }
    end

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

  # Contribution info.
  class ContributionInfo
    # @return [Array<IsoBibItem::ContributorRole>]
    attr_reader :role

    # @return
    #   [IsoBibItem::Person, IsoBibItem::Organization,
    #    IsoBibItem::IsoProjectGroup]
    attr_reader :entity

    # @param entity [IsoBibItem::Person, IsoBibItem::Organization,
    #   IsoBibItem::IsoProjectGroup]
    # @param role [Array<String>]
    def initialize(entity:, role: ['publisher'])
      @entity = entity
      @role   = role.map { |r| ContributorRole.new(*r) }
    end

    def to_xml(builder)
      entity.to_xml builder
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iso-bib-item-0.4.5 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.4.4 lib/iso_bib_item/contribution_info.rb