module Psychgus::Stylables::HierarchyStylable

(see Stylers::HierarchyStyler)

Attributes

io[RW]
verbose[RW]

Public Class Methods

new(io: StringIO.new,verbose: false,**kargs) click to toggle source

@param io [IO] the IO to write to @param verbose [true,false] whether to be more verbose (e.g., write child info) @param kargs [Hash] capture extra keyword args, so no error for undefined args

# File lib/psychgus/stylables.rb, line 135
def initialize(io: StringIO.new,verbose: false,**kargs)
  @io = io
  @verbose = verbose
end

Public Instance Methods

style(sniffer,node) click to toggle source

Write the hierarchy of node to {io}.

@see Styler#style

# File lib/psychgus/stylables.rb, line 143
def style(sniffer,node)
  @io.print(' ' * (sniffer.level - 1))

  name = node.respond_to?(:value) ? node.value : node.class.name
  parent = sniffer.parent

  @io.print "(#{sniffer.level}:#{sniffer.position}):#{name} - "

  if @verbose
    @io.print parent
  else
    @io.print "<#{parent.debug_tag}:(#{parent.level}:#{parent.position})>"
  end

  @io.puts
end
to_s() click to toggle source

Convert {io} to a String if possible (e.g., StringIO).

@return [String] the IO String result or just {io} as a String

# File lib/psychgus/stylables.rb, line 163
def to_s
  return @io.respond_to?(:string) ? @io.string : @io.to_s
end