Class: Console::Output::Sensitive::Filter
- Inherits:
-
Object
- Object
- Console::Output::Sensitive::Filter
- Defined in:
- lib/console/output/sensitive.rb
Overview
A simple filter for redacting sensitive information.
Instance Method Summary collapse
-
#call(text) ⇒ Object
Apply the filter to the given text.
-
#initialize(substitutions) ⇒ Filter
constructor
Create a new filter.
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 |