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.



6269
6270
6271
6272
# File 'lib/syntax_tree/node.rb', line 6269

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

Instance Attribute Details

#keywordObject (readonly)

String

the keyword associated with this conditional



6264
6265
6266
# File 'lib/syntax_tree/node.rb', line 6264

def keyword
  @keyword
end

#nodeObject (readonly)

IfMod | UnlessMod

the node that is being formatted



6267
6268
6269
# File 'lib/syntax_tree/node.rb', line 6267

def node
  @node
end

Instance Method Details

#format(q) ⇒ Object



6274
6275
6276
6277
6278
6279
6280
# File 'lib/syntax_tree/node.rb', line 6274

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