Class: SyntaxTree::ConditionalModFormatter

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

Overview

Formats an IfMod or UnlessMod node.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, node) ⇒ ConditionalModFormatter

Returns a new instance of ConditionalModFormatter.



5485
5486
5487
5488
# File 'lib/syntax_tree/node.rb', line 5485

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

Instance Attribute Details

#keyword ⇒ Object (readonly)

[String] the keyword associated with this conditional



5480
5481
5482
# File 'lib/syntax_tree/node.rb', line 5480

def keyword
  @keyword
end

#node ⇒ Object (readonly)

[IfMod | UnlessMod] the node that is being formatted



5483
5484
5485
# File 'lib/syntax_tree/node.rb', line 5483

def node
  @node
end

Instance Method Details

#format(q) ⇒ Object



5490
5491
5492
5493
5494
5495
5496
# File 'lib/syntax_tree/node.rb', line 5490

def format(q)
  if ContainsAssignment.call(node.statement) || q.parent.is_a?(In)
    q.group { format_flat(q) }
  else
    q.group { q.if_break { format_break(q) }.if_flat { format_flat(q) } }
  end
end