class Prism::NodeInspector
:nodoc:
implementations of child nodes.
This object is responsible for generating the output for the inspect method
def <<(line)
def <<(line) output << "#{prefix}#{line}" end
def child_inspector(append)
def child_inspector(append) NodeInspector.new("#{prefix}#{append}") end
def child_node(node, append)
def child_node(node, append) node.inspect(child_inspector(append)).delete_prefix(prefix) end
def header(node)
This generates a string that is used as the header of the inspect output
def header(node) output = +"@ #{node.class.name.split("::").last} (" output << "location: (#{node.location.start_line},#{node.location.start_column})-(#{node.location.end_line},#{node.location.end_column})" output << ", newline: true" if node.newline? output << ")\n" output end
def initialize(prefix = "")
def initialize(prefix = "") @prefix = prefix @output = +"" end
def list(prefix, nodes)
Generates a string that represents a list of nodes. It handles properly
def list(prefix, nodes) output = +"(length: #{nodes.length})\n" last_index = nodes.length - 1 nodes.each_with_index do |node, index| pointer, preadd = (index == last_index) ? ["└── ", " "] : ["├── ", "│ "] node_prefix = "#{prefix}#{preadd}" output << node.inspect(NodeInspector.new(node_prefix)).sub(node_prefix, "#{prefix}#{pointer}") end output end
def location(value)
def location(value) if value "(#{value.start_line},#{value.start_column})-(#{value.end_line},#{value.end_column}) = #{value.slice.inspect}" else "∅" end end
def to_str
def to_str output end