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)
-
+ (String) indent(string, indent = 2)
private
Indent a multiline string with a number of spaces.
Instance Method Summary (collapse)
-
- (String) call
private
Perform the pretty-printing.
-
- (PP) initialize(node)
constructor
private
Create a new pretty-printer.
-
- (String) pp_attributes
private
Format the node attributes.
-
- (String) pp_children
private
Format the node children.
-
- (String) pp_tag
private
Format the node tag.
Constructor Details
- (PP) initialize(node)
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
10 11 12 |
# File 'lib/hexp/node/pp.rb', line 10 def initialize(node) @node = node end |
Class Method Details
+ (String) indent(string, indent = 2)
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
65 66 67 |
# File 'lib/hexp/node/pp.rb', line 65 def self.indent(string, indent = 2) string.lines.map {|line| " "*indent + line}.join end |
Instance Method Details
- (String) call
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
19 20 21 22 23 24 25 |
# File 'lib/hexp/node/pp.rb', line 19 def call [ @node.class.inspect_name, pp_tag, PP.indent(pp_attributes + pp_children).strip ].join end |
- (String) pp_attributes
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
41 42 43 44 45 |
# File 'lib/hexp/node/pp.rb', line 41 def pp_attributes attrs = @node.attributes return '' if attrs.empty? ', ' + attrs.inspect end |
- (String) pp_children
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
52 53 54 55 56 |
# File 'lib/hexp/node/pp.rb', line 52 def pp_children children = @node.children return ']' if children.empty? ", [\n#{ children.map(&:pp).join(",\n") }]]" end |
- (String) pp_tag
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
32 33 34 |
# File 'lib/hexp/node/pp.rb', line 32 def pp_tag "[#{@node.tag.inspect}" end |