Sha256: b77f571a1dee33ba40bb8856582bb5b0d48ae6e60038636b214e91631c0fcc2a

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 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]
    def initialize(name:, abbreviation: nil, url: nil)
      super(url: url)
      @name         = LocalizedString.new name
      @abbreviation = LocalizedString.new abbreviation
      @identifiers  = []
    end

    # @return [String]
    def to_xml(builder)
      builder.organization do
        builder.name { |b| name.to_xml b }
        # unless abbreviati.content.nil? || abbreviation.content.empty?
        builder.abbreviation { |a| abbreviation.to_xml a }
        # end
        builder.uri uri.to_s if uri
        identifiers.each { |identifier| identifier.to_xml builder }
        super
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iso-bib-item-0.1.11 lib/iso_bib_item/organization.rb
iso-bib-item-0.1.10 lib/iso_bib_item/organization.rb
iso-bib-item-0.1.9 lib/iso_bib_item/organization.rb