Class: Pragmater::Formatters::Main

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

Overview

Formats all pragmas in a consistent manner.

Constant Summary collapse

FORMATTERS =
[General, Shebang].freeze
PATTERN =
FORMATTERS.map { |formatter| formatter::PATTERN }
.then { |patterns| Regexp.union(*patterns) }
.freeze

Instance Method Summary collapse

Constructor Details

#initialize(string, formatters: FORMATTERS) ⇒ Main

Returns a new instance of Main.



13
14
15
16
# File 'lib/pragmater/formatters/main.rb', line 13

def initialize string, formatters: FORMATTERS
  @string = string
  @formatters = formatters
end

Instance Method Details

#callObject



18
# File 'lib/pragmater/formatters/main.rb', line 18

def call = formatters.reduce(string) { |pragma, formatter| formatter.new(pragma).call }