Last active
January 27, 2016 19:26
-
-
Save saabdoli/97ad1040ec27549307fd to your computer and use it in GitHub Desktop.
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
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.each 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.each do |name_part| | |
name_parts.index(name_parts.map(&:downcase) & numerals).upcase | |
end | |
name_parts.join(' ') | |
else | |
name = name.capitalize | |
end | |
end | |
participants.update_one({ :_id => participant[:_id] }, { "$set" => {:firstName => names[0], :lastName => names[1], :displayName => names[0] + " " + names[1] } }) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment