Class: Tracebook::Redaction::Pattern
- Inherits:
-
Data
- Object
- Data
- Tracebook::Redaction::Pattern
- Defined in:
- lib/tracebook/redaction/pattern.rb
Overview
A single redaction pattern with regex, replacement, and optional validator.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Instance Method Summary collapse
-
#initialize(name:, regex:, replacement:, validator: nil) ⇒ Pattern
constructor
A new instance of Pattern.
- #redact(text) ⇒ Object
Constructor Details
#initialize(name:, regex:, replacement:, validator: nil) ⇒ Pattern
Returns a new instance of Pattern.
7 8 9 |
# File 'lib/tracebook/redaction/pattern.rb', line 7 def initialize(name:, regex:, replacement:, validator: nil) super end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name
6 7 8 |
# File 'lib/tracebook/redaction/pattern.rb', line 6 def name @name end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex
6 7 8 |
# File 'lib/tracebook/redaction/pattern.rb', line 6 def regex @regex end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement
6 7 8 |
# File 'lib/tracebook/redaction/pattern.rb', line 6 def replacement @replacement end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator
6 7 8 |
# File 'lib/tracebook/redaction/pattern.rb', line 6 def validator @validator end |
Instance Method Details
#redact(text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tracebook/redaction/pattern.rb', line 11 def redact(text) return text unless text.is_a?(String) text.gsub(regex) do |match| if validator && !validator.call(match) match else replacement end end end |