Class: SyntaxTree::DotFormatter

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

Overview

Responsible for formatting Dot2 and Dot3 nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator, node) ⇒ DotFormatter



3875
3876
3877
3878
# File 'lib/syntax_tree/node.rb', line 3875

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

Instance Attribute Details

#nodeObject (readonly)

Dot2 | Dot3

the node that is being formatter



3873
3874
3875
# File 'lib/syntax_tree/node.rb', line 3873

def node
  @node
end

#operatorObject (readonly)

String

the operator to display



3870
3871
3872
# File 'lib/syntax_tree/node.rb', line 3870

def operator
  @operator
end

Instance Method Details

#format(q) ⇒ Object



3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
# File 'lib/syntax_tree/node.rb', line 3880

def format(q)
  left = node.left
  right = node.right

  q.format(left) if left

  case q.parent
  when If, IfMod, Unless, UnlessMod
    q.text(" #{operator} ")
  else
    q.text(operator)
  end

  q.format(right) if right
end