Class: TopSecret::Filters::Regex

Inherits:
Object
  • Object
show all
Defined in:
lib/top_secret/filters/regex.rb

Overview

Applies regex-based filtering to extract matching text from input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, regex:) ⇒ Regex

Returns a new instance of Regex.

Parameters:

  • label (String)

    The label for redacted content

  • regex (Regexp)

    The regular expression used to match content



12
13
14
15
# File 'lib/top_secret/filters/regex.rb', line 12

def initialize(label:, regex:)
  @label = label
  @regex = regex
end

Instance Attribute Details

#labelString (readonly)

Returns The label applied to matching content.

Returns:

  • (String)

    The label applied to matching content



8
9
10
# File 'lib/top_secret/filters/regex.rb', line 8

def label
  @label
end

Instance Method Details

#call(input) ⇒ Array<String>

Applies the regex to the input and returns all matches.

Parameters:

  • input (String)

    The input text to scan

Returns:

  • (Array<String>)

    All matches found



21
22
23
# File 'lib/top_secret/filters/regex.rb', line 21

def call(input)
  input.scan(regex)
end