ConsoleSourceConsoleOutputSensitiveFilter

class Filter

A simple filter for redacting sensitive information.

Definitions

def initialize(substitutions)

Create a new filter.

Signature

parameter substitutions Hash

The substitutions to apply.

Implementation

def initialize(substitutions)
	@substitutions = substitutions
	@pattern = Regexp.union(substitutions.keys)
end

def call(text)

Apply the filter to the given text. This will replace all occurrences of the pattern with the corresponding substitution.

Signature

parameter text String

The text to filter.

returns String

The filtered text.

Implementation

def call(text)
	text.gsub(@pattern, @substitutions)
end