Sha256: a571057c754c8357e850361e195304dd27f4fbe9d34d0bfeec762664316e3214

Contents?: true

Size: 1.64 KB

Versions: 163

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true
module Nokogiri
  module XML
    module PP
      module Node
        def inspect # :nodoc:
          attributes = inspect_attributes.reject { |x|
            begin
              attribute = send x
              !attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
            rescue NoMethodError
              true
            end
          }.map { |attribute|
            "#{attribute.to_s.sub(/_\w+/, 's')}=#{send(attribute).inspect}"
          }.join ' '
          "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
        end

        def pretty_print pp # :nodoc:
          nice_name = self.class.name.split('::').last
          pp.group(2, "#(#{nice_name}:#{sprintf("0x%x", object_id)} {", '})') do

            pp.breakable
            attrs = inspect_attributes.map { |t|
              [t, send(t)] if respond_to?(t)
            }.compact.find_all { |x|
              if x.last
                if [:attribute_nodes, :children].include? x.first
                  !x.last.empty?
                else
                  true
                end
              end
            }

            pp.seplist(attrs) do |v|
              if [:attribute_nodes, :children].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

163 entries across 156 versions & 6 rubygems

Version Path
nokogiri-1.11.0.rc1-x86-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.11.0.rc1-x64-mingw32 lib/nokogiri/xml/pp/node.rb
nokogiri-1.11.0.rc1-java lib/nokogiri/xml/pp/node.rb