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

Returns a new instance of DotFormatter.



3321
3322
3323
3324
# File 'lib/syntax_tree/node.rb', line 3321

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

Instance Attribute Details

#nodeObject (readonly)

Dot2 | Dot3

the node that is being formatter



3319
3320
3321
# File 'lib/syntax_tree/node.rb', line 3319

def node
  @node
end

#operatorObject (readonly)

String

the operator to display



3316
3317
3318
# File 'lib/syntax_tree/node.rb', line 3316

def operator
  @operator
end

Instance Method Details

#format(q) ⇒ Object



3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
# File 'lib/syntax_tree/node.rb', line 3326

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