Sha256: 25bc6689e9c70eb6da6812eb3e603d2addf7489adfedf2342e6ae2ffb47af0e8

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

module RelatonBib
  # Document identifier.
  class DocumentIdentifier
    # @return [String]
    attr_reader :id

    # @return [String, NilClass]
    attr_reader :type

    # @param id [String]
    # @param type [String, NilClass]
    def initialize(id:, type: nil)
      @id   = id
      @type = type
    end

    # in docid manipulations, assume ISO as the default: id-part:year
    def remove_part
      case @type
      when "Chinese Standard" then @id.sub!(/\.\d+/, "")
      else
        @id.sub!(/-\d+/, "")
      end
    end

    def remove_date
      case @type
      when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "")
      else
        @id.sub!(/:[12]\d\d\d/, "")
      end
    end

    def all_parts
      @id += " (all parts)"
    end

    #
    # Add docidentifier xml element
    #
    # @param [Nokogiri::XML::Builder] builder
    #
    def to_xml(builder)
      element = builder.docidentifier id
      element[:type] = type if type
    end

    # @return [Hash]
    def to_hash
      hash = { "id" => id }
      hash["type"] = type if type
      hash
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/relaton-bib-1.2.4/lib/relaton_bib/document_identifier.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/relaton-bib-1.2.4/lib/relaton_bib/document_identifier.rb
relaton-bib-1.2.4 lib/relaton_bib/document_identifier.rb
relaton-bib-1.2.2 lib/relaton_bib/document_identifier.rb
relaton-bib-1.2.1 lib/relaton_bib/document_identifier.rb
relaton-bib-1.2.0 lib/relaton_bib/document_identifier.rb
relaton-bib-1.1.1 lib/relaton_bib/document_identifier.rb
relaton-bib-1.1.0 lib/relaton_bib/document_identifier.rb
relaton-bib-1.0.4 lib/relaton_bib/document_identifier.rb
relaton-bib-1.0.3 lib/relaton_bib/document_identifier.rb
relaton-bib-1.0.2 lib/relaton_bib/document_identifier.rb
relaton-bib-1.0.1 lib/relaton_bib/document_identifier.rb
relaton-bib-1.0.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.9.2 lib/relaton_bib/document_identifier.rb
relaton-bib-0.9.1 lib/relaton_bib/document_identifier.rb
relaton-bib-0.9.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.8.1 lib/relaton_bib/document_identifier.rb
relaton-bib-0.8.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.7.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.6.0 lib/relaton_bib/document_identifier.rb