Sha256: 25bb87c32e30521b335156cac3977248a3a90b04284088f0212948a446459fe3

Contents?: true

Size: 1.67 KB

Versions: 100

Compression:

Stored size: 1.67 KB

Contents

module RelatonBib
  class WorkGroup
    # @return [String]
    attr_reader :name

    # @return [Integer, nil]
    attr_reader :number

    # @return [String, nil]
    attr_reader :identifier, :prefix, :type

    # @param name [String]
    # @param identifier [String, nil]
    # @param prefix [String, nil]
    # @param number [Integer, nil]
    # @param type [String, nil]
    def initialize(name:, identifier: nil, prefix: nil, number: nil, type: nil)
      @identifier = identifier
      @prefix = prefix
      @name = name
      @number = number
      @type = type
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder) # rubocop:disable Metrics/AbcSize
      builder.text name
      builder.parent[:number] = number if number
      builder.parent[:type] = type if type
      builder.parent[:identifier] = identifier if identifier
      builder.parent[:prefix] = prefix if prefix
    end

    # @return [Hash]
    def to_hash
      hash = { "name" => name }
      hash["number"] = number if number
      hash["type"] = type if type
      hash["identifier"] = identifier if identifier
      hash["prefix"] = prefix if prefix
      hash
    end

    # @param prfx [String]
    # @param count [Integer]
    # @return [String]
    def to_asciibib(prfx = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity
      pref = prfx.empty? ? prfx : "#{prfx}."
      out = count > 1 ? "#{pref}::\n" : ""
      out += "#{pref}name:: #{name}\n"
      out += "#{pref}number:: #{number}\n" if number
      out += "#{pref}type:: #{type}\n" if type
      out += "#{pref}identifier:: #{identifier}\n" if identifier
      out += "#{pref}prefix:: #{prefix}\n" if prefix
      out
    end
  end
end

Version data entries

100 entries across 100 versions & 1 rubygems

Version Path
relaton-bib-1.11.7 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.6 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.5 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.4 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.3 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.2 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.1 lib/relaton_bib/workgroup.rb
relaton-bib-1.11.0 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.7 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.6 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.5 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.4 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.3 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.2 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.1 lib/relaton_bib/workgroup.rb
relaton-bib-1.10.0 lib/relaton_bib/workgroup.rb
relaton-bib-1.9.23 lib/relaton_bib/workgroup.rb
relaton-bib-1.9.22 lib/relaton_bib/workgroup.rb
relaton-bib-1.9.21 lib/relaton_bib/workgroup.rb
relaton-bib-1.9.20 lib/relaton_bib/workgroup.rb