class Fluent::PAN::Masker

Constants

CHECKSUM_FUNC

Public Class Methods

new(regexp, checksum_algorithm, mask, force=false) click to toggle source
# 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

Public Instance Methods

mask_if_found_pan(orgval) click to toggle source
# 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?() click to toggle source
# File lib/fluent/plugin/pan/masker.rb, line 63
def numerals_mask?
  if @mask.to_s =~ /^\d+$/
    true
  else
    false
  end
end
valid?(pan) click to toggle source
# File lib/fluent/plugin/pan/masker.rb, line 59
def valid?(pan)
  @checksum_func.call(pan)
end