Class: QuietQuality::Cli::MessageFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/cli/message_formatter.rb

Constant Summary collapse

TOKEN_MATCHING_REGEX =
%r{%[a-z]*-?\d+(?:tool|loc|level|path|lines|rule|body)}

Instance Method Summary collapse

Constructor Details

#initialize(message_format:) ⇒ MessageFormatter

Returns a new instance of MessageFormatter.



6
7
8
# File 'lib/quiet_quality/cli/message_formatter.rb', line 6

def initialize(message_format:)
  @message_format = message_format
end

Instance Method Details

#format(message) ⇒ Object



10
11
12
13
14
15
# File 'lib/quiet_quality/cli/message_formatter.rb', line 10

def format(message)
  formatted_tokens = parsed_tokens.map { |pt| FormattedToken.new(parsed_token: pt, message: message) }
  formatted_tokens.reduce(message_format) do |interpolating, ftok|
    interpolating.gsub(ftok.token, ftok.formatted_token)
  end
end