Class: Phlexing::Formatter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, max: 80) ⇒ Formatter

Returns a new instance of Formatter.



11
12
13
14
# File 'lib/phlexing/formatter.rb', line 11

def initialize(source, max: 80)
  @source = source.to_s.dup
  @max = max
end

Class Method Details

.callObject



7
8
9
# File 'lib/phlexing/formatter.rb', line 7

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



16
17
18
19
20
# File 'lib/phlexing/formatter.rb', line 16

def call
  SyntaxTree.format(@source, @max).strip
rescue SyntaxTree::Parser::ParseError, NoMethodError
  @source
end