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.



5538
5539
5540
5541
# File 'lib/syntax_tree/node.rb', line 5538

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

Instance Attribute Details

#keywordObject (readonly)

String

the keyword associated with this conditional



5533
5534
5535
# File 'lib/syntax_tree/node.rb', line 5533

def keyword
  @keyword
end

#nodeObject (readonly)

IfMod | UnlessMod

the node that is being formatted



5536
5537
5538
# File 'lib/syntax_tree/node.rb', line 5536

def node
  @node
end

Instance Method Details

#format(q) ⇒ Object



5543
5544
5545
5546
5547
5548
5549
# File 'lib/syntax_tree/node.rb', line 5543

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