Class: Console::Output::Sensitive::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/console/output/sensitive.rb

Overview

A simple filter for redacting sensitive information.

Instance Method Summary collapse

Constructor Details

#initialize(substitutions) ⇒ Filter

Create a new filter.



109
110
111
112
# File 'lib/console/output/sensitive.rb', line 109

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

Instance Method Details

#call(text) ⇒ Object

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



118
119
120
# File 'lib/console/output/sensitive.rb', line 118

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