Sha256: 6a515cd76752bdd76dd5369a6620b092029ab1a166fe2a87606e0fbcd341dd12

Contents?: true

Size: 951 Bytes

Versions: 33

Compression:

Stored size: 951 Bytes

Contents

module RelatonBib
  class Classification
    # @return [String, nil]
    attr_reader :type

    # @return [String]
    attr_reader :value

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

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      xml = builder.classification value
      xml[:type] = type if type
    end

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

    # @param prefix [String]
    # @param count [Integer] number of classifications
    # @return [String]
    def to_asciibib(prefix = "", count = 1)
      pref = prefix.empty? ? "classification" : prefix + ".classification"
      out = count > 1 ? "#{pref}::\n" : ""
      out += "#{pref}.type:: #{type}\n" if type
      out += "#{pref}.value:: #{value}\n"
      out
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
relaton-bib-1.19.6 lib/relaton_bib/classification.rb
relaton-bib-1.19.5 lib/relaton_bib/classification.rb
relaton-bib-1.19.4 lib/relaton_bib/classification.rb
relaton-bib-1.19.3 lib/relaton_bib/classification.rb
relaton-bib-1.19.2 lib/relaton_bib/classification.rb
relaton-bib-1.19.1 lib/relaton_bib/classification.rb
relaton-bib-1.19.0 lib/relaton_bib/classification.rb
relaton-bib-1.18.5 lib/relaton_bib/classification.rb
relaton-bib-1.18.3 lib/relaton_bib/classification.rb
relaton-bib-1.18.2 lib/relaton_bib/classification.rb
relaton-bib-1.18.1 lib/relaton_bib/classification.rb
relaton-bib-1.18.0 lib/relaton_bib/classification.rb
relaton-bib-1.17.2 lib/relaton_bib/classification.rb
relaton-bib-1.17.1 lib/relaton_bib/classification.rb
relaton-bib-1.17.0 lib/relaton_bib/classification.rb
relaton-bib-1.16.5 lib/relaton_bib/classification.rb
relaton-bib-1.16.4 lib/relaton_bib/classification.rb
relaton-bib-1.16.3 lib/relaton_bib/classification.rb
relaton-bib-1.16.2 lib/relaton_bib/classification.rb
relaton-bib-1.16.1 lib/relaton_bib/classification.rb