Sha256: 01366c5bc7de51a4dff99fcc88379c72dda4f6ce4099bf4b70c698ae2fcc5147

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module RelatonBib
  class DocumentType
    attr_reader :type, :abbreviation

    #
    # Initialize a DocumentType.
    #
    # @param [String] type document type
    # @param [String, nil] abbreviation type abbreviation
    #
    def initialize(type:, abbreviation: nil)
      @type = type
      @abbreviation = abbreviation
    end

    #
    # Build XML representation of the document type.
    #
    # @param [Nokogiri::XML::Builder] builder XML builder
    #
    def to_xml(builder)
      xml = builder.doctype @type
      xml[:abbreviation] = @abbreviation if @abbreviation
    end

    #
    # Hash representation of the document type.
    #
    # @return [Hash]
    #
    def to_hash
      hash = { "type" => @type }
      hash["abbreviation"] = @abbreviation if @abbreviation
      hash
    end

    #
    # Asciibib representation of the document type.
    #
    # @param [String] prefix prefix
    #
    # @return [String] AsciiBib representation
    #
    def to_asciibib(prefix = "")
      pref = prefix.empty? ? prefix : prefix + "."
      pref += "doctype."
      out = "#{pref}type:: #{@type}\n"
      out += "#{pref}abbreviation:: #{@abbreviation}\n" if @abbreviation
      out
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relaton-bib-1.17.2 lib/relaton_bib/document_type.rb
relaton-bib-1.17.1 lib/relaton_bib/document_type.rb
relaton-bib-1.17.0 lib/relaton_bib/document_type.rb