Class: SyntaxTree::DotFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Responsible for formatting Dot2 and Dot3 nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator, node) ⇒ DotFormatter

Returns a new instance of DotFormatter.



4870
4871
4872
4873
# File 'lib/syntax_tree.rb', line 4870

def initialize(operator, node)
  @operator = operator
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Dot2 | Dot3

the node that is being formatter



4868
4869
4870
# File 'lib/syntax_tree.rb', line 4868

def node
  @node
end

#operatorObject (readonly)

String

the operator to display



4865
4866
4867
# File 'lib/syntax_tree.rb', line 4865

def operator
  @operator
end

Instance Method Details

#format(q) ⇒ Object



4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
# File 'lib/syntax_tree.rb', line 4875

def format(q)
  space = [If, IfMod, Unless, UnlessMod].include?(q.parent.class)

  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