Sha256: 5012b43dde9c32685d572e6007f220960d915655579a94c523217a4794601fc8

Contents?: true

Size: 1.63 KB

Versions: 80

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Nokogiri
  module XML
    # :nodoc: all
    module PP
      module Node
        COLLECTIONS = [:attribute_nodes, :children]

        def inspect
          attributes = inspect_attributes.reject do |x|
            attribute = send(x)
            !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
          rescue NoMethodError
            true
          end.map do |attribute|
            "#{attribute.to_s.sub(/_\w+/, "s")}=#{send(attribute).inspect}"
          end.join(" ")
          "#<#{self.class.name}:#{format("0x%x", object_id)} #{attributes}>"
        end

        def pretty_print(pp)
          nice_name = self.class.name.split("::").last
          pp.group(2, "#(#{nice_name}:#{format("0x%x", object_id)} {", "})") do
            pp.breakable
            attrs = inspect_attributes.filter_map do |t|
              [t, send(t)] if respond_to?(t)
            end.find_all do |x|
              if x.last
                if COLLECTIONS.include?(x.first)
                  !x.last.empty?
                else
                  true
                end
              end
            end

            pp.seplist(attrs) do |v|
              if COLLECTIONS.include?(v.first)
                pp.group(2, "#{v.first.to_s.sub(/_\w+$/, "s")} = [", "]") do
                  pp.breakable
                  pp.seplist(v.last) do |item|
                    pp.pp(item)
                  end
                end
              else
                pp.text("#{v.first} = ")
                pp.pp(v.last)
              end
            end
            pp.breakable
          end
        end
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 3 rubygems

Version Path
nokogiri-1.14.0-x86_64-darwin lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-x86-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-aarch64-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-x86-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-x86_64-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-arm-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-x64-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0-x64-mingw-ucrt lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x86_64-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-java lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x86_64-darwin lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x86-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x64-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x86-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-x64-mingw-ucrt lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-arm64-darwin lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-arm-linux lib/nokogiri/xml/pp/node.rb
nokogiri-1.14.0.rc1-aarch64-linux lib/nokogiri/xml/pp/node.rb