Sha256: 627dd0ae116451919ae380b8855f722f59a1646e465aec88e8346843ad8f33f5

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 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)
      builder.docidentifier(id, type: type)
    end

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
relaton-bib-0.5.1 lib/relaton_bib/document_identifier.rb
relaton-bib-0.5.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.4.1 lib/relaton_bib/document_identifier.rb
relaton-bib-0.4.0 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.12 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.11 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.10 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.9 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.8 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.7 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.6 lib/relaton_bib/document_identifier.rb
relaton-bib-0.3.5 lib/relaton_bib/document_identifier.rb