Created
February 26, 2013 01:13
-
-
Save JeffreyATW/5034913 to your computer and use it in GitHub Desktop.
Generates a nice list of names for addressing purposes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def address_name | |
families = [] | |
last_names = {} | |
guests.each do |guest| | |
# Discard if name has question marks | |
unless guest.name =~ /\?/ | |
names = guest.name.split(' ') | |
# Discard if last name isn't uppercase | |
if names.last =~ /[A-Z]/ | |
# If last name ends with a period, it's a suffix | |
if names.last =~ /\.$/ | |
# Add to last name list for penultimate word | |
(last_names[names[-2]] ||= []) << names.first | |
else | |
(last_names[names.last] ||= []) << names.first | |
end | |
end | |
end | |
end | |
last_names.each do |last_name, first_names| | |
if first_names.length > 4 | |
families << "The #{last_name} Family" | |
else | |
families << first_names.to_sentence + ' ' + last_name | |
end | |
end | |
families.to_sentence | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment