Академический Документы
Профессиональный Документы
Культура Документы
stympy/faker
This repository
Pull requests
Search
Issues
Gist
stympy / faker
Watch
69
Star
2,584
Fork
563
A library for generating fake data such as names, addresses, and phone numbers.
Code
526 commits
branch: master
1 branch
17 releases
132 contributors
faker /
Issues
39
Pull requests
56
Wiki
latest commit 7a4e2a05b8
lib
10 days ago
script
Streamlining a bit
5 years ago
tasks
4 years ago
test
10 days ago
website
4 years ago
.gitignore
2 years ago
.travis.yml
CONTRIBUTING.md
3 years ago
Gemfile
2 years ago
Gemfile.lock
Version bump
10 months ago
History.txt
Version bump
10 months ago
License.txt
Updated copyright
README.md
Rakefile
faker.gemspec
5 days ago
Pulse
Graphs
https://github.com/st
ympy/faker.gi
Clone in Desktop
Download ZIP
5 years ago
9 days ago
2 years ago
9 days ago
README.md
Faker
This gem is a port of Perl's Data::Faker library that generates fake data.
It comes in very handy for taking screenshots (taking screenshots for my project, Catch the Best was
the original impetus for the creation of this gem), having real-looking test data, and having your
database populated with more than one or two records while you're doing development.
Installing
gem install faker
Usage
Faker::Name.name
https://github.com/stympy/faker
1/8
6/9/2015
stympy/faker
Faker::Address
Faker::Address.city #=> "Imogeneborough"
Faker::Address.street_name #=> "Larkin Fork"
Faker::Address.street_address #=> "282 Kevin Brook"
Faker::Address.secondary_address #=> "Apt. 672"
Faker::Address.building_number #=> "7304"
Faker::Address.zip_code #=> "58517"
Faker::Address.zip #=> "58517"
Faker::Address.postcode #=> "58517"
Faker::Address.time_zone #=> "Asia/Yakutsk"
Faker::Address.street_suffix #=> "Street"
Faker::Address.city_suffix #=> "fort"
Faker::Address.city_prefix #=> "Lake"
Faker::Address.state #=> "California"
Faker::Address.state_abbr #=> "AP"
Faker::Address.country #=> "French Guiana"
Faker::Address.country_code #=> "IT"
Faker::Address.latitude #=> "-58.17256227443719"
Faker::Address.longitude #=> "-156.65548382095133"
Faker::Bitcoin
Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"
Faker::Bitcoin.testnet_address #=> ""msHGunDvoEwmVFXvd2Bub1SNw5RP1YHJaf""
Faker::Business
Faker::Business.credit_card_number #=> "1228-1221-1221-1431"
Faker::Business.credit_card_expiry_date #=> <Date: 2015-11-11 ((2457338j,0s,0n),+0s,2299161j)>
Faker::Business.credit_card_type #=> "visa"
Faker::Code
Faker::Code.isbn #=> "759021701-8"
Faker::Code.ean #=> "4600051000057"
https://github.com/stympy/faker
2/8
6/9/2015
stympy/faker
Faker::Commerce
Faker::Commerce.color #=> "lavender"
# Optional arguments max=3, fixed_amount=false
Faker::Commerce.department #=> "Grocery, Health & Beauty"
Faker::Commerce.department(5) #=> "Grocery, Books, Health & Beauty"
Faker::Commerce.department(2, true) #=> "Books & Tools"
Faker::Commerce.product_name #=> "Practical Granite Shirt"
Faker::Commerce.price #=> "44.6"
Faker::Company
Faker::Company.name #=> "Hirthe-Ritchie"
Faker::Company.suffix #=> "Group"
# Generate a buzzword-laden catch phrase.
Faker::Company.catch_phrase #=> "Business-focused coherent parallelism"
# When a straight answer won't do, BS to the rescue!
Faker::Company.bs #=> "empower one-to-one web-readiness"
Faker::Company.ein #=> "34-8488813"
Faker::Company.duns_number #=> "08-341-3736"
# Get a random company logo url in PNG format.
Faker::Company.logo #=> "http://pigment.github.com/fake-logos/logos/medium/color/5.png"
Faker::Date
# Random date between dates
Faker::Date.between(2.days.ago, Date.today) #=> "Wed, 24 Sep 2014"
# Random date in the future (up to maximum of N days)
Faker::Date.forward(23) # => "Fri, 03 Oct 2014"
# Random date in the past (up to maximum of N days)
Faker::Date.backward(14) #=> "Fri, 19 Sep 2014"
Faker::Internet
# Optional argument name=nil
Faker::Internet.email #=> "eliza@mann.net"
Faker::Internet.email('Nancy') #=> "nancy@terry.biz"
# Optional argument name=nil
Faker::Internet.free_email #=> "freddy@gmail.com"
Faker::Internet.free_email('Nancy') #=> "nancy@yahoo.com"
# Optional argument name=nil
Faker::Internet.safe_email #=> "christelle@example.org"
Faker::Internet.safe_email('Nancy') #=> "nancy@example.net"
https://github.com/stympy/faker
3/8
6/9/2015
stympy/faker
# Optional arguments specifier=nil, separators=%w(. _)
Faker::Internet.user_name #=> "alexie"
Faker::Internet.user_name('Nancy') #=> "nancy"
Faker::Internet.user_name('Nancy Johnson', %w(. _ -)) #=> "johnson-nancy"
# Optional arguments: min_length=8, max_length=16
Faker::Internet.password #=> "vg5msvy1uerg7"
Faker::Internet.password(8) #=> "yfgjik0hgzdqs0"
Faker::Internet.password(10, 20) #=> "eoc9shwd1hwq4vbgfw"
Faker::Internet.domain_name #=> "effertz.info"
Faker::Internet.fix_umlauts('') #=> "aeoeuess"
Faker::Internet.domain_word #=> "haleyziemann"
Faker::Internet.domain_suffix #=> "info"
Faker::Internet.ip_v4_address #=> "24.29.18.175"
Faker::Internet.ip_v6_address #=> "ac5f:d696:3807:1d72:2eb5:4e81:7d2b:e1df"
# Optional argument prefix=''
Faker::Internet.mac_address #=> "e6:0d:00:11:ed:4f"
Faker::Internet.mac_address('55:44:33') #=> "55:44:33:02:1d:9b"
# Optional arguments: host=domain_name, path="/#{user_name}"
Faker::Internet.url #=> "http://thiel.com/chauncey_simonis"
Faker::Internet.url('example.com') #=> "http://example.com/clotilde.swift"
Faker::Internet.url('example.com', '/foobar.html') #=> "http://example.com/foobar.html"
# Optional arguments: words=nil, glue=nil
Faker::Internet.slug #=> "pariatur_laudantium"
Faker::Internet.slug('foo bar') #=> "foo.bar"
Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
Faker::Lorem
Faker::Lorem.word #=> "repellendus"
# Optional arguments: num=3, supplemental=false
Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]
https://github.com/stympy/faker
4/8
6/9/2015
stympy/faker
Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequunt
Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitati
Faker::Lorem.paragraph(2, true) #=> "Cedo vero adipisci. Theatrum crustulum coaegresco tonsor crastinus stabilis. Aliqua c
Faker::Lorem.paragraph(2, false, 4) #=> "Neque aut et nemo aut incidunt voluptates. Dolore cum est sint est. Vitae assumen
Faker::Lorem.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum."
Faker::Name
Faker::Name.name #=> "Tyshawn Johns Sr."
Faker::Name.first_name #=> "Kaci"
Faker::Name.last_name #=> "Ernser"
Faker::Name.prefix #=> "Mr."
Faker::Name.suffix #=> "IV"
Faker::Name.title #=> "Legacy Creative Director"
Faker::Avatar
Faker::Avatar.image #=> "http://robohash.org/sitsequiquia.png?size=300x300"
Faker::Avatar.image("my-own-slug") #=> "http://robohash.org/my-own-slug.png?size=300x300"
Faker::Avatar.image("my-own-slug", "50x50") #=> "http://robohash.org/my-own-slug.png?size=50x50"
Faker::Avatar.image("my-own-slug", "50x50", "jpg") #=> "http://robohash.org/my-own-slug.jpg?size=50x50"
Faker::Avatar.image("my-own-slug", "50x50", "bmp") #=> "http://robohash.org/my-own-slug.bmp?size=50x50"
Faker::Number
# Required parameter: digits
Faker::Number.number(10) #=> "1968353479"
Faker::Number.digit #=> "1"
Faker::PhoneNumber
Phone numbers may be in any of the following formats:
333-333-3333
(333) 333-3333
1-333-333-3333
333.333.3333
333-333-3333
333-333-3333 x3333
(333) 333-3333 x3333
1-333-333-3333 x3333
https://github.com/stympy/faker
5/8
6/9/2015
stympy/faker
333.333.3333 x3333
(Don't let the example output below fool you - any format can be returned at random.)
Faker::PhoneNumber.phone_number #=> "397.693.1309"
Faker::PhoneNumber.cell_phone #=> "(186)285-7925"
# NOTE NOTE NOTE NOTE
# For the 'US only' methods below, first you must do the following:
Faker::Config.locale = 'en-US'
# US only
Faker::PhoneNumber.area_code #=> "201"
# US only
Faker::PhoneNumber.exchange_code #=> "208"
# Optional parameter: length=4
Faker::PhoneNumber.subscriber_number #=> "3873"
Faker::PhoneNumber.subscriber_number(2) #=> "39"
Faker::PhoneNumber.extension #=> "3764"
Faker::Time
# Random date between dates
Faker::Time.between(DateTime.now - 1, DateTime.now) #=> "2014-09-18 12:30:59 -0700"
# Random date between dates (within specified part of the day)
# You can install the active_support gem to facilitate time manipulation like 45.minutes + 2.hours
require "as-duration"
Faker::Time.between(2.days.ago, Time.now, :all) #=> "2014-09-19 07:03:30 -0700"
Faker::Time.between(2.days.ago, Time.now, :day) #=> "2014-09-18 16:28:13 -0700"
Faker::Time.between(2.days.ago, Time.now, :night) #=> "2014-09-20 19:39:38 -0700"
Faker::Time.between(2.days.ago, Time.now, :morning) #=> "2014-09-19 08:07:52 -0700"
Faker::Time.between(2.days.ago, Time.now, :afternoon) #=> "2014-09-18 12:10:34 -0700"
Faker::Time.between(2.days.ago, Time.now, :evening) #=> "2014-09-19 20:21:03 -0700"
Faker::Time.between(2.days.ago, Time.now, :midnight) #=> "2014-09-20 00:40:14 -0700"
# Random time in the future (up to maximum of N days)
Faker::Time.forward(23, :morning) # => "2014-09-26 06:54:47 -0700"
# Random time in the past (up to maximum of N days)
Faker::Time.backward(14, :evening) #=> "2014-09-17 19:56:33 -0700"
Faker::Hacker
Are you having trouble writing tech-savvy dialogue for your latest screenplay? Worry not! Hollywoodgrade technical talk is ready to fill out any form where you need to look smart.
# Full Phrase
Faker::Hacker.say_something_smart #=> "Try to compress the SQL interface, maybe it will program the back-end hard drive!"
# Short technical abbreviations
Faker::Hacker.abbreviation #=> "RAM"
# Hacker centric adjectives
Faker::Hacker.adjective #=> "open-source"
# Only the best hacker related nouns
Faker::Hacker.noun #=> "bandwidth"
https://github.com/stympy/faker
6/8
6/9/2015
stympy/faker
# Actions that hackers take
Faker::Hacker.verb #=> "bypass"
# Verbs that end in -ing
Faker::Hacker.ingverb #=> "synthesizing"
Faker::App
Faker::App.name #=> "Treeflex"
Faker::App.version #=> "0.7.9"
Faker::App.author #=> "Daphne Swift"
Faker::SlackEmoji
# Random Slack Emoji from people category
Faker::SlackEmoji.people #=> ":sleepy:"
# Random Slack Emoji from nature category
Faker::SlackEmoji.nature #=> ":chestnut:"
# Random Slack Emoji from food and drink category
Faker::SlackEmoji.food_and_drink #=> ":tangerine:"
# Random Slack Emoji from celebration category
Faker::SlackEmoji.celebration #=> ":ribbon:"
# Random Slack Emoji from activity category
Faker::SlackEmoji.activity #=> ":performing_arts:"
# Random Slack Emoji from travel and places category
Faker::SlackEmoji.travel_and_places #=> ":truck:"
# Random Slack Emoji from objects & symbols category
Faker::SlackEmoji.objects_and_symbols #=> ":alarm_clock:"
# Random Slack Emoji from custom category
Faker::SlackEmoji.custom #=> ":suspect:"
# Random Slack Emoji from any category
Faker::SlackEmoji.emoji #=> ":last_quarter_moon:"
Customization
Since you may want to make addresses and other types of data look different depending on where in
the world you are (US postal codes vs. UK postal codes, for example), Faker uses the I18n gem to
store strings (like state names) and formats (US postal codes are NNNNN while UK postal codes are
AAN NAA), allowing you to get different formats by switching locales. Just set Faker::Config.locale to
the locale you want, and Faker will take care of the rest.
If your locale doesn't already exist, create it in the liblocales directory and you can then override or
add elements to suit
en-au-ocker:
faker:
name:
# Existing faker field, new data
first_name: [Charlotte, Ava, Chloe, Emily]
# New faker fields
https://github.com/stympy/faker
7/8
6/9/2015
stympy/faker
ocker_first_name: [Bazza, Bluey, Davo, Johno, Shano, Shazza]
region: [South East Queensland, Wide Bay Burnett, Margaret River, Port Pirie, Gippsland, Elizabeth, Barossa]
Contributing
See CONTRIBUTING.md.
Contact
Comments and feedback are welcome. Send an email to Benjamin Curtis via the google group.
License
This code is free to use under the terms of the MIT license.
Terms
Privacy
https://github.com/stympy/faker
Security
Contact
Status
API
Training
Shop
Blog
About
8/8