class PIIDetector::Comparator
Public Class Methods
similar?(desired, check)
click to toggle source
@param desired [String] @param check [String] @return [Boolean] or [MatchData]
# File lib/pii_detector/comparator.rb, line 12 def similar?(desired, check) standardized_desired_str = desired.strip.underscore standardized_check_str = check.strip.underscore return false if standardized_check_str.length <= 1 score = Levenshtein.distance(standardized_desired_str, standardized_check_str) standardized_check_str == standardized_desired_str || standardized_check_str.match(/^#{standardized_desired_str}_/) || standardized_check_str.match(/_#{standardized_desired_str}?/) || standardized_check_str.match(/[a-z\d]*_#{standardized_desired_str}_[a-z\d]*/) || (PIIDetector.config.edit_distance < standardized_check_str.length && score < PIIDetector.config.edit_distance) end