Skip to content

Instantly share code, notes, and snippets.

@rogerleite
Last active Dec 16, 2015
Embed
What would you like to do?
CSV data generator for lazy people like me.
#!/usr/bin/ruby
# Tested on ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin11.4.2]
# Usage:
# $ bundle install
#
# $ bundle exec ./big_bang # see available actions
# $ TOTAL=100 bundle exec ./big_bang users > users.csv # generate a csv with 100 users
require 'uuid'
require 'faker'
actions = {
"users" => Proc.new do |args|
counter = ENV["TOTAL"].to_i
counter = 5 if counter <= 0
counter.times do |index|
login = "#{UUID.generate}-#{index}"
name = "#{Faker::Name.first_name} #{Faker::Name.last_name}"
puts "#{login}@acme.com,#{name},#{login}"
end
end,
"magic" => Proc.new do |args|
puts "magic"
end
}
## Main ##
action = ARGV[0].to_s
if actions.include?(action)
actions[action].call(ARGV.clone)
else
puts "Invalid action. Available actions are:\n"
actions.keys.each { |action| puts action }
end
source "https://rubygems.org"
gem "faker", "~> 1.1.2"
gem "uuid", "~> 2.3.7"
GEM
remote: https://rubygems.org/
specs:
faker (1.1.2)
i18n (~> 0.5)
i18n (0.6.4)
macaddr (1.6.1)
systemu (~> 2.5.0)
systemu (2.5.2)
uuid (2.3.7)
macaddr (~> 1.0)
PLATFORMS
ruby
DEPENDENCIES
faker (~> 1.1.2)
uuid (~> 2.3.7)
7aae29c0-931f-0130-2e02-3c07543e75e9-0@acme.com Eleanora Schimmel 7aae29c0-931f-0130-2e02-3c07543e75e9-0
7ab25e60-931f-0130-2e02-3c07543e75e9-1@acme.com Brooke Jerde 7ab25e60-931f-0130-2e02-3c07543e75e9-1
7ab261a0-931f-0130-2e02-3c07543e75e9-2@acme.com Deborah Bechtelar 7ab261a0-931f-0130-2e02-3c07543e75e9-2
7ab26440-931f-0130-2e02-3c07543e75e9-3@acme.com Jamison Hammes 7ab26440-931f-0130-2e02-3c07543e75e9-3
7ab26730-931f-0130-2e02-3c07543e75e9-4@acme.com Moriah Barrows 7ab26730-931f-0130-2e02-3c07543e75e9-4
7ab269e0-931f-0130-2e02-3c07543e75e9-5@acme.com Brown Towne 7ab269e0-931f-0130-2e02-3c07543e75e9-5
7ab26c80-931f-0130-2e02-3c07543e75e9-6@acme.com Theresia Gottlieb 7ab26c80-931f-0130-2e02-3c07543e75e9-6
7ab26ef0-931f-0130-2e02-3c07543e75e9-7@acme.com Genevieve Cassin 7ab26ef0-931f-0130-2e02-3c07543e75e9-7
7ab271c0-931f-0130-2e02-3c07543e75e9-8@acme.com Daisy Heller 7ab271c0-931f-0130-2e02-3c07543e75e9-8
7ab27470-931f-0130-2e02-3c07543e75e9-9@acme.com Lauryn Mueller 7ab27470-931f-0130-2e02-3c07543e75e9-9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment