Class: PromptScrub::Detector
- Inherits:
-
Object
- Object
- PromptScrub::Detector
- Defined in:
- lib/promptscrub/detector.rb
Direct Known Subclasses
PromptScrub::Detectors::CreditCard, PromptScrub::Detectors::Email, PromptScrub::Detectors::Phone, PromptScrub::Detectors::SSN
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, pattern) ⇒ Detector
constructor
A new instance of Detector.
- #scan(text) ⇒ Object
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
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
5 6 7 |
# File 'lib/promptscrub/detector.rb', line 5 def pattern @pattern end |
#type ⇒ Object (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 |