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.



4573
4574
4575
4576
# File 'lib/syntax_tree.rb', line 4573

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

Instance Attribute Details

#nodeObject (readonly)

Dot2 | Dot3

the node that is being formatter



4571
4572
4573
# File 'lib/syntax_tree.rb', line 4571

def node
  @node
end

#operatorObject (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