random_data
This gem provides a Random singleton class with a series of methods for generating random test data including names, mailing addresses, dates, phone numbers, e-mail addresses, and text. Instead of:
foo.name = "John Doe"
You get:
foo.name = "#{Random.firstname} #{Random.initial} #{Random.lastname}"
Installation
sudo gem install random_data
or get the gem manually from rubyforge.org/frs/?group_id=4458
Methods
Contact Methods
Random.phone, Random.international_phone, Random.email
Time/Date Methods
Random.date, Random.date_between
Location Methods
Random.address_line_1, Random.address_line_2, Random.zipcode, Random.uk_post_code, Random.state_code, Random.state_full, Random.country, Random.city
Name Methods
Random.firstname, Random.firstname_male, Random.firstname_female, Random.initial, Random.lastname
Text Methods
Random.alphanumeric, Random.paragraphs
Grammatical Methods
Random.grammatical_construct
Number Methods
Random.number, Random.bit, Random.bits
Boolean Methods
Random.boolean
Markov Generator Methods
Random.MarkovGenerator.new Random.MarkovGenerator.insert Random.MarkovGenerator.generate
Array Extension
Array.rand Array.roulette
Choose From File Methods
Random implements a method_missing helper that will choose a line at random from a file in your load path. See Random::method_missing for details.
Note that some methods take parameters to bound or limit the amount of data returned. See RDocs for details.
Examples of Some Methods
>>Random.alphanumeric => “cfbutm3vYfhZXil0”
>> Random.alphanumeric(5) => “XYVyn”
>> Random.paragraphs => “Ulysses, fighting evil and tyranny with all his power and with all of his might. Ulysses, fighting evil and tyranny with all his power and with all of his might. nnHe’s got style, a groovy style, and a car that just won’t stop. nn”
>> Random.paragraphs(3) => “Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum. Down the road that’s where I’ll always be. He’s got style, a groovy style, and a car that just won’t stop. I’ve gotten burned over Cheryl Tiegs and blown up for Raquel Welch, but when I end up in the hay it’s only hay hey hey. Hey there where ya goin, not exactly knowin’. nnLorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. I might jump an open drawbridge or Tarzan from a vine, beause I’m the unknown stuntman that makes Eastwood look so fine. He just keeps on movin’ and ladies keep improvin’. Rolling down to Dallas - who is providin my palace?. Every stop I make I make a new friend; Can’t stay for long just turn around and I’m gone again. nnAlways fighting all the evil forces bringing peace and justice to all. nn”
>> Random.firstname => “Thomas”
>> Random.initial => “E”
>> Random.lastname => “Robinson”
>> Random.date => Sun, 09 Sep 2007
(Returns an actual date object, shown here in its to_s form) >> Random.date(1000) => Sun, 26 Nov 2006
>> Random.email => “[email protected]”
>> Random.phone => “564-103-8353”
>> Random.international_phone => “011-24-37-9704”
>> Random.address_line_1 => “38367 Adams Rd”
>> Random.address_line_2 => “Lot 247”
>> Random.zipcode => 22904
(Note that the zipcodes are totally random and may not be real zipcodes)
>> Random.state_code => “MD”
>> Random.state_full => “New Mexico”
>> Random.country => “Philippines”
Contact
Let me know if you have patches, comments, or suggestions: [email protected]
Special Thanks
Major thanks to Hugh Sasse and Paul Barry for their contributions.
Copyright
Copyright © 2008 Mike Subelsky, Baltimore, Maryland, released under the MIT license.