Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def format_ssns(string)
- # get array of ssns without damaging string
- string_copy = string.dup
- array_of_ssns = grab_all_ssns(string_copy)
- # remove all non-numbers from ssn in the array
- array_of_ssns.map! do |ssn|
- ssn = ssn.gsub(/\D/, "")
- # insert dashes in the correct places
- ssn = ssn.insert(3, "-").insert(6, "-")
- end
- # loop through ssns in string and replace with index[0] of ssn array
- string_as_array = string.split(' ')
- string_as_array.map! do |word|
- if word =~ /\d{3}\D*\d{2}\D*\d{4}(.*)/
- additional = word.match(/\d{3}\D*\d{2}\D*\d{4}(.*)/)[1]
- ssn_plus_additional = array_of_ssns[0] + additional
- word = ssn_plus_additional
- array_of_ssns.delete_at(0)
- end
- word
- end
- string_as_array.join(' ')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement