Skip to content

Instantly share code, notes, and snippets.

@mattfitzgerald
Last active December 25, 2015 13:39
Show Gist options
  • Save mattfitzgerald/6984666 to your computer and use it in GitHub Desktop.
Save mattfitzgerald/6984666 to your computer and use it in GitHub Desktop.
# hacky contact csv maker
# usage: ruby generate_contacts.rb > contacts.csv
require 'rubygems'
require 'faker'
require 'fastercsv'
contacts_to_create = 50
output_path = File.join(File.dirname(__FILE__), "output.csv")
# must be method names
columns = %w(first_name last_name dob gender mobile email drink music happy word)
def choose(a,b)
# because ruby 1.8
(a..b).to_a.choice
end
def dob
choose(1,30).to_s+"/"+choose(1,12).to_s+"/"+"19"+choose(70,90).to_s
end
def first_name
Faker::Name.first_name
end
def last_name
Faker::Name.last_name
end
def drink
drinks = %w(lemonade champagne water prune\ juice)
drinks.sample(choose(1,drinks.length)).join(',')
end
def music
%w(jazz psy\ trance shoe\ gazing ambient).choice
end
def mobile
'0414'+Array.new(6){rand(9)}.join
end
def email
Faker::Internet.email
end
def header(columns)
columns.map{|col| col.gsub('_',' ')}
end
def row(columns)
columns.map{|col| send(col)}
end
def gender
['m','f',nil].choice
end
def happy
[true, false, nil].choice
end
def word
Faker::Lorem.word
end
s = FasterCSV.generate do |csv|
csv << header(columns)
contacts_to_create.times{csv << row(columns)}
end
puts s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment