Class: Pragmater::Formatters::Shebang

Inherits:
Object
  • Object
show all
Defined in:
lib/pragmater/formatters/shebang.rb

Overview

Formats shebang pragmas in a consistent manner.

Constant Summary collapse

PATTERN =
%r(\A\#!\s?/.*ruby\Z)

Instance Method Summary collapse

Constructor Details

#initialize(string, pattern: PATTERN) ⇒ Shebang

Returns a new instance of Shebang.



9
10
11
12
# File 'lib/pragmater/formatters/shebang.rb', line 9

def initialize string, pattern: PATTERN
  @string = string
  @pattern = pattern
end

Instance Method Details

#callObject



14
15
16
17
18
# File 'lib/pragmater/formatters/shebang.rb', line 14

def call
  return string unless string.match? pattern

  string.split("!").then { |octothorpe, path| "#{octothorpe}! #{path.strip}" }
end