Class: SyntaxTree::ArrayLiteral::QWordsFormatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ QWordsFormatter

Returns a new instance of QWordsFormatter.



1394
1395
1396
# File 'lib/syntax_tree.rb', line 1394

def initialize(contents)
  @contents = contents
end

Instance Attribute Details

#contentsObject (readonly)

Args

the contents of the array



1392
1393
1394
# File 'lib/syntax_tree.rb', line 1392

def contents
  @contents
end

Instance Method Details

#format(q) ⇒ Object



1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
# File 'lib/syntax_tree.rb', line 1398

def format(q)
  q.group(0, "%w[", "]") do
    q.indent do
      q.breakable("")
      q.seplist(contents.parts, -> { q.breakable }) do |part|
        if part.is_a?(StringLiteral)
          q.format(part.parts.first)
        else
          q.text(part.value[1..-1])
        end
      end
    end
    q.breakable("")
  end
end