Class: Fluent::PAN::Masker
- Inherits:
-
Object
- Object
- Fluent::PAN::Masker
- Defined in:
- lib/fluent/plugin/pan/masker.rb
Constant Summary collapse
- CHECKSUM_FUNC =
{ luhn: ->(digits){ sum = 0 alt = false digits.reverse.each do |i| if alt i *= 2 if i > 9 i -= 9 end end sum += i alt = !alt end (sum % 10).zero? }, none: ->digits{ # Do nothing. always satisfied. true } }
Instance Method Summary collapse
-
#initialize(regexp, checksum_algorithm, mask, force = false) ⇒ Masker
constructor
A new instance of Masker.
- #mask_if_found_pan(orgval) ⇒ Object
- #numerals_mask? ⇒ Boolean
- #valid?(pan) ⇒ Boolean
Constructor Details
#initialize(regexp, checksum_algorithm, mask, force = false) ⇒ Masker
Returns a new instance of Masker.
26 27 28 29 30 31 |
# File 'lib/fluent/plugin/pan/masker.rb', line 26 def initialize(regexp, checksum_algorithm, mask, force=false) @regexp = regexp @mask = mask @force = force @checksum_func = CHECKSUM_FUNC[checksum_algorithm] end |
Instance Method Details
#mask_if_found_pan(orgval) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fluent/plugin/pan/masker.rb', line 33 def mask_if_found_pan(orgval) filtered = orgval.to_s.gsub(@regexp) do |match| pan = match.split("").select { |i| i =~ /\d/ }.map { |j| j.to_i } if valid?(pan) match = @mask else match end end retval = filtered if orgval.is_a? Integer if numerals_mask? retval = filtered.to_i else if @force retval = filtered else retval = orgval end end end retval end |
#numerals_mask? ⇒ Boolean
63 64 65 66 67 68 69 |
# File 'lib/fluent/plugin/pan/masker.rb', line 63 def numerals_mask? if @mask.to_s =~ /^\d+$/ true else false end end |
#valid?(pan) ⇒ Boolean
59 60 61 |
# File 'lib/fluent/plugin/pan/masker.rb', line 59 def valid?(pan) @checksum_func.call(pan) end |