Sha256: 85f008d1b4718fd311e85032978724f764f5652a09a07e62e1fa2a7061de5119

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

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

    # @return [ContributorRoleType]
    attr_reader :type

    # @param type [ContributorRoleType] allowed types "author", "editor",
    #   "cartographer", "publisher"
    def initialize(type, description = [])
      @type = type
      @description = description.map { |d| FormattedString.new d }
    end

    def to_xml(builder)
      builder.role(type: type) do
        description.each do |d|
          builder.description do |desc|
            d.to_xml(desc)
          end
        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

7 entries across 7 versions & 1 rubygems

Version Path
iso-bib-item-0.1.6 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.5 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.4 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.3 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.2 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.1 lib/iso_bib_item/contribution_info.rb
iso-bib-item-0.1.0 lib/iso_bib_item/contribution_info.rb