Sha256: 28ad8524e7bf0ec4d4baac2413a7dc37ee44b077eb31f2e81cc254f67bf9583d

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require 'iso_bib_item/contributor'

module IsoBibItem
  # module OrgIdentifierType
  #   ORCID = 'orcid'
  #   URI   = 'uri'
  # end

  # Organization identifier.
  class OrgIdentifier
    # @return [String]
    attr_reader :type

    # @return [String]
    attr_reader :value

    # @param type [String]
    # @param value [String]
    def initialize(type, value)
      @type  = type
      @value = value
    end

    def to_xml(builder)
      builder.identifier(value, type: type)
    end
  end

  # Organization.
  class Organization < Contributor
    # @return [IsoBibItem::LocalizedString]
    attr_reader :name

    # @return [IsoBibItem::LocalizedString]
    attr_reader :abbreviation

    # @return [Array<IsoBibItem::OrgIdentifier>]
    attr_reader :identifiers

    # @param name [String]
    # @param abbreviation [String]
    # @param url [String]
    # @TODO identifier
    def initialize(name:, abbreviation: nil, url: nil)
      super(url: url)
      @name         = LocalizedString.new name
      @abbreviation = LocalizedString.new abbreviation
      @identifiers  = []
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.organization do
        builder.name { |b| name.to_xml b }
        builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation&.to_s
        builder.uri uri.to_s if uri
        identifiers.each { |identifier| identifier.to_xml builder }
        super
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iso-bib-item-0.2.2 lib/iso_bib_item/organization.rb
iso-bib-item-0.2.1 lib/iso_bib_item/organization.rb