Class: Hexp::Node::PP
- Inherits:
-
Object
- Object
- Hexp::Node::PP
- Defined in:
- lib/hexp/node/pp.rb
Overview
Pretty-print a node and its contents
Class Method Summary collapse
-
.indent(string, indent = 2) ⇒ String
private
Indent a multiline string with a number of spaces.
Instance Method Summary collapse
-
#call ⇒ String
private
Perform the pretty-printing.
-
#initialize(node) ⇒ PP
constructor
private
Create a new pretty-printer.
-
#pp_attributes ⇒ String
private
Format the node attributes.
-
#pp_children ⇒ String
private
Format the node children.
-
#pp_tag ⇒ String
private
Format the node tag.
Constructor Details
#initialize(node) ⇒ PP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new pretty-printer
11 12 13 |
# File 'lib/hexp/node/pp.rb', line 11 def initialize(node) @node = node end |
Class Method Details
.indent(string, indent = 2) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indent a multiline string with a number of spaces
69 70 71 |
# File 'lib/hexp/node/pp.rb', line 69 def self.indent(string, indent = 2) string.lines.map {|line| " "*indent + line}.join end |
Instance Method Details
#call ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform the pretty-printing
20 21 22 23 24 25 26 |
# File 'lib/hexp/node/pp.rb', line 20 def call [ @node.class.inspect_name, pp_tag, PP.indent(pp_attributes + pp_children).strip ].join end |
#pp_attributes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format the node attributes
42 43 44 45 46 |
# File 'lib/hexp/node/pp.rb', line 42 def pp_attributes attrs = @node.attributes return '' if attrs.empty? ', ' + attrs.inspect end |
#pp_children ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format the node children
53 54 55 56 57 |
# File 'lib/hexp/node/pp.rb', line 53 def pp_children children = @node.children return ']' if children.empty? ", [\n#{ children.map(&:pp).join(",\n") }]]" end |
#pp_tag ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format the node tag
33 34 35 |
# File 'lib/hexp/node/pp.rb', line 33 def pp_tag "[#{@node.tag.inspect}" end |