Class: SyntaxTree::DotFormatter
- Inherits:
-
Object
- Object
- SyntaxTree::DotFormatter
- Defined in:
- lib/syntax_tree.rb
Overview
Responsible for formatting Dot2 and Dot3 nodes.
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
- Dot2 | Dot3
-
the node that is being formatter.
-
#operator ⇒ Object
readonly
- String
-
the operator to display.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(operator, node) ⇒ DotFormatter
constructor
A new instance of DotFormatter.
Constructor Details
#initialize(operator, node) ⇒ DotFormatter
Returns a new instance of DotFormatter.
4573 4574 4575 4576 |
# File 'lib/syntax_tree.rb', line 4573 def initialize(operator, node) @operator = operator @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
- Dot2 | Dot3
-
the node that is being formatter
4571 4572 4573 |
# File 'lib/syntax_tree.rb', line 4571 def node @node end |
#operator ⇒ Object (readonly)
- String
-
the operator to display
4568 4569 4570 |
# File 'lib/syntax_tree.rb', line 4568 def operator @operator end |
Instance Method Details
#format(q) ⇒ Object
4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 |
# File 'lib/syntax_tree.rb', line 4578 def format(q) parent = q.parent space = parent.is_a?(If) || parent.is_a?(Unless) left = node.left right = node.right q.format(left) if left q.text(" ") if space q.text(operator) q.text(" ") if space q.format(right) if right end |