Sha256: bda711560bc0a5b713b35d45d47297a83c0e0ecc6d9aab8bec20dc56f0300019

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module RelatonUn
  class UnBibliographicItem < RelatonBib::BibliographicItem
    TYPES = %w[
      recommendation plenary addendum communication corrigendum reissue agenda
      budgetary sec-gen-notes expert-report resolution
    ].freeze

    DISTRIBUTIONS = { "GEN" => "general", "LTD" => "limited",
                      "DER" => "restricted", "PRO" => "provisional" }.freeze

    # @return [RelatonUn::Session, NilClass]
    attr_reader :session

    # @return [String, NilClass]
    attr_reader :distribution

    # @param session [RelatonUn::Session, NilClass]
    # @param distribution [String]
    def initialize(**args)
      if args[:distribution] && !DISTRIBUTIONS.has_value?(args[:distribution])
        warn "[relaton-un] WARNING: invalid distribution: #{args[:distribution]}"
      end
      @distribution = args.delete :distribution
      @session = args.delete :session
      super **args
      # @doctype = args[:doctype]
    end

    # @param builder [Nokogiri::XML::Builder]
    # @param bibdata [TrueClasss, FalseClass, NilClass]
    def to_xml(builder = nil, **opts)
      super(builder, **opts) do |b|
        b.ext do
          editorialgroup&.to_xml b
          b.distribution distribution if distribution
          session&.to_xml b if session
        end
      end
    end

    # @return [Hash]
    def to_hash
      hash = super
      hash["session"] = session.to_hash if session
      hash
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relaton-un-1.2.0 lib/relaton_un/un_bibliographic_item.rb