1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00
faker/README.md

318 lines
8.4 KiB
Markdown
Raw Normal View History

2016-01-05 17:49:33 +03:00
# faker
2017-02-18 11:44:25 +03:00
[![Build Status](https://travis-ci.org/askn/faker.svg?branch=master)](https://travis-ci.org/askn/faker)
2016-01-05 17:49:33 +03:00
This shard is a port of [Faker](https://github.com/stympy/faker) gem that generates fake data.
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
faker:
github: askn/faker
```
## Usage
```crystal
require "faker"
Faker::Name.name
```
### Faker.seed
If you wish to seed the random data, you can call `Faker.seed number` and then all subsequent calls will be deterministic.
2018-12-08 05:30:13 +03:00
### Faker::Address
2016-01-05 17:49:33 +03:00
```crystal
2016-01-12 09:57:54 +03:00
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.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"
2016-03-28 10:41:33 +03:00
Faker::Address.country_code #=> "IT"
2016-01-12 09:57:54 +03:00
Faker::Address.latitude #=> "-58.17256227443719"
Faker::Address.longitude #=> "-156.65548382095133"
```
2018-12-08 05:30:13 +03:00
### Faker::Business
2016-01-12 09:57:54 +03:00
```crystal
Faker::Business.credit_card_number #=> "1228-1221-1221-1431"
Faker::Business.credit_card_expiry_date #=> <Time: 2015-11-11>
Faker::Business.credit_card_type #=> "visa"
2016-01-05 23:25:13 +03:00
2016-01-05 17:49:33 +03:00
```
2016-01-12 09:57:54 +03:00
2018-12-08 05:30:13 +03:00
### Faker::Commerce
2016-01-06 17:37:20 +03:00
```crystal
2016-01-12 09:57:54 +03:00
Faker::Commerce.color #=> "lavender"
2016-03-28 23:52:01 +03:00
# Optional arguments max=3, fixed_amount=false
2016-01-12 09:57:54 +03:00
Faker::Commerce.department #=> "Grocery, Health & Beauty"
2016-03-28 23:52:01 +03:00
Faker::Commerce.department(5) #=> "Grocery, Books, Health & Beauty"
Faker::Commerce.department(2, true) #=> "Books & Tools"
2016-01-12 09:57:54 +03:00
Faker::Commerce.product_name #=> "Practical Granite Shirt"
Faker::Commerce.price #=> "44.6"
2016-03-28 23:52:01 +03:00
Faker::Commerce.material #=> "Plastic"
2016-01-06 17:37:20 +03:00
```
2018-12-08 05:30:13 +03:00
### Faker::Company
2016-01-05 17:49:33 +03:00
```crystal
2016-01-12 09:57:54 +03:00
Faker::Company.name #=> "Hirthe-Ritchie"
Faker::Company.suffix #=> "Group"
2016-01-17 23:31:08 +03:00
# Get a random company logo url in PNG format.
Faker::Company.logo #=> "https://pigment.github.com/fake-logos/logos/medium/color/5.png"
2016-01-05 17:49:33 +03:00
```
2016-01-12 09:57:54 +03:00
2018-12-08 05:30:13 +03:00
### Faker::Internet
2016-01-05 17:49:33 +03:00
```crystal
2016-01-12 09:57:54 +03:00
# 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"
# 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"
2016-03-28 01:26:33 +03:00
# Optional arguments: min_length=8, max_length=16
Faker::Internet.password #=> "vg5msvy1uerg7"
2016-01-12 09:57:54 +03:00
2016-03-28 01:26:33 +03:00
Faker::Internet.password(8) #=> "yfgjik0hgzdqs0"
Faker::Internet.password(10, 20) #=> "eoc9shwd1hwq4vbgfw"
Faker::Internet.password(10, 20, true) #=> "3k5qS15aNmG"
Faker::Internet.password(10, 20, true, true) #=> "*%NkOnJsH4"
2016-01-12 09:57:54 +03:00
Faker::Internet.domain_name #=> "effertz.info"
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"
2016-01-17 23:31:08 +03:00
# 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"
2016-01-12 09:57:54 +03:00
# Optional arguments: host=domain_name, path="/#{user_name}"
Faker::Internet.url #=> "http://thiel.com/chauncey_simonis"
2016-01-17 23:31:08 +03:00
Faker::Internet.url('example.com') #=> "http://example.com/clotilde.swift"
Faker::Internet.url('example.com', '/foobar.html') #=> "http://example.com/foobar.html"
2016-01-12 09:57:54 +03:00
# 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"
2016-01-05 17:49:33 +03:00
```
2018-12-08 05:30:13 +03:00
### Faker::Lorem
2016-01-05 17:49:33 +03:00
```crystal
2016-01-06 15:21:35 +03:00
2016-01-12 09:57:54 +03:00
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"]
2016-01-05 17:49:33 +03:00
2016-01-12 09:57:54 +03:00
# Optional arguments: char_count=255
Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
Faker::Lorem.characters(10) #=> "ang9cbhoa8"
2016-01-05 17:49:33 +03:00
2016-01-12 09:57:54 +03:00
# Optional arguments: word_count=4, supplemental=false, random_words_to_add=6
Faker::Lorem.sentence #=> "Dolore illum animi et neque accusantium."
Faker::Lorem.sentence(3) #=> "Commodi qui minus deserunt sed vero quia."
Faker::Lorem.sentence(3, true) #=> "Inflammatio denego necessitatibus caelestis autus illum."
2016-01-17 23:31:08 +03:00
Faker::Lorem.sentence(3, false, 4) #=> "Aut voluptatem illum fugit ut sit."
Faker::Lorem.sentence(3, true, 4) #=> "Accusantium tantillus dolorem timor."
2016-01-12 09:57:54 +03:00
# Optional arguments: sentence_count=3, supplemental=false
Faker::Lorem.sentences #=> ["Vero earum commodi soluta.", "Quaerat fuga cumque et vero eveniet omnis ut.", "Cumque sit dolor ut est consequuntur."]
Faker::Lorem.sentences(1) #=> ["Ut perspiciatis explicabo possimus doloribus enim quia."]
Faker::Lorem.sentences(1, true) #=> ["Quis capillus curo ager veritatis voro et ipsum."]
2016-01-05 17:49:33 +03:00
2016-01-12 09:57:54 +03:00
# Optional arguments: sentence_count=3, supplemental=false, random_sentences_to_add=3
Faker::Lorem.paragraph #=> "Neque dicta enim quasi. Qui corrupti est quisquam. Facere animi quod aut. Qui nulla consequuntur consectetur sapiente."
Faker::Lorem.paragraph(2) #=> "Illo qui voluptas. Id sit quaerat enim aut cupiditate voluptates dolorum. Porro necessitatibus numquam dolor quia earum."
Faker::Lorem.paragraph(2, true) #=> ""
2016-01-17 23:31:08 +03:00
Faker::Lorem.paragraph(2, false, 4) #=> "Neque aut et nemo aut incidunt voluptates. Dolore cum est sint est. Vitae assumenda porro odio dolores fugiat. Est voluptatum quia rerum."
Faker::Lorem.paragraph(2, true, 4) #=> "Vomito unde uxor annus. Et patior utilis sursum."
2016-01-12 09:57:54 +03:00
# Optional arguments: paragraph_count=3, supplemental=false
Faker::Lorem.paragraphs #=> ""
Faker::Lorem.paragraphs(1) #=> ""
Faker::Lorem.paragraphs(1, true) #=> ""
2016-01-05 17:49:33 +03:00
```
2018-12-08 05:30:13 +03:00
### Faker::Name
2016-01-05 17:49:33 +03:00
```crystal
2016-01-12 09:57:54 +03:00
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"
2016-01-05 17:49:33 +03:00
```
2018-12-08 05:30:13 +03:00
### Faker::Number
2016-01-06 16:16:07 +03:00
```crystal
2016-01-12 09:57:54 +03:00
# Required parameter: digits
Faker::Number.number(10) #=> "1968353479"
# Required parameter: l_digits
Faker::Number.decimal(2) #=> "11.88"
Faker::Number.decimal(2, 3) #=> "18.843"
2016-03-28 00:08:52 +03:00
# Required parameter: digits
Faker::Number.hexadecimal(3) #=> "e74"
2016-03-27 01:22:56 +03:00
Faker::Number.between(1, 10) #=> 7
Faker::Number.positive #=> 235.59238499107653
Faker::Number.negative #=> -4480.042585669558
2016-01-12 09:57:54 +03:00
Faker::Number.digit #=> "1"
2016-01-06 16:16:07 +03:00
```
2018-12-08 05:30:13 +03:00
### Faker::PhoneNumber
2016-01-05 17:49:33 +03:00
```crystal
2016-01-12 09:57:54 +03:00
Faker::PhoneNumber.phone_number #=> "397.693.1309"
2016-01-05 17:49:33 +03:00
```
2016-03-28 00:08:52 +03:00
### Faker::Hacker
---------------------
Are you having trouble writing tech-savvy dialogue for your latest screenplay?
Worry not! Hollywood-grade technical talk is ready to fill out any form where you need to look smart.
```crystal
# 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"
# Actions that hackers take
Faker::Hacker.verb #=> "bypass"
# Verbs that end in -ing
Faker::Hacker.ingverb #=> "synthesizing"
```
2016-01-17 23:31:08 +03:00
### Faker::Team
```crystal
# Random Team Creature
Faker::Team.creature #=> "gooses"
# Random Team Name created from random US State (Faker::Address.state) prepended to a random Team Creature
Faker::Team.name #=> "Oregon vixens"
# Random Team State
Faker::Team.state #=> "Oregon"
```
2016-01-05 17:49:33 +03:00
## Contributing
1. Fork it ( https://github.com/askn/faker/fork )
2. Create your feature branch (git checkout -b my-new-feature)
2016-01-06 15:21:35 +03:00
3. Commit your changes (git commit -am "Add some feature")
2016-01-05 17:49:33 +03:00
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [askn](https://github.com/askn) Aşkın Gedik - creator, maintainer