Skip to content

Instantly share code, notes, and snippets.

@timd
Created December 11, 2012 17:45
Show Gist options
  • Save timd/4260564 to your computer and use it in GitHub Desktop.
Save timd/4260564 to your computer and use it in GitHub Desktop.
An example random data creator
#!/bin/env ruby
# encoding: utf-8
require "faker"
require 'random_data'
require 'json'
randomPostcode = Random.uk_post_code
randomAddress = Random.address_line_1 + " " + Random.address_line_2 + " " + randomPostcode
customer_hash = {
"name" => Faker::Name.name,
"address" => randomAddress,
"postcode" => randomPostcode
}
@json = JSON.pretty_generate(customer_hash)
puts @json
begin
File.delete("output.json")
file = File.open("output.json", "w")
file.write(@json)
rescue IOError => e
#some error occur, dir not writable etc.
ensure
file.close unless file == nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment