Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
easy to understand, and use, ruby based, contact generator
# Copyright 2014, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
puts ARGV.count
if ARGV.count < 1
puts "Missing argument - number of contacts"
exit
end
first_name = "First"
last_name = "Last"
domain = "invalid.domain"
if ARGV.count == 4
first_name = ARGV[1]
last_name = ARGV[2]
domain = ARGV[3]
end
email_address = first_name + "." + last_name
puts "attempting to generate file for " + ARGV[0] + " contacts ("+ARGV[0]+"contacts.csv) - with first name: " + first_name + " and last name: " + last_name
contact_count = Integer(ARGV[0])
File.open(ARGV[0]+"contacts.csv", 'w') { |f|
f.write("id,first name, last name, email\n")
for i in 1..contact_count do
f.write(i.to_s + "," + i.to_s + first_name + "," + last_name + i.to_s + ","+email_address + i.to_s + "\@"+domain+"\n")
end
}
@fraxedas

This comment has been minimized.

Copy link

@fraxedas fraxedas commented May 16, 2014

for i in 1..contact_count do
f.write("" + i.to_s + "," + i.to_s + first_name + "," + last_name + i.to_s + ","+email_address + i.to_s + "@"+domain+"\n")
end

That will generate the id field

@aausch

This comment has been minimized.

Copy link
Owner Author

@aausch aausch commented May 16, 2014

thanks1

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