Sha256: b82e6b4b7760b04d46b5409d453ed8031084afa136f50802f680f164d85e6a5d

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "pp"

module QiitaMarker
  class Node
    module Inspect
      PP_INDENT_SIZE = 2

      def inspect
        PP.pp(self, +"", Float::INFINITY)
      end

      # @param printer [PrettyPrint] pp
      def pretty_print(printer)
        printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do
          printer.breakable

          attrs = [:sourcepos, :string_content, :url, :title, :header_level, :list_type, :list_start, :list_tight, :fence_info].map do |name|
            [name, __send__(name)]
          rescue NodeError
            nil
          end.compact

          printer.seplist(attrs) do |name, value|
            printer.text("#{name}=")
            printer.pp(value)
          end

          if first_child
            printer.breakable
            printer.group(PP_INDENT_SIZE) do
              children = []
              node = first_child
              while node
                children << node
                node = node.next
              end
              printer.text("children=")
              printer.pp(children)
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qiita_marker-0.23.6.1 lib/qiita_marker/node/inspect.rb
qiita_marker-0.23.6.0 lib/qiita_marker/node/inspect.rb
qiita_marker-0.23.5.1 lib/qiita_marker/node/inspect.rb
qiita_marker-0.23.5.0 lib/qiita_marker/node/inspect.rb