Class: PromptScrub::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/promptscrub/detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, pattern) ⇒ Detector

Returns a new instance of Detector.



7
8
9
10
# File 'lib/promptscrub/detector.rb', line 7

def initialize(type, pattern)
  @type    = type.to_s.upcase
  @pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/promptscrub/detector.rb', line 5

def pattern
  @pattern
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/promptscrub/detector.rb', line 5

def type
  @type
end

Instance Method Details

#scan(text) ⇒ Object



12
13
14
# File 'lib/promptscrub/detector.rb', line 12

def scan(text)
  text.scan(pattern).map { |m| m.is_a?(Array) ? m.first : m }.uniq
end