class DataAnon::Strategy::Field::RandomFormattedString
Keeping the format same it changes each digit with random digit, character with character preserving the case.
!!!ruby anonymize('PhoneNumber').using FieldStrategy::RandomFormattedString.new anonymize('Email').using FieldStrategy::RandomFormattedString.new
Constants
- CAPS_CHARS
- SMALL_CHARS
Public Instance Methods
Source
# File lib/strategy/field/string/random_formatted_string.rb, line 16 def anonymize field @original_string = field.value @anonymized_string = "" @original_string.each_char do |char| if /\d/.match(char) @anonymized_string += DataAnon::Utils::RandomInt.generate(0, 9).to_s elsif /[a-z]/.match(char) @anonymized_string += SMALL_CHARS[rand(SMALL_CHARS.length)] elsif /[A-Z]/.match(char) @anonymized_string += CAPS_CHARS[rand(CAPS_CHARS.length)] else @anonymized_string += char end end @anonymized_string end