Class: Memorandom::Plugins::CC
- Inherits:
-
Memorandom::PluginTemplate
- Object
- Memorandom::PluginTemplate
- Memorandom::Plugins::CC
- Defined in:
- lib/memorandom/plugins/cc.rb
Constant Summary collapse
- @@description =
"This plugin looks for credit card numbers"
- @@confidence =
0.10
Instance Attribute Summary
Attributes inherited from Memorandom::PluginTemplate
Instance Method Summary collapse
-
#scan(buffer, source_offset) ⇒ Object
Scan takes a buffer and an offset of where this buffer starts in the source.
Methods inherited from Memorandom::PluginTemplate
#confidence, confidence, #description, description, #initialize, #report_hit, #reset
Constructor Details
This class inherits a constructor from Memorandom::PluginTemplate
Instance Method Details
#scan(buffer, source_offset) ⇒ Object
Scan takes a buffer and an offset of where this buffer starts in the source
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/memorandom/plugins/cc.rb', line 12 def scan(buffer, source_offset) buffer.scan( # Look for credit card numbers in various formats /(?:^|\D)([\d \-]{12,32})(?:$|\D)/ ).each do |m| matched = m.first # This may hit an earlier identical match, but thats ok last_offset = buffer.index(matched) next unless last_offset # Clean out any non-digits and validate the card cleaned = matched.gsub(/[^\d]+/, '') next unless CreditCardValidator::Validator.valid?(cleaned) cc_type = CreditCardValidator::Validator.card_type(cleaned) cc_type = cc_type.split('_').map{|x| x.capitalize }.join report_hit(:type => "CreditCard(#{cc_type})", :data => cleaned, :offset => source_offset + last_offset) end end |