Skip to content

Instantly share code, notes, and snippets.

@kayline
Created March 21, 2013 22:41
Show Gist options
  • Save kayline/5217485 to your computer and use it in GitHub Desktop.
Save kayline/5217485 to your computer and use it in GitHub Desktop.
# Determine whether a string contains a Social Security number.
def has_ssn?(string)
#check overall length
if string.length < 11
return false
#check for match
elsif string.match(/\d{3}(-)\d{2}(-)\d{4}/)
return true
else
return false
end
end
# Return the Social Security number from a string.
def grab_ssn(string)
if has_ssn?(string)
result = string.match(/\d{3}(-)\d{2}(-)\d{4}/)
result = result.to_s
return result
else
return nil
end
end
# Return all of the Social Security numbers from a string.
def grab_all_ssns(string)
puts "The input is \"#{string}\""
if has_ssn?(string)
result = string.scan(/\d{3}./)
puts "The match data is #{result}"
matches_array = result.to_a
puts "The grab result for multiple ssns is #{matches_array.inspect}"
matches = matches_array.join(", ")
puts "The string of matches is #{matches}"
return matches
else
puts "No ssn present"
return nil
end
end
# Obfuscate all of the Social Security numbers in a string. Example: XXX-XX-4430.
def hide_all_ssns(string)
end
# Ensure all of the Social Security numbers use dashes for delimiters.
# Example: 480.01.4430 and 480014430 would both be 480-01-4430.
def format_ssns(string)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment