Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 448 lines (291 sloc) 12.362 kb
6b985c9 Benjamin Curtis Tidying up a bit
authored
1 Faker
2 =====
8b887cd Alex Antonov ean integration
asiniy authored
3 This gem is a port of Perl's Data::Faker library that generates fake data.
6b985c9 Benjamin Curtis Tidying up a bit
authored
4
5 It comes in very handy for taking screenshots (taking screenshots for my
6 project, [Catch the Best](http://catchthebest.com/) was the original impetus
7 for the creation of this gem), having real-looking test data, and having your
8 database populated with more than one or two records while you're doing
9 development.
10
42a4d33 Michael Minton Added install instructions to ReadMe.
minton authored
11 Installing
12 ----------
13 ```bash
5a839ff T.J. Schuck Don't recommend installing gem with sudo
tjschuck authored
14 gem install faker
42a4d33 Michael Minton Added install instructions to ReadMe.
minton authored
15 ```
16
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
17 ##Usage
6b985c9 Benjamin Curtis Tidying up a bit
authored
18 -----
1690240 Chris Knadler Wraps usage section of readme in a ruby code block
cknadler authored
19 ```ruby
20 Faker::Name.name #=> "Christophe Bartell"
21
22 Faker::Internet.email #=> "kirsten.greenholt@corkeryfisher.info"
23 ```
6b985c9 Benjamin Curtis Tidying up a bit
authored
24
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
25 ###Faker::Address
26 -----------------
27
28 ```ruby
29 Faker::Address.city #=> "Imogeneborough"
30
31 Faker::Address.street_name #=> "Larkin Fork"
32
33 Faker::Address.street_address #=> "282 Kevin Brook"
34
35 Faker::Address.secondary_address #=> "Apt. 672"
36
37 Faker::Address.building_number #=> "7304"
38
39 Faker::Address.zip_code #=> "58517"
40
41 Faker::Address.zip #=> "58517"
42
43 Faker::Address.postcode #=> "58517"
44
45 Faker::Address.time_zone #=> "Asia/Yakutsk"
46
47 Faker::Address.street_suffix #=> "Street"
48
49 Faker::Address.city_suffix #=> "fort"
50
51 Faker::Address.city_prefix #=> "Lake"
52
53 Faker::Address.state_abbr #=> "AP"
54
55 Faker::Address.state #=> "California"
56
57 Faker::Address.country #=> "French Guiana"
58
59 Faker::Address.latitude #=> "-58.17256227443719"
60
61 Faker::Address.longitude #=> "-156.65548382095133"
62
63
64 ```
65
66 ###Faker::Bitcoin
67 -----------------
68
69 ```ruby
70
71 Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"
1823e48 Dawid Sklodowski Update README
dawid-sklodowski authored
72 Faker::Bitcoin.testnet_address #=> ""msHGunDvoEwmVFXvd2Bub1SNw5RP1YHJaf""
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
73
74 ```
75
76 ###Faker::Business
77 ------------------
78
79 ```ruby
80
81 Faker::Business.credit_card_number #=> "1228-1221-1221-1431"
82
83 Faker::Business.credit_card_expiry_date #=> <Date: 2015-11-11 ((2457338j,0s,0n),+0s,2299161j)>
84
85 Faker::Business.credit_card_type #=> "visa"
86
87 ```
88
89 ###Faker::Code
90 --------------
91
92 ```ruby
93
94 Faker::Code.isbn #=> "759021701-8"
95
8b887cd Alex Antonov ean integration
asiniy authored
96 Faker::Code.ean #=> "4600051000057"
97
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
98 ```
99
100 ###Faker::Commerce
101 ------------------
102
103 ```ruby
104
105 Faker::Commerce.color #=> "lavender"
106
4999019 Maarten van Grootel Update commerce.department to return department based on random combinat...
maartenvg authored
107 # Optional arguments max=3, fixed_amount=false
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
108 Faker::Commerce.department #=> "Grocery, Health & Beauty"
4999019 Maarten van Grootel Update commerce.department to return department based on random combinat...
maartenvg authored
109 Faker::Commerce.department(5) #=> "Grocery, Books, Health & Beauty"
110 Faker::Commerce.department(2, true) #=> "Books & Tools"
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
111
112 Faker::Commerce.product_name #=> "Practical Granite Shirt"
113
8b8012f updated README.md to include Faker::Commerce.price
Cristian Tountzis authored
114 Faker::Commerce.price #=> "44.6"
e5dba9e added breakline in README.md line 111
Cristian Tountzis authored
115
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
116 ```
117
118 ###Faker::Company
119 -----------------
120
121 ```ruby
122
123 Faker::Company.name #=> "Hirthe-Ritchie"
124
125 Faker::Company.suffix #=> "Group"
126
127 # Generate a buzzword-laden catch phrase.
128 Faker::Company.catch_phrase #=> "Business-focused coherent parallelism"
129
130 # When a straight answer won't do, BS to the rescue!
131 Faker::Company.bs #=> "empower one-to-one web-readiness"
132
e59281e Daniel Lockhart Add Employer Identification Number generation to Faker::Company
Lockyy authored
133 Faker::Company.ein #=> "34-8488813"
134
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
135 Faker::Company.duns_number #=> "08-341-3736"
136
e3516ee Sam Oliver Use more realistic logos
samoli authored
137 # Get a random company logo url in PNG format.
138 Faker::Company.logo #=> "http://pigment.github.com/fake-logos/logos/medium/color/5.png"
65921be Cole Hecht Add logo generator
colehecht authored
139
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
140 ```
141
ecdced1 Eric Hayes Added faker date documentation as well.
ejhayes authored
142 ###Faker::Date
143 ---------------------
144
145 ```ruby
e0031ef Dennis Charles Hackethal Update README.md
dchacke authored
146 # Random date between dates
ecdced1 Eric Hayes Added faker date documentation as well.
ejhayes authored
147 Faker::Date.between(2.days.ago, Date.today) #=> "Wed, 24 Sep 2014"
148
e0031ef Dennis Charles Hackethal Update README.md
dchacke authored
149 # Random date in the future (up to maximum of N days)
ecdced1 Eric Hayes Added faker date documentation as well.
ejhayes authored
150 Faker::Date.forward(23) # => "Fri, 03 Oct 2014"
151
e0031ef Dennis Charles Hackethal Update README.md
dchacke authored
152 # Random date in the past (up to maximum of N days)
ecdced1 Eric Hayes Added faker date documentation as well.
ejhayes authored
153 Faker::Date.backward(14) #=> "Fri, 19 Sep 2014"
154 ```
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
155
156 ###Faker::Internet
157 ---------------
158
159 ```ruby
160 # Optional argument name=nil
161 Faker::Internet.email #=> "eliza@mann.net"
162
163 Faker::Internet.email('Nancy') #=> "nancy@terry.biz"
164
165 # Optional argument name=nil
166 Faker::Internet.free_email #=> "freddy@gmail.com"
167
168 Faker::Internet.free_email('Nancy') #=> "nancy@yahoo.com"
169
170 # Optional argument name=nil
171 Faker::Internet.safe_email #=> "christelle@example.org"
172
173 Faker::Internet.safe_email('Nancy') #=> "nancy@example.net"
174
175 # Optional arguments specifier=nil, separators=%w(. _)
176 Faker::Internet.user_name #=> "alexie"
177
178 Faker::Internet.user_name('Nancy') #=> "nancy"
179
180 Faker::Internet.user_name('Nancy Johnson', %w(. _ -)) #=> "johnson-nancy"
181
18068f9 Jordan Luyke modify password to use Lorem.characters
jluyke authored
182 # Optional arguments: min_length=8, max_length=16
183 Faker::Internet.password #=> "vg5msvy1uerg7"
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
184
18068f9 Jordan Luyke modify password to use Lorem.characters
jluyke authored
185 Faker::Internet.password(8) #=> "yfgjik0hgzdqs0"
186
187 Faker::Internet.password(10, 20) #=> "eoc9shwd1hwq4vbgfw"
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
188
189 Faker::Internet.domain_name #=> "effertz.info"
190
191 Faker::Internet.fix_umlauts('äöüß') #=> "aeoeuess"
192
193 Faker::Internet.domain_word #=> "haleyziemann"
194
195 Faker::Internet.domain_suffix #=> "info"
196
197 Faker::Internet.ip_v4_address #=> "24.29.18.175"
198
199 Faker::Internet.ip_v6_address #=> "ac5f:d696:3807:1d72:2eb5:4e81:7d2b:e1df"
200
546a914 Adam Fabicki Added example for Faker::Internet.mac_address
dr-impossible authored
201 # Optional argument prefix=''
202 Faker::Internet.mac_address #=> "e6:0d:00:11:ed:4f"
203 Faker::Internet.mac_address('55:44:33') #=> "55:44:33:02:1d:9b"
204
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
205 # Optional arguments: host=domain_name, path="/#{user_name}"
206 Faker::Internet.url #=> "http://thiel.com/chauncey_simonis"
207 Faker::Internet.url('example.com') #=> "http://example.com/clotilde.swift"
208 Faker::Internet.url('example.com', '/foobar.html') #=> "http://example.com/foobar.html"
209
210 # Optional arguments: words=nil, glue=nil
211 Faker::Internet.slug #=> "pariatur_laudantium"
212 Faker::Internet.slug('foo bar') #=> "foo.bar"
213 Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
214
215
216 ```
217
218 ###Faker::Lorem
219 ---------------
220
221 ```ruby
222
223 Faker::Lorem.word #=> "repellendus"
224
225 # Optional arguments: num=3, supplemental=false
226 Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
227 Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
228 Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]
229
230 # Optional arguments: char_count=255
231 Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
232 Faker::Lorem.characters(10) #=> "ang9cbhoa8"
233
234 # Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
235 Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
236 Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
237 Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
238 Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
239 Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."
240
241 # Optional arguments: sentence_count=3, supplemental=false
242 Faker::Lorem.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."]
243 Faker::Lorem.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."]
244 Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et ipsum."]
245
246 # Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
247 Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente."
248 Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum."
249 Faker::Lorem.paragraph(2, true) #=> ""
250 Faker::Lorem.paragraph(2, false, 4) #=> ""
251 Faker::Lorem.paragraph(2, true, 4) #=> ""
252
253 # Optional arguments: paragraph_count=3, supplemental=false
254 Faker::Lorem.paragraphs #=> ""
255 Faker::Lorem.paragraphs(1) #=> ""
256 Faker::Lorem.paragraphs(1, true) #=> ""
257
258 ```
259
260 ###Faker::Name
261 --------------
262
263 ```ruby
264
265 Faker::Name.name #=> "Tyshawn Johns Sr."
266
267 Faker::Name.first_name #=> "Kaci"
268
269 Faker::Name.last_name #=> "Ernser"
270
271 Faker::Name.prefix #=> "Mr."
272
273 Faker::Name.suffix #=> "IV"
274
275 Faker::Name.title #=> "Legacy Creative Director"
276
277 ```
278
dd23df1 Lukasz Lazewski Adding Faker::Avatar.image to README to expose it better
luki3k5 authored
279 ###Faker::Avatar
280 ----------------
281
282 ```ruby
283
284 Faker::Avatar.image #=> "http://robohash.org/sitsequiquia.png?size=300x300"
285
286 Faker::Avatar.image("my-own-slug") #=> "http://robohash.org/my-own-slug.png?size=300x300"
287
288 Faker::Avatar.image("my-own-slug", "50x50") #=> "http://robohash.org/my-own-slug.png?size=50x50"
289
290 Faker::Avatar.image("my-own-slug", "50x50", "jpg") #=> "http://robohash.org/my-own-slug.jpg?size=50x50"
291
292 Faker::Avatar.image("my-own-slug", "50x50", "bmp") #=> "http://robohash.org/my-own-slug.bmp?size=50x50"
293 ```
294
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
295 ###Faker::Number
296 ----------------
297
298 ```ruby
299
300 # Required parameter: digits
301 Faker::Number.number(10) #=> "1968353479"
302
303 Faker::Number.digit #=> "1"
304
305 ```
306
307 ###Faker::PhoneNumber
308 ---------------------
309
310 Phone numbers may be in any of the following formats:
311
312 * 333-333-3333
313 * (333) 333-3333
314 * 1-333-333-3333
315 * 333.333.3333
316 * 333-333-3333
317 * 333-333-3333 x3333
318 * (333) 333-3333 x3333
319 * 1-333-333-3333 x3333
320 * 333.333.3333 x3333
321
322 (Don't let the example output below fool you - any format can be returned at random.)
323
324 ```ruby
325
326 Faker::PhoneNumber.phone_number #=> "397.693.1309"
327
328 Faker::PhoneNumber.cell_phone #=> "(186)285-7925"
329
330 # NOTE NOTE NOTE NOTE
331 # For the 'US only' methods below, first you must do the following:
bd49660 Graeme Britz update Config.locale example in README
grbritz authored
332 Faker::Config.locale = 'en-US'
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
333
334 # US only
335 Faker::PhoneNumber.area_code #=> "201"
336
337 # US only
338 Faker::PhoneNumber.exchange_code #=> "208"
339
340 # Optional parameter: length=4
341 Faker::PhoneNumber.subscriber_number #=> "3873"
342
343 Faker::PhoneNumber.subscriber_number(2) #=> "39"
344
345 Faker::PhoneNumber.extension #=> "3764"
346
347 ```
348
07807a1 Eric Hayes Updated README to include Faker::Time
ejhayes authored
349 ###Faker::Time
350 ---------------------
351
352 ```ruby
353 # Random date between dates
354 Faker::Time.between(2.days.ago, Time.now) #=> "2014-09-18 12:30:59 -0700"
355
356 # Random date between dates (within specified part of the day)
357 Faker::Time.between(2.days.ago, Time.now, :all) #=> "2014-09-19 07:03:30 -0700"
358 Faker::Time.between(2.days.ago, Time.now, :day) #=> "2014-09-18 16:28:13 -0700"
359 Faker::Time.between(2.days.ago, Time.now, :night) #=> "2014-09-20 19:39:38 -0700"
360 Faker::Time.between(2.days.ago, Time.now, :morning) #=> "2014-09-19 08:07:52 -0700"
361 Faker::Time.between(2.days.ago, Time.now, :afternoon) #=> "2014-09-18 12:10:34 -0700"
362 Faker::Time.between(2.days.ago, Time.now, :evening) #=> "2014-09-19 20:21:03 -0700"
363 Faker::Time.between(2.days.ago, Time.now, :midnight) #=> "2014-09-20 00:40:14 -0700"
364
365 # Random time in the future (up to maximum of N days)
366 Faker::Time.forward(23, :morning) # => "2014-09-26 06:54:47 -0700"
367
368 # Random time in the past (up to maximum of N days)
369 Faker::Time.backward(14, :evening) #=> "2014-09-17 19:56:33 -0700"
370 ```
371
85be8ab dima-groupon Adding hacker related phrases for times when you need to sound smart on ...
dima-groupon authored
372 ###Faker::Hacker
373 ---------------------
374 Are you having trouble writing tech-savvy dialogue for your latest screenplay?
375 Worry not! Hollywood-grade technical talk is ready to fill out any form where you need to look smart.
376
377 ```ruby
378 # Full Phrase
379 Faker::Hacker.say_something_smart #=> "Try to compress the SQL interface, maybe it will program the back-end hard drive!"
380
381 # Short technical abbreviations
382 Faker::Hacker.abbreviation #=> "RAM"
383
384 # Hacker centric adjectives
385 Faker::Hacker.adjective #=> "open-source"
386
387 # Only the best hacker related nouns
388 Faker::Hacker.noun #=> "bandwidth"
389
390 # Actions that hackers take
391 Faker::Hacker.verb #=> "bypass"
392
393 # Verbs that end in -ing
394 Faker::Hacker.ingverb #=> "synthesizing"
395 ```
396
a6fe6a2 Add Faker::App to generate random App details
Hiemanshu Sharma authored
397 ###Faker::App
398 -----------------
399
400 ```ruby
401
402 Faker::App.name #=> "Treeflex"
85be8ab dima-groupon Adding hacker related phrases for times when you need to sound smart on ...
dima-groupon authored
403
a6fe6a2 Add Faker::App to generate random App details
Hiemanshu Sharma authored
404 Faker::App.version #=> "0.7.9"
85be8ab dima-groupon Adding hacker related phrases for times when you need to sound smart on ...
dima-groupon authored
405
a6fe6a2 Add Faker::App to generate random App details
Hiemanshu Sharma authored
406 Faker::App.author #=> "Daphne Swift"
407
408 ```
916fe1c Added usage documentation for all sub-modules within Faker.
Drago authored
409
6b985c9 Benjamin Curtis Tidying up a bit
authored
410 Customization
411 ------------
412 Since you may want to make addresses and other types of data look different
413 depending on where in the world you are (US postal codes vs. UK postal codes,
414 for example), Faker uses the I18n gem to store strings (like state names) and
415 formats (US postal codes are NNNNN while UK postal codes are AAN NAA),
416 allowing you to get different formats by switching locales. Just set
417 Faker::Config.locale to the locale you want, and Faker will take care of the
418 rest.
419
4d4d7c7 Sean Kelly Created some local specifics for Australian region, with some popular fi...
seankellyaus authored
420 If your locale doesn't already exist, create it in the \lib\locales\ directory
421 and you can then override or add elements to suit
422
423 ```yaml
424
425 en-au-ocker:
426 faker:
427 name:
428 # Exiting faker field, new data
429 first_name: [Charlotte, Ava, Chloe, Emily]
a6fe6a2 Add Faker::App to generate random App details
Hiemanshu Sharma authored
430
4d4d7c7 Sean Kelly Created some local specifics for Australian region, with some popular fi...
seankellyaus authored
431 # New faker fields
432 ocker_first_name: [Bazza, Bluey, Davo, Johno, Shano, Shazza]
433 region: [South East Queensland, Wide Bay Burnett, Margaret River, Port Pirie, Gippsland, Elizabeth, Barossa]
a6fe6a2 Add Faker::App to generate random App details
Hiemanshu Sharma authored
434
4d4d7c7 Sean Kelly Created some local specifics for Australian region, with some popular fi...
seankellyaus authored
435 ```
436
6b985c9 Benjamin Curtis Tidying up a bit
authored
437 Contributing
438 ------------
f96d3f0 Igor Kapkov don't have 2 different contributing guide
igas authored
439 See [CONTRIBUTING.md](https://github.com/stympy/faker/blob/master/CONTRIBUTING.md).
b1fd2a5 Dane O'Connor make testing env easier to bootstrap and document in readme
thedeeno authored
440
6b985c9 Benjamin Curtis Tidying up a bit
authored
441 Contact
442 -------
443 Comments and feedback are welcome. Send an email to Benjamin Curtis via the [google group](http://groups.google.com/group/ruby-faker).
444
445 License
446 -------
447 This code is free to use under the terms of the MIT license.
Something went wrong with that request. Please try again.