Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anthonycrumley/c86905e8a80df7892586 to your computer and use it in GitHub Desktop.
Save anthonycrumley/c86905e8a80df7892586 to your computer and use it in GitHub Desktop.
require('mongo')
def client
@client ||= Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'network-dev')
end
def participants
client[:participants]
end
participants.find().each do |participant|
puts participant
numerals = ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii']
if participant[:firstName] and participant[:lastName]
names = [ participant[:firstName], participant[:lastName] ]
names.map! do |name|
# Handle hyphenated names
if name.include? '-'
name.split('-').map(&:capitalize).join('-')
# Handle split up names
elsif name.include? ' '
name_parts = name.split(' ').map(&:capitalize)
# Handle numerals
name_parts.map! do |name_part|
if numerals.include? name_part.downcase
name_part.upcase
else
name_part
end
end
name_parts.join(' ')
else
name.capitalize
end
end
participants.update_one({ :_id => participant[:_id] }, { "$set" => {:firstName => names[0], :lastName => names[1], :displayName => names[0] + " " + names[1] } })
end
end
@saabdoli
Copy link

saabdoli commented Feb 2, 2016

This worked for all my test cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment