faker 1.6.3 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +13 -0
- data/README.md +185 -23
- data/lib/faker.rb +20 -0
- data/lib/faker/app.rb +1 -1
- data/lib/faker/beer.rb +1 -1
- data/lib/faker/chuck_norris.rb +16 -0
- data/lib/faker/code.rb +59 -0
- data/lib/faker/company.rb +19 -0
- data/lib/faker/crypto.rb +19 -0
- data/lib/faker/date.rb +30 -2
- data/lib/faker/educator.rb +23 -0
- data/lib/faker/file.rb +23 -0
- data/lib/faker/internet.rb +24 -15
- data/lib/faker/lorem.rb +21 -7
- data/lib/faker/music.rb +21 -0
- data/lib/faker/name.rb +7 -0
- data/lib/faker/placeholdit.rb +3 -3
- data/lib/faker/space.rb +54 -0
- data/lib/faker/time.rb +7 -18
- data/lib/faker/vehicle.rb +37 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker/yoda.rb +10 -0
- data/lib/locales/de.yml +26 -8
- data/lib/locales/en-GB.yml +1 -1
- data/lib/locales/en-PAK.yml +17 -0
- data/lib/locales/en.yml +195 -4
- data/lib/locales/es-MX.yml +82 -0
- data/lib/locales/es.yml +4 -0
- data/lib/locales/fr.yml +7 -4
- data/lib/locales/pt-BR.yml +51 -23
- metadata +13 -103
- data/test/test_array_sample_method_compat.rb +0 -56
- data/test/test_avatar.rb +0 -43
- data/test/test_ca_cat_locale.rb +0 -35
- data/test/test_ca_locale.rb +0 -22
- data/test/test_da_dk_locale.rb +0 -32
- data/test/test_en_au_locale.rb +0 -24
- data/test/test_en_au_ocker_locale.rb +0 -25
- data/test/test_en_ca_locale.rb +0 -18
- data/test/test_en_locale.rb +0 -35
- data/test/test_en_nz_locale.rb +0 -33
- data/test/test_en_ug_locale.rb +0 -23
- data/test/test_en_us_locale.rb +0 -89
- data/test/test_es_locale.rb +0 -34
- data/test/test_faker.rb +0 -29
- data/test/test_faker_app.rb +0 -12
- data/test/test_faker_beer.rb +0 -41
- data/test/test_faker_bitcoin.rb +0 -14
- data/test/test_faker_book.rb +0 -24
- data/test/test_faker_boolean.rb +0 -23
- data/test/test_faker_business.rb +0 -34
- data/test/test_faker_cat.rb +0 -20
- data/test/test_faker_city.rb +0 -52
- data/test/test_faker_code.rb +0 -35
- data/test/test_faker_color.rb +0 -50
- data/test/test_faker_commerce.rb +0 -84
- data/test/test_faker_company.rb +0 -34
- data/test/test_faker_date.rb +0 -89
- data/test/test_faker_hacker_talk.rb +0 -37
- data/test/test_faker_hipster.rb +0 -78
- data/test/test_faker_internet.rb +0 -190
- data/test/test_faker_lorem.rb +0 -87
- data/test/test_faker_name.rb +0 -20
- data/test/test_faker_number.rb +0 -107
- data/test/test_faker_shakespeare.rb +0 -53
- data/test/test_faker_slack_emoji.rb +0 -45
- data/test/test_faker_star_wars.rb +0 -74
- data/test/test_faker_street.rb +0 -58
- data/test/test_faker_superhero.rb +0 -16
- data/test/test_faker_team.rb +0 -25
- data/test/test_faker_time.rb +0 -93
- data/test/test_faker_university.rb +0 -20
- data/test/test_fi_locale.rb +0 -33
- data/test/test_flexible.rb +0 -62
- data/test/test_helper.rb +0 -12
- data/test/test_locale.rb +0 -47
- data/test/test_pl_locale.rb +0 -24
- data/test/test_placeholdit.rb +0 -92
- data/test/test_pt_locale.rb +0 -27
- data/test/test_sv_locale.rb +0 -28
- data/test/test_uk_locale.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2ee70ea2d6aaca6b29368c96662c4719cb8ae1
|
4
|
+
data.tar.gz: c5b4ed33812b75c33da0d94e204cd42aa2d4b347
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af9b9aec025fb8991e1b0af57105dee42ad6e83e6771b99dee333613235bb5b48cc17428117fe45f968636708bf1f6d3cdf0cd8e9b7b3cb885533da79a3b89b
|
7
|
+
data.tar.gz: d300551f4b629cdf6894710f681af489f871fe2835937a312b74fb1c0d37263a42e44bc8e7eebb63c8e0dd06e059c7b822ef6a712689f39ddd948f220e01cb72
|
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 1.6.4 2016-07-06
|
2
|
+
* Removed support for Ruby 1.9.3
|
3
|
+
* Added Faker::ChuckNorris, Faker::Crypto, Faker::Educator, Faker::File, Faker::Music, Faker::Space, Faker::Vehicle, and Faker::Yoda
|
4
|
+
* Fixed bug with credit card types
|
5
|
+
* DST fixes in Faker::Time
|
6
|
+
* Added Faker::Name.name_with_middle
|
7
|
+
* Added Faker::Code.imei
|
8
|
+
* Added Faker::Code.asin
|
9
|
+
* Added Faker::Lorem.question and Faker::Lorem.questions
|
10
|
+
* Added Faker::Internet.private_ip_v4_address
|
11
|
+
* Added Faker::Company.australian_business_number
|
12
|
+
* Other miscellaneous fixes and locale updates
|
13
|
+
|
1
14
|
== 1.6.3 2016-02-23
|
2
15
|
* Fix for UTF problem in Ruby 1.9.3
|
3
16
|
* Fix for Faker::StarWars.character
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
Faker
|
2
|
-
|
1
|
+
# Faker [](https://travis-ci.org/stympy/faker) [](https://badge.fury.io/rb/faker)
|
2
|
+
|
3
|
+
|
3
4
|
This gem is a port of Perl's Data::Faker library that generates fake data.
|
4
5
|
|
5
6
|
It comes in very handy for taking screenshots (taking screenshots for my
|
@@ -15,6 +16,49 @@ development.
|
|
15
16
|
Please refer the README of your version for the available methods.
|
16
17
|
List of all versions is [available here](https://github.com/stympy/faker/releases).
|
17
18
|
|
19
|
+
Contents
|
20
|
+
--------
|
21
|
+
|
22
|
+
- [Installing](#installing)
|
23
|
+
- [Usage](#usage)
|
24
|
+
- [Faker::Address](#fakeraddress)
|
25
|
+
- [Faker::Bitcoin](#fakerbitcoin)
|
26
|
+
- [Faker::Business](#fakerbusiness)
|
27
|
+
- [Faker::Code](#fakercode)
|
28
|
+
- [Faker::Color](#fakercolor)
|
29
|
+
- [Faker::Commerce](#fakercommerce)
|
30
|
+
- [Faker::Company](#fakercompany)
|
31
|
+
- [Faker::Date](#fakerdate)
|
32
|
+
- [Faker::Internet](#fakerinternet)
|
33
|
+
- [Faker::File](#fakerfile)
|
34
|
+
- [Faker::Lorem](#fakerlorem)
|
35
|
+
- [Faker::Name](#fakername)
|
36
|
+
- [Faker::Number](#fakernumber)
|
37
|
+
- [Faker::Boolean](#fakerboolean)
|
38
|
+
- [Faker::PhoneNumber](#fakerphonenumber)
|
39
|
+
- [Faker::Time](#fakertime)
|
40
|
+
- [Faker::Hacker](#fakerhacker)
|
41
|
+
- [Faker::Crypto](#fakercrypto)
|
42
|
+
- [Faker::App](#fakerapp)
|
43
|
+
- [Faker::SlackEmoji](#fakerslackemoji)
|
44
|
+
- [Faker::Team](#fakerteam)
|
45
|
+
- [Faker::Book](#fakerbook)
|
46
|
+
- [Faker::University](#fakeruniversity)
|
47
|
+
- [Faker::Placeholdit](#fakerplaceholdit)
|
48
|
+
- [Faker::Hipster](#fakerhipster)
|
49
|
+
- [Faker::Superhero](#fakersuperhero)
|
50
|
+
- [Faker::StarWars](#fakerstarwars)
|
51
|
+
- [Faker::Beer](#fakerbeer)
|
52
|
+
- [Faker::ChuckNorris](#fakerchucknorris)
|
53
|
+
- [Faker::Educator](#fakereducator)
|
54
|
+
- [Faker::Space](#fakerspace)
|
55
|
+
- [Faker::Music](#fakermusic)
|
56
|
+
- [Faker::Vehicle](#fakervehicle)
|
57
|
+
- [Customization](#customization)
|
58
|
+
- [Contributing](#contributing)
|
59
|
+
- [Contact](#contact)
|
60
|
+
- [License](#license)
|
61
|
+
|
18
62
|
Installing
|
19
63
|
----------
|
20
64
|
```bash
|
@@ -29,7 +73,7 @@ Faker::Name.name #=> "Christophe Bartell"
|
|
29
73
|
Faker::Internet.email #=> "kirsten.greenholt@corkeryfisher.info"
|
30
74
|
```
|
31
75
|
|
32
|
-
###Faker::Address
|
76
|
+
### Faker::Address
|
33
77
|
-----------------
|
34
78
|
|
35
79
|
```ruby
|
@@ -78,7 +122,7 @@ Faker::Address.longitude #=> "-156.65548382095133"
|
|
78
122
|
```ruby
|
79
123
|
|
80
124
|
Faker::Bitcoin.address #=> "1HUoGjmgChmnxxYhz87YytV4gVjfPaExmh"
|
81
|
-
Faker::Bitcoin.testnet_address #=> "
|
125
|
+
Faker::Bitcoin.testnet_address #=> "msHGunDvoEwmVFXvd2Bub1SNw5RP1YHJaf"
|
82
126
|
|
83
127
|
```
|
84
128
|
|
@@ -104,6 +148,10 @@ Faker::Code.isbn #=> "759021701-8"
|
|
104
148
|
|
105
149
|
Faker::Code.ean #=> "4600051000057"
|
106
150
|
|
151
|
+
Faker::Code.imei #= "546327785982623"
|
152
|
+
|
153
|
+
Faker::Code.asin #=> "B00000IGGJ"
|
154
|
+
|
107
155
|
```
|
108
156
|
|
109
157
|
###Faker::Color
|
@@ -167,6 +215,9 @@ Faker::Company.logo #=> "https://pigment.github.com/fake-logos/logos/medium/colo
|
|
167
215
|
|
168
216
|
Faker::Company.swedish_organisation_number #=> "7718797652"
|
169
217
|
|
218
|
+
# Generate an Australian Business Number
|
219
|
+
Faker::Company.australian_business_number #=> "81137773602"
|
220
|
+
|
170
221
|
# Get a random profession
|
171
222
|
Faker::Company.profession #=> "firefighter"
|
172
223
|
|
@@ -179,7 +230,7 @@ Faker::Company.profession #=> "firefighter"
|
|
179
230
|
# Random date between dates
|
180
231
|
Faker::Date.between(2.days.ago, Date.today) #=> "Wed, 24 Sep 2014"
|
181
232
|
|
182
|
-
#
|
233
|
+
# Random date between dates except for certain date
|
183
234
|
Faker::Date.between_except(1.year.ago, 1.year.from_now, Date.today) #=> "Wed, 24 Sep 2014"
|
184
235
|
|
185
236
|
# Random date in the future (up to maximum of N days)
|
@@ -236,8 +287,10 @@ Faker::Internet.domain_suffix #=> "info"
|
|
236
287
|
|
237
288
|
Faker::Internet.ip_v4_address #=> "24.29.18.175"
|
238
289
|
|
239
|
-
#
|
240
|
-
|
290
|
+
# Private IP range according to RFC 1918 and 127.0.0.0/8 and 169.254.0.0/16.
|
291
|
+
Faker::Internet.private_ip_v4_address #=> "10.0.0.1"
|
292
|
+
|
293
|
+
# Guaranteed not to be in the ip range from the private_ip_v4_address method.
|
241
294
|
Faker::Internet.public_ip_v4_address #=> "24.29.18.175"
|
242
295
|
|
243
296
|
Faker::Internet.ip_v4_cidr #=> "24.29.18.175/21"
|
@@ -263,6 +316,18 @@ Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
|
|
263
316
|
|
264
317
|
```
|
265
318
|
|
319
|
+
###Faker::File
|
320
|
+
---------------
|
321
|
+
```ruby
|
322
|
+
Faker::File.extension #=> "mp3"
|
323
|
+
Faker::File.mime_type #=> "application/pdf"
|
324
|
+
# Optional arguments: dir, name, extension, directory_separator
|
325
|
+
Faker::File.file_name('path/to') #=> "path/to/something_random.jpg"
|
326
|
+
Faker::File.file_name('foo/bar', 'baz') #=> "foo/bar/baz.zip"
|
327
|
+
Faker::File.file_name('foo/bar', 'baz', 'doc') #=> "foo/bar/baz.doc"
|
328
|
+
Faker::File.file_name('foo/bar', 'baz', 'mp3', '\') #=> "foo\bar\baz.mp3"
|
329
|
+
```
|
330
|
+
|
266
331
|
###Faker::Lorem
|
267
332
|
---------------
|
268
333
|
|
@@ -270,7 +335,7 @@ Faker::Internet.slug('foo bar', '-') #=> "foo-bar"
|
|
270
335
|
|
271
336
|
Faker::Lorem.word #=> "repellendus"
|
272
337
|
|
273
|
-
# Optional arguments: num=3, supplemental=false
|
338
|
+
# Optional arguments: num=3, supplemental=false (words from a supplementary list of Lorem-like words)
|
274
339
|
Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
|
275
340
|
Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
|
276
341
|
Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]
|
@@ -310,17 +375,19 @@ Faker::Lorem.paragraphs(1, true) #=> ["Depulso animi cunctatio amicitia adficio.
|
|
310
375
|
|
311
376
|
```ruby
|
312
377
|
|
313
|
-
Faker::Name.name
|
378
|
+
Faker::Name.name #=> "Tyshawn Johns Sr."
|
379
|
+
|
380
|
+
Faker::Name.name_with_middle #=> "Aditya Elton Douglas"
|
314
381
|
|
315
|
-
Faker::Name.first_name
|
382
|
+
Faker::Name.first_name #=> "Kaci"
|
316
383
|
|
317
|
-
Faker::Name.last_name
|
384
|
+
Faker::Name.last_name #=> "Ernser"
|
318
385
|
|
319
|
-
Faker::Name.prefix
|
386
|
+
Faker::Name.prefix #=> "Mr."
|
320
387
|
|
321
|
-
Faker::Name.suffix
|
388
|
+
Faker::Name.suffix #=> "IV"
|
322
389
|
|
323
|
-
Faker::Name.title
|
390
|
+
Faker::Name.title #=> "Legacy Creative Director"
|
324
391
|
|
325
392
|
```
|
326
393
|
|
@@ -430,15 +497,16 @@ Faker::PhoneNumber.extension #=> "3764"
|
|
430
497
|
Faker::Time.between(DateTime.now - 1, DateTime.now) #=> "2014-09-18 12:30:59 -0700"
|
431
498
|
|
432
499
|
# Random date between dates (within specified part of the day)
|
433
|
-
# You can install the
|
434
|
-
|
435
|
-
|
436
|
-
Faker::Time.between(2.days.ago,
|
437
|
-
Faker::Time.between(2.days.ago,
|
438
|
-
Faker::Time.between(2.days.ago,
|
439
|
-
Faker::Time.between(2.days.ago,
|
440
|
-
Faker::Time.between(2.days.ago,
|
441
|
-
Faker::Time.between(2.days.ago,
|
500
|
+
# You can install the as-duration gem to facilitate time manipulation like 45.minutes + 2.hours
|
501
|
+
# (not needed if you already have activesupport, which is included with Rails)
|
502
|
+
require 'as-duration'
|
503
|
+
Faker::Time.between(2.days.ago, Date.today, :all) #=> "2014-09-19 07:03:30 -0700"
|
504
|
+
Faker::Time.between(2.days.ago, Date.today, :day) #=> "2014-09-18 16:28:13 -0700"
|
505
|
+
Faker::Time.between(2.days.ago, Date.today, :night) #=> "2014-09-20 19:39:38 -0700"
|
506
|
+
Faker::Time.between(2.days.ago, Date.today, :morning) #=> "2014-09-19 08:07:52 -0700"
|
507
|
+
Faker::Time.between(2.days.ago, Date.today, :afternoon) #=> "2014-09-18 12:10:34 -0700"
|
508
|
+
Faker::Time.between(2.days.ago, Date.today, :evening) #=> "2014-09-19 20:21:03 -0700"
|
509
|
+
Faker::Time.between(2.days.ago, Date.today, :midnight) #=> "2014-09-20 00:40:14 -0700"
|
442
510
|
|
443
511
|
# Random time in the future (up to maximum of N days)
|
444
512
|
Faker::Time.forward(23, :morning) # => "2014-09-26 06:54:47 -0700"
|
@@ -472,6 +540,19 @@ Faker::Hacker.verb #=> "bypass"
|
|
472
540
|
Faker::Hacker.ingverb #=> "synthesizing"
|
473
541
|
```
|
474
542
|
|
543
|
+
###Faker::Crypto
|
544
|
+
---------------------
|
545
|
+
|
546
|
+
```ruby
|
547
|
+
|
548
|
+
Faker::Crypto.md5 #=> "6b5ed240042e8a65c55ddb826c3408e6"
|
549
|
+
|
550
|
+
Faker::Crypto.sha1 #=> "4e99e31c51eef8b2d290e709f757f92e558a503f"
|
551
|
+
|
552
|
+
Faker::Crypto.sha256 #=> "51e4dbb424cd9db1ec5fb989514f2a35652ececef33f21c8dd1fd61bb8e3929d"
|
553
|
+
|
554
|
+
```
|
555
|
+
|
475
556
|
###Faker::App
|
476
557
|
-----------------
|
477
558
|
|
@@ -676,7 +757,88 @@ Faker::Beer.alcohol #=> "6.3%"
|
|
676
757
|
Faker::Beer.blg #=> "18.5°Blg"
|
677
758
|
```
|
678
759
|
|
760
|
+
###Faker::ChuckNorris
|
761
|
+
----------------
|
762
|
+
|
763
|
+
```ruby
|
764
|
+
Faker::ChuckNorris.fact #=> "Chuck Norris can solve the Towers of Hanoi in one move."
|
765
|
+
```
|
766
|
+
|
767
|
+
###Faker::Educator
|
768
|
+
-------------------
|
769
|
+
|
770
|
+
```ruby
|
771
|
+
Faker::Educator.university #=> "Mallowtown Technical College"
|
772
|
+
|
773
|
+
Faker::Educator.secondary_school #=> "Iceborough Secodary College"
|
774
|
+
|
775
|
+
Faker::Educator.course #=> "Associate Degree in Criminology"
|
776
|
+
|
777
|
+
Faker::Educator.campus #=> "Vertapple Campus"
|
778
|
+
```
|
779
|
+
|
780
|
+
###Faker::Space
|
781
|
+
----------------
|
782
|
+
|
783
|
+
```ruby
|
784
|
+
# Random planet from our Solar System
|
785
|
+
Faker::Space.planet #=> "Venus"
|
786
|
+
|
787
|
+
# Random moon from our Solar System
|
788
|
+
Faker::Space.moon #=> "Europa"
|
789
|
+
|
790
|
+
# Random galaxy
|
791
|
+
Faker::Space.galaxy #=> "Andromeda"
|
792
|
+
|
793
|
+
# Random nebula name
|
794
|
+
Faker::Space.nebula #=> "Triffid Nebula"
|
795
|
+
|
796
|
+
# Random star cluster
|
797
|
+
Faker::Space.star_cluster #=> "Messier 70"
|
798
|
+
|
799
|
+
# Random constellation
|
800
|
+
Faker::Space.constellation #=> "Orion"
|
801
|
+
|
802
|
+
# Random star
|
803
|
+
Faker::Space.star #=> "Proxima Centauri"
|
804
|
+
|
805
|
+
# Random national space agency
|
806
|
+
Faker::Space.agency #=> "Japan Aerospace Exploration Agency"
|
807
|
+
|
808
|
+
# Random space agency abbreviation
|
809
|
+
Faker::Space.agency_abv #=> "NASA"
|
810
|
+
|
811
|
+
# Random spacecraft name (limited to NASA)
|
812
|
+
Faker::Space.nasa_space_craft #=> "Endeavour"
|
813
|
+
|
814
|
+
# Random private space company title
|
815
|
+
Faker::Space.company #=> "SpaceX"
|
816
|
+
|
817
|
+
# Random unit of stellar distance with number
|
818
|
+
Faker::Space.distance_measurement #=> "15 parsecs"
|
819
|
+
```
|
820
|
+
|
679
821
|
|
822
|
+
###Faker::Music
|
823
|
+
-------------------
|
824
|
+
|
825
|
+
```ruby
|
826
|
+
Faker::Music.key #=> "C"
|
827
|
+
|
828
|
+
Faker::Music.instrument #=> "Ukelele"
|
829
|
+
```
|
830
|
+
|
831
|
+
###Faker::Vehicle
|
832
|
+
------------------
|
833
|
+
|
834
|
+
```ruby
|
835
|
+
|
836
|
+
# Generate vehicle identification number
|
837
|
+
Faker::Vehicle.vin #=> "LLDWXZLG77VK2LUUF"
|
838
|
+
|
839
|
+
# Random vehicle manufacturer
|
840
|
+
Faker::Vehicle.manufacture #=> "JAGUAR CARS LTD"
|
841
|
+
```
|
680
842
|
|
681
843
|
Customization
|
682
844
|
------------
|
data/lib/faker.rb
CHANGED
@@ -97,6 +97,18 @@ module Faker
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# Helper for the common approach of grabbing a translation
|
101
|
+
# with an array of values and returning all of them.
|
102
|
+
def fetch_all(key)
|
103
|
+
fetched = translate("faker.#{key}")
|
104
|
+
fetched = fetched.last if fetched.size <= 1
|
105
|
+
if !fetched.respond_to?(:sample) && fetched.match(/^\//) and fetched.match(/\/$/) # A regex
|
106
|
+
regexify(fetched)
|
107
|
+
else
|
108
|
+
fetched
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
100
112
|
# Load formatted strings from the locale, "parsing" them
|
101
113
|
# into method calls that can be used to generate a
|
102
114
|
# formatted translation: e.g., "#{first_name} #{last_name}".
|
@@ -182,6 +194,7 @@ require 'faker/company'
|
|
182
194
|
require 'faker/university'
|
183
195
|
require 'faker/finance'
|
184
196
|
require 'faker/internet'
|
197
|
+
require 'faker/file'
|
185
198
|
require 'faker/lorem'
|
186
199
|
require 'faker/name'
|
187
200
|
require 'faker/team'
|
@@ -207,6 +220,13 @@ require 'faker/superhero'
|
|
207
220
|
require 'faker/beer'
|
208
221
|
require 'faker/boolean'
|
209
222
|
require 'faker/star_wars'
|
223
|
+
require 'faker/chuck_norris'
|
224
|
+
require 'faker/crypto'
|
225
|
+
require 'faker/educator'
|
226
|
+
require 'faker/space'
|
227
|
+
require 'faker/yoda'
|
228
|
+
require 'faker/music'
|
229
|
+
require 'faker/vehicle'
|
210
230
|
|
211
231
|
require 'extensions/array'
|
212
232
|
require 'extensions/symbol'
|
data/lib/faker/app.rb
CHANGED
data/lib/faker/beer.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Faker
|
2
|
+
class ChuckNorris < Base
|
3
|
+
flexible :name
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def name
|
8
|
+
parse('chuck_norris')
|
9
|
+
end
|
10
|
+
|
11
|
+
# from: https://github.com/jenkinsci/chucknorris-plugin/blob/master/src/main/java/hudson/plugins/chucknorris/FactGenerator.java
|
12
|
+
def fact; fetch('chuck_norris.fact'); end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/faker/code.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Faker
|
2
2
|
class Code < Base
|
3
|
+
flexible :code
|
3
4
|
class << self
|
4
5
|
|
5
6
|
# Generates a 10 digit NPI (National Provider Identifier
|
@@ -37,8 +38,66 @@ module Faker
|
|
37
38
|
"#{prefix}#{values}#{check_alpha}"
|
38
39
|
end
|
39
40
|
|
41
|
+
# Generate GSM modem, device or mobile phone 15 digit IMEI number.
|
42
|
+
def imei
|
43
|
+
generate_imei
|
44
|
+
end
|
45
|
+
|
46
|
+
# Retrieves a real Amazon ASIN code list taken from
|
47
|
+
# https://archive.org/details/asin_listing
|
48
|
+
def asin
|
49
|
+
fetch('code.asin')
|
50
|
+
end
|
51
|
+
|
40
52
|
private
|
41
53
|
|
54
|
+
# Reporting body identifier
|
55
|
+
RBI = %w(01 10 30 33 35 44 45 49 50 51 52 53 54 86 91 98 99).freeze
|
56
|
+
|
57
|
+
def generate_imei
|
58
|
+
pos = 0
|
59
|
+
str = Array.new(15, 0)
|
60
|
+
sum = 0
|
61
|
+
t = 0
|
62
|
+
len_offset = 0
|
63
|
+
len = 15
|
64
|
+
|
65
|
+
# Fill in the first two values of the string based with the specified prefix.
|
66
|
+
# Reporting Body Identifier list: http://en.wikipedia.org/wiki/Reporting_Body_Identifier
|
67
|
+
arr = RBI.sample
|
68
|
+
str[0] = arr[0].to_i
|
69
|
+
str[1] = arr[1].to_i
|
70
|
+
pos = 2
|
71
|
+
|
72
|
+
# Fill all the remaining numbers except for the last one with random values.
|
73
|
+
while pos < (len - 1)
|
74
|
+
str[pos] = rand(0..9)
|
75
|
+
pos += 1
|
76
|
+
end
|
77
|
+
|
78
|
+
# Calculate the Luhn checksum of the values thus far
|
79
|
+
len_offset = (len + 1) % 2
|
80
|
+
for pos in (0..(len - 1))
|
81
|
+
if (pos + len_offset) % 2 != 0
|
82
|
+
t = str[pos] * 2
|
83
|
+
|
84
|
+
if t > 9
|
85
|
+
t -= 9
|
86
|
+
end
|
87
|
+
|
88
|
+
sum += t
|
89
|
+
else
|
90
|
+
sum += str[pos]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Choose the last digit so that it causes the entire string to pass the checksum.
|
95
|
+
str[len - 1] = (10 - (sum % 10)) % 10
|
96
|
+
|
97
|
+
# Output the IMEI value.
|
98
|
+
str.join('')
|
99
|
+
end
|
100
|
+
|
42
101
|
def generate_base10_isbn
|
43
102
|
values = regexify(/\d{9}/)
|
44
103
|
remainder = sum(values) { |value, index| (index + 1) * value.to_i } % 11
|