faker 3.1.1 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +64 -1
- data/README.md +15 -6
- data/lib/faker/default/chile_rut.rb +23 -17
- data/lib/faker/default/code.rb +60 -18
- data/lib/faker/default/company.rb +44 -5
- data/lib/faker/default/date.rb +61 -5
- data/lib/faker/default/driving_licence.rb +19 -8
- data/lib/faker/default/food.rb +13 -0
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +17 -3
- data/lib/faker/default/internet.rb +62 -31
- data/lib/faker/default/lorem.rb +5 -2
- data/lib/faker/default/marketing.rb +1 -1
- data/lib/faker/default/omniauth.rb +1 -1
- data/lib/faker/default/release notes.md +59 -0
- data/lib/faker/default/twitter.rb +1 -1
- data/lib/faker/default/types.rb +3 -2
- data/lib/faker/default/vehicle.rb +19 -8
- data/lib/faker/games/dnd.rb +49 -7
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/movies/avatar.rb +49 -0
- data/lib/faker/quotes/quote.rb +13 -0
- data/lib/faker/sports/chess.rb +90 -0
- data/lib/faker/travel/airport.rb +2 -6
- data/lib/faker/travel/train_station.rb +54 -0
- data/lib/faker/tv_shows/archer.rb +51 -0
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +13 -6
- data/lib/helpers/positional_generator.rb +480 -0
- data/lib/locales/README.md +18 -2
- data/lib/locales/ar.yml +1 -0
- data/lib/locales/bg.yml +1 -1
- data/lib/locales/da-DK.yml +1 -0
- data/lib/locales/de-AT.yml +1 -1
- data/lib/locales/de-CH.yml +4336 -11
- data/lib/locales/de.yml +1 -0
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/avatar.yml +31 -0
- data/lib/locales/en/chess.yml +103 -0
- data/lib/locales/en/company.yml +1 -0
- data/lib/locales/en/dnd.yml +186 -1
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/food.yml +12 -0
- data/lib/locales/en/internet.yml +3 -0
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/mitch_hedberg.yml +46 -0
- data/lib/locales/en/opera.yml +1 -1
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/train_station.yml +280 -0
- data/lib/locales/en-AU.yml +1 -0
- data/lib/locales/en-CA.yml +1 -0
- data/lib/locales/en-GB.yml +2 -0
- data/lib/locales/en-MS.yml +1 -0
- data/lib/locales/en-NG.yml +1 -0
- data/lib/locales/en-NZ.yml +1 -0
- data/lib/locales/en-PAK.yml +1 -0
- data/lib/locales/en-SG.yml +1 -0
- data/lib/locales/en-UG.yml +1 -0
- data/lib/locales/en-US.yml +1 -0
- data/lib/locales/en-ZA.yml +1 -0
- data/lib/locales/en-au-ocker.yml +2 -0
- data/lib/locales/es-AR.yml +1 -0
- data/lib/locales/es-MX.yml +1 -0
- data/lib/locales/es.yml +1 -0
- data/lib/locales/fi-FI.yml +1 -0
- data/lib/locales/fr/name.yml +2 -1
- data/lib/locales/fr-CA.yml +1 -0
- data/lib/locales/fr-CH.yml +1 -0
- data/lib/locales/hy.yml +1 -0
- data/lib/locales/it.yml +1 -0
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ko.yml +1 -0
- data/lib/locales/mi-NZ.yml +2 -0
- data/lib/locales/nb-NO.yml +1 -0
- data/lib/locales/nl.yml +1 -0
- data/lib/locales/pl.yml +1 -0
- data/lib/locales/pt-BR.yml +1 -0
- data/lib/locales/pt.yml +1 -0
- data/lib/locales/ru.yml +1 -0
- data/lib/locales/sk.yml +1 -0
- data/lib/locales/sv.yml +1 -0
- data/lib/locales/tr.yml +1 -0
- data/lib/locales/uk.yml +3 -0
- data/lib/locales/vi.yml +1 -0
- data/lib/locales/zh-CN.yml +1 -0
- data/lib/locales/zh-TW.yml +1 -0
- metadata +18 -144
- data/lib/faker/default/fillmurray.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d53bbdb52aa714d065ea68bcddd91aad8ca346b3e00ce828e5a95a7f32fb9cc
|
4
|
+
data.tar.gz: 05fa5f30f28a2b00825253650e23ea433f26457c43bf822117628f7494b660a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 253c37f13596516e56f85bfbd7e509ececcfa1dd77d9ceec3cd92d127fed1249a4197dbd1ccbb0699ee9895870eaa30d61f59288bc0d954fa9805f3526346539
|
7
|
+
data.tar.gz: 2e1f76f104cd9b0a3852366c26847692620129e795bb321ada197829b2d981a0a0e21f723597c741971a78a540597a84d0c86a2b9bda5fdf059e05f1f2b57c7f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,68 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v3.2.0](https://github.com/faker-ruby/faker/tree/v3.2.0) (2023-04-14)
|
4
|
+
|
5
|
+
Happy Spring with a new Faker release! 🌼
|
6
|
+
|
7
|
+
This version changes `Faker::Internet.email`, `Faker::Internet.domain_name`, `Faker::Internet.safe_email`, and `Faker::Internet.free_email` default behavior.
|
8
|
+
|
9
|
+
These generators email are now RFC 2606 compliant. They generate safe values by default using the Reserved Top Level DNS Names: `example` and `test`. To maintain backwards compatibility and give users the option to use non-safe domains at their own risk, custom domains are allowed.
|
10
|
+
|
11
|
+
`Faker::Internet.safe_email`, and `Faker::Internet.free_email` have been deprecated. Users have until October 2023 to make the necessary changes.
|
12
|
+
|
13
|
+
[More details and updated docs can be found here](https://github.com/faker-ruby/faker/blob/main/doc/default/internet.md#about-faker-ruby-transition-to-be-rfc-2606-compliant).
|
14
|
+
|
15
|
+
Other changes included in this version:
|
16
|
+
|
17
|
+
## Features
|
18
|
+
* Generate safe `email` and `domain_name` by default (RFC 2606) by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2733
|
19
|
+
* Add avatar movie by @lexisvar in https://github.com/faker-ruby/faker/pull/2699
|
20
|
+
* add chess sport by @lexisvar in https://github.com/faker-ruby/faker/pull/2701
|
21
|
+
* Remove FillMurray service by @ferblape in https://github.com/faker-ruby/faker/pull/2702
|
22
|
+
* Add Allergens to Food by @AaronRustad in https://github.com/faker-ruby/faker/pull/2706
|
23
|
+
* Update sport docs by @clementf in https://github.com/faker-ruby/faker/pull/2716
|
24
|
+
* Add country code +44 to en-gb locale by @jremes-foss in https://github.com/faker-ruby/faker/pull/2731
|
25
|
+
* Add names to DnD generator by @dollerbill in https://github.com/faker-ruby/faker/pull/2735
|
26
|
+
* add digits to password by @wyattroyc in https://github.com/faker-ruby/faker/pull/2705
|
27
|
+
* performance: remove unnecessary i18n locale reload by @codez in https://github.com/faker-ruby/faker/pull/2723
|
28
|
+
* Add Faker::Company.department generator by @acuppy in https://github.com/faker-ruby/faker/pull/2737
|
29
|
+
* Mitch Hedberg quotes by @MosDeef in https://github.com/faker-ruby/faker/pull/2721
|
30
|
+
|
31
|
+
## Bug fixes
|
32
|
+
* Fix explanation what Marketing.buzzwords does by @danieldiekmeier in https://github.com/faker-ruby/faker/pull/2700
|
33
|
+
* fix: Typo in Faker::Travel::Airport docs by @evanlouden in https://github.com/faker-ruby/faker/pull/2712
|
34
|
+
* Fix full changelog link for 3.1.1 by @rnestler in https://github.com/faker-ruby/faker/pull/2714
|
35
|
+
* Stop publishing to RubyGem by @VladVadlja in https://github.com/faker-ruby/faker/pull/2711
|
36
|
+
* Add default_country_code in locale by @ashwin-elangovan in https://github.com/faker-ruby/faker/pull/2732
|
37
|
+
* Fix formatting in readme.md by @leon-vogt in https://github.com/faker-ruby/faker/pull/2722
|
38
|
+
|
39
|
+
## Update local dependencies
|
40
|
+
* Fix rubocop updates by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2708
|
41
|
+
* Update rubocop-minitest requirement from = 0.29.0 to = 0.30.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2743
|
42
|
+
* Update minitest requirement from = 5.17.0 to = 5.18.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2727
|
43
|
+
* Update rubocop requirement from = 1.48.1 to = 1.50.1 by @dependabot in https://github.com/faker-ruby/faker/pull/2747
|
44
|
+
* Add Faker::Company.department generator by @acuppy in https://github.com/faker-ruby/faker/pull/2737
|
45
|
+
* Update Pull Request template and guides by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2749
|
46
|
+
|
47
|
+
## New Contributors
|
48
|
+
* @lexisvar made their first contribution in https://github.com/faker-ruby/faker/pull/2699
|
49
|
+
* @danieldiekmeier made their first contribution in https://github.com/faker-ruby/faker/pull/2700
|
50
|
+
* @AaronRustad made their first contribution in https://github.com/faker-ruby/faker/pull/2706
|
51
|
+
* @evanlouden made their first contribution in https://github.com/faker-ruby/faker/pull/2712
|
52
|
+
* @rnestler made their first contribution in https://github.com/faker-ruby/faker/pull/2714
|
53
|
+
* @VladVadlja made their first contribution in https://github.com/faker-ruby/faker/pull/2711
|
54
|
+
* @clementf made their first contribution in https://github.com/faker-ruby/faker/pull/2716
|
55
|
+
* @leon-vogt made their first contribution in https://github.com/faker-ruby/faker/pull/2722
|
56
|
+
* @ashwin-elangovan made their first contribution in https://github.com/faker-ruby/faker/pull/2732
|
57
|
+
* @wyattroyc made their first contribution in https://github.com/faker-ruby/faker/pull/2705
|
58
|
+
* @codez made their first contribution in https://github.com/faker-ruby/faker/pull/2723
|
59
|
+
* @acuppy made their first contribution in https://github.com/faker-ruby/faker/pull/2737
|
60
|
+
* @MosDeef made their first contribution in https://github.com/faker-ruby/faker/pull/2721
|
61
|
+
|
62
|
+
**Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.1.1...v3.2.0
|
63
|
+
|
64
|
+
------------------------------------------------------------------------------
|
65
|
+
|
3
66
|
## [v3.1.1](https://github.com/faker-ruby/faker/tree/v3.1.1) (2023-02-03)
|
4
67
|
|
5
68
|
Happy Valentine's Day with a new Faker release! 🎉
|
@@ -35,7 +98,7 @@ This version:
|
|
35
98
|
* @petergoldstein made their first contribution in https://github.com/faker-ruby/faker/pull/2673
|
36
99
|
* @dwilsonactual made their first contribution in https://github.com/faker-ruby/faker/pull/2693
|
37
100
|
|
38
|
-
**Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.1.0...
|
101
|
+
**Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.1.0...v3.1.1
|
39
102
|
|
40
103
|
------------------------------------------------------------------------------
|
41
104
|
|
data/README.md
CHANGED
@@ -27,12 +27,16 @@ and it was the original impetus for the creation of this gem).
|
|
27
27
|
## Table of Contents
|
28
28
|
|
29
29
|
- [Faker](#faker)
|
30
|
+
- [Quick links](#quick-links)
|
31
|
+
- [Table of Contents](#table-of-contents)
|
30
32
|
- [Notes](#notes)
|
31
33
|
- [Getting Started](#getting-started)
|
32
34
|
- [Usage](#usage)
|
35
|
+
- [A note about the Generators versions](#a-note-about-the-generators-versions)
|
33
36
|
- [Ensuring unique values](#ensuring-unique-values)
|
34
37
|
- [Deterministic Random](#deterministic-random)
|
35
38
|
- [Customization](#customization)
|
39
|
+
- [Minitest and Faker \>= 2.22](#minitest-and-faker--222)
|
36
40
|
- [Generators](#generators)
|
37
41
|
- [Contributing](#contributing)
|
38
42
|
- [Versioning](#versioning)
|
@@ -165,9 +169,7 @@ Faker::Config.locale = 'es'
|
|
165
169
|
Faker::Config.locale = :es
|
166
170
|
```
|
167
171
|
|
168
|
-
|
169
|
-
|
170
|
-
To override Faker's locales,
|
172
|
+
To override Faker's locales, and set it on threaded server environments
|
171
173
|
check out the [locales README](lib/locales/README.md).
|
172
174
|
|
173
175
|
### Minitest and Faker >= 2.22
|
@@ -237,7 +239,6 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
237
239
|
- [Faker::Emotion](doc/default/emotion.md)
|
238
240
|
- [Faker::Esport](doc/default/esport.md)
|
239
241
|
- [Faker::File](doc/default/file.md)
|
240
|
-
- [Faker::Fillmurray](doc/default/fillmurray.md)
|
241
242
|
- [Faker::Finance](doc/default/finance.md)
|
242
243
|
- [Faker::Food](doc/default/food.md)
|
243
244
|
- [Faker::FunnyName](doc/default/funny_name.md)
|
@@ -319,10 +320,14 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
319
320
|
</details>
|
320
321
|
|
321
322
|
<details>
|
322
|
-
<summary>
|
323
|
+
<summary>Travel</summary>
|
323
324
|
|
324
|
-
### Travel
|
325
325
|
- [Faker:Travel::Airport](doc/travel/airport.md)
|
326
|
+
- [Faker:Travel::TrainStation](doc/travel/train_station.md)
|
327
|
+
</details>
|
328
|
+
|
329
|
+
<details>
|
330
|
+
<summary>Creature</summary>
|
326
331
|
|
327
332
|
- [Faker::Creature::Animal](doc/creature/animal.md)
|
328
333
|
- [Faker::Creature::Bird](doc/creature/bird.md)
|
@@ -340,6 +345,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
340
345
|
- [Faker::Games::Dota](doc/games/dota.md)
|
341
346
|
- [Faker::Games::ElderScrolls](doc/games/elder_scrolls.md)
|
342
347
|
- [Faker::Games::Fallout](doc/games/fallout.md)
|
348
|
+
- [Faker::Games::FinalFantasyXIV](doc/games/final_fantasy_xiv.md)
|
343
349
|
- [Faker::Games::HalfLife](doc/games/half_life.md)
|
344
350
|
- [Faker::Games::Heroes](doc/games/heroes.md)
|
345
351
|
- [Faker::Games::HeroesOfTheStorm](doc/games/heroes_of_the_storm.md)
|
@@ -377,6 +383,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
377
383
|
<summary>Movies</summary>
|
378
384
|
|
379
385
|
- [Faker::Movie](doc/movies/movie.md)
|
386
|
+
- [Faker::Movies::Avatar](doc/movies/avatar.md)
|
380
387
|
- [Faker::Movies::BackToTheFuture](doc/movies/back_to_the_future.md)
|
381
388
|
- [Faker::Movies::Departed](doc/movies/departed.md)
|
382
389
|
- [Faker::Movies::Ghostbusters](doc/movies/ghostbusters.md)
|
@@ -421,6 +428,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
421
428
|
|
422
429
|
- [Faker::Sports](doc/sports/sports.md)
|
423
430
|
- [Faker::Sports::Basketball](doc/sports/basketball.md)
|
431
|
+
- [Faker::Sports::Chess](doc/sports/chess.md)
|
424
432
|
- [Faker::Sports::Football](doc/sports/football.md)
|
425
433
|
- [Faker::Sports::Mountaineering](doc/sports/mountaineering.md)
|
426
434
|
- [Faker::Sports::Volleyball](doc/sports/volleyball.md)
|
@@ -430,6 +438,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
|
|
430
438
|
<summary>Tv Shows</summary>
|
431
439
|
|
432
440
|
- [Faker::TvShows::AquaTeenHungerForce](doc/tv_shows/aqua_teen_hunger_force.md)
|
441
|
+
- [Faker::TvShows::Archer](doc/tv_shows/archer.md)
|
433
442
|
- [Faker::TvShows::BigBangTheory](doc/tv_shows/big_bang_theory.md)
|
434
443
|
- [Faker::TvShows::BojackHorseman](doc/tv_shows/bojack_horseman.md)
|
435
444
|
- [Faker::TvShows::BreakingBad](doc/tv_shows/breaking_bad.md)
|
@@ -8,18 +8,19 @@ module Faker
|
|
8
8
|
##
|
9
9
|
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits).
|
10
10
|
#
|
11
|
-
# @param min_rut [Integer] Specifies the minimum value of the
|
12
|
-
# @param
|
11
|
+
# @param min_rut [Integer] Specifies the minimum value of the RUT.
|
12
|
+
# @param max_rut [Integer] Specifies the maximum value of the RUT.
|
13
|
+
# @param fixed [Boolean] Determines if the RUT is fixed (returns the min_rut value).
|
13
14
|
# @return [Number]
|
14
15
|
#
|
15
16
|
# @example
|
16
17
|
# Faker::ChileRut.rut #=> 11235813
|
17
|
-
# Faker::ChileRut.rut(min_rut:
|
18
|
-
# Faker::ChileRut.rut(min_rut:
|
18
|
+
# Faker::ChileRut.rut(min_rut: 10_000_000, max_rut: 30_000_000) #=> 21853211
|
19
|
+
# Faker::ChileRut.rut(min_rut: 20_890_156, fixed: true) #=> 20890156
|
19
20
|
#
|
20
|
-
# @faker.version
|
21
|
-
def rut(min_rut: 1, fixed: false)
|
22
|
-
@last_rut = fixed ? min_rut : rand_in_range(min_rut,
|
21
|
+
# @faker.version next
|
22
|
+
def rut(min_rut: 1, max_rut: 99_999_999, fixed: false)
|
23
|
+
@last_rut = fixed ? min_rut : rand_in_range(min_rut, max_rut)
|
23
24
|
end
|
24
25
|
|
25
26
|
##
|
@@ -68,25 +69,30 @@ module Faker
|
|
68
69
|
##
|
69
70
|
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit).
|
70
71
|
#
|
71
|
-
# @param min_rut [Integer] Specifies the minimum value of the
|
72
|
-
# @param
|
72
|
+
# @param min_rut [Integer] Specifies the minimum value of the RUT.
|
73
|
+
# @param max_rut [Integer] Specifies the maximum value of the RUT.
|
74
|
+
# @param fixed [Boolean] Determines if the RUT is fixed (returns the min_rut value).
|
73
75
|
# @return [String]
|
74
76
|
#
|
75
77
|
# @example
|
76
78
|
# Faker::ChileRut.full_rut #=> "30686957-4"
|
77
|
-
# Faker::ChileRut.full_rut(min_rut:
|
78
|
-
# Faker::ChileRut.full_rut(min_rut:
|
79
|
+
# Faker::ChileRut.full_rut(min_rut: 10_000_000, max_rut: 30_000_000) #=> "20686957-4"
|
80
|
+
# Faker::ChileRut.full_rut(min_rut: 30_686_957, fixed: true) #=> "30686957-4"
|
79
81
|
#
|
80
82
|
# @faker.version next
|
81
|
-
def full_rut(min_rut:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
|
86
|
-
end
|
83
|
+
def full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false)
|
84
|
+
this_rut = rut(min_rut: min_rut, max_rut: max_rut, fixed: fixed)
|
85
|
+
this_rut = format_rut(this_rut) if formatted
|
86
|
+
"#{this_rut}-#{dv}"
|
87
87
|
end
|
88
88
|
|
89
89
|
attr_reader :last_rut
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def format_rut(rut)
|
94
|
+
rut.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
|
95
|
+
end
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
data/lib/faker/default/code.rb
CHANGED
@@ -93,11 +93,23 @@ module Faker
|
|
93
93
|
# @faker.version 2.2.0
|
94
94
|
def nric(min_age: 18, max_age: 65)
|
95
95
|
birthyear = Date.birthday(min_age: min_age, max_age: max_age).year
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
96
|
+
|
97
|
+
generate(:string) do |g|
|
98
|
+
g.computed(name: :prefix) do
|
99
|
+
if birthyear < 2000
|
100
|
+
'S'
|
101
|
+
else
|
102
|
+
'T'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
g.computed(name: :yy) do
|
106
|
+
birthyear.to_s[-2..]
|
107
|
+
end
|
108
|
+
g.int(name: :values, length: 5)
|
109
|
+
g.computed(name: :check, deps: %i[prefix yy values]) do |prefix, yy, values|
|
110
|
+
generate_nric_check_alphabet("#{yy}#{values}", prefix)
|
111
|
+
end
|
112
|
+
end
|
101
113
|
end
|
102
114
|
|
103
115
|
##
|
@@ -197,15 +209,29 @@ module Faker
|
|
197
209
|
end
|
198
210
|
|
199
211
|
def generate_base10_isbn
|
200
|
-
|
201
|
-
|
202
|
-
|
212
|
+
generate(:string) do |g|
|
213
|
+
g.int(name: :values, length: 9)
|
214
|
+
g.lit('-')
|
215
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
216
|
+
remainder = sum(values.to_s) { |value, offset| (offset + 1) * value.to_i } % 11
|
217
|
+
if remainder == 10
|
218
|
+
'X'
|
219
|
+
else
|
220
|
+
remainder.to_s
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
203
224
|
end
|
204
225
|
|
205
226
|
def generate_base13_isbn
|
206
|
-
|
207
|
-
|
208
|
-
|
227
|
+
generate(:string) do |g|
|
228
|
+
g.int(name: :values, length: 12)
|
229
|
+
g.lit('-')
|
230
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
231
|
+
remainder = sum(values.to_s) { |value, offset| offset.even? ? value.to_i : value.to_i * 3 } % 10
|
232
|
+
(10 - remainder) % 10
|
233
|
+
end
|
234
|
+
end
|
209
235
|
end
|
210
236
|
|
211
237
|
def sum(values)
|
@@ -215,15 +241,31 @@ module Faker
|
|
215
241
|
end
|
216
242
|
|
217
243
|
def generate_base8_ean
|
218
|
-
|
219
|
-
|
220
|
-
|
244
|
+
generate(:string) do |g|
|
245
|
+
g.int(name: :values, length: 7)
|
246
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
247
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
|
248
|
+
if check_digit == 10
|
249
|
+
0
|
250
|
+
else
|
251
|
+
check_digit
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
221
255
|
end
|
222
256
|
|
223
257
|
def generate_base13_ean
|
224
|
-
|
225
|
-
|
226
|
-
|
258
|
+
generate(:string) do |g|
|
259
|
+
g.int(name: :values, length: 12)
|
260
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
261
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
|
262
|
+
if check_digit == 10
|
263
|
+
0
|
264
|
+
else
|
265
|
+
check_digit
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
227
269
|
end
|
228
270
|
|
229
271
|
EAN_CHECK_DIGIT8 = [3, 1, 3, 1, 3, 1, 3].freeze
|
@@ -231,7 +273,7 @@ module Faker
|
|
231
273
|
|
232
274
|
def rut_verificator_digit(rut)
|
233
275
|
total = rut.to_s.rjust(8, '0').chars.zip(%w[3 2 7 6 5 4 3 2]).collect { |a, b| a.to_i * b.to_i }.inject(:+)
|
234
|
-
(11 - total % 11).to_s.gsub(
|
276
|
+
(11 - total % 11).to_s.gsub('10', 'k').gsub('11', '0')
|
235
277
|
end
|
236
278
|
|
237
279
|
def generate_nric_check_alphabet(values, prefix)
|
@@ -151,6 +151,19 @@ module Faker
|
|
151
151
|
fetch('company.profession')
|
152
152
|
end
|
153
153
|
|
154
|
+
##
|
155
|
+
# Produces a company department.
|
156
|
+
#
|
157
|
+
# @return [String]
|
158
|
+
#
|
159
|
+
# @example
|
160
|
+
# Faker::Company.department #=> "Information Technology"
|
161
|
+
#
|
162
|
+
# @faker.version next
|
163
|
+
def department
|
164
|
+
fetch('company.department')
|
165
|
+
end
|
166
|
+
|
154
167
|
##
|
155
168
|
# Produces a company spanish organisation number.
|
156
169
|
#
|
@@ -330,7 +343,12 @@ module Faker
|
|
330
343
|
#
|
331
344
|
# @faker.version 1.9.2
|
332
345
|
def south_african_pty_ltd_registration_number
|
333
|
-
|
346
|
+
generate(:string) do |g|
|
347
|
+
g.int(length: 4)
|
348
|
+
g.lit('/')
|
349
|
+
g.int(ranges: [1000..9_999_999_999])
|
350
|
+
g.lit('/07')
|
351
|
+
end
|
334
352
|
end
|
335
353
|
|
336
354
|
##
|
@@ -343,7 +361,18 @@ module Faker
|
|
343
361
|
#
|
344
362
|
# @faker.version 1.9.2
|
345
363
|
def south_african_close_corporation_registration_number
|
346
|
-
|
364
|
+
generate(:string) do |g|
|
365
|
+
g.oneof do |one|
|
366
|
+
one.group do |g_|
|
367
|
+
g_.lit('CK')
|
368
|
+
g_.int(length: 2)
|
369
|
+
end
|
370
|
+
one.int(length: 4)
|
371
|
+
end
|
372
|
+
g.lit('/')
|
373
|
+
g.int(ranges: [1000..9_999_999_999])
|
374
|
+
g.lit('/23')
|
375
|
+
end
|
347
376
|
end
|
348
377
|
|
349
378
|
##
|
@@ -356,7 +385,12 @@ module Faker
|
|
356
385
|
#
|
357
386
|
# @faker.version 1.9.2
|
358
387
|
def south_african_listed_company_registration_number
|
359
|
-
|
388
|
+
generate(:string) do |g|
|
389
|
+
g.int(length: 4)
|
390
|
+
g.lit('/')
|
391
|
+
g.int(ranges: [1000..9_999_999_999])
|
392
|
+
g.lit('/06')
|
393
|
+
end
|
360
394
|
end
|
361
395
|
|
362
396
|
##
|
@@ -369,7 +403,12 @@ module Faker
|
|
369
403
|
#
|
370
404
|
# @faker.version 1.9.2
|
371
405
|
def south_african_trust_registration_number
|
372
|
-
|
406
|
+
generate(:string) do |g|
|
407
|
+
g.lit('IT')
|
408
|
+
g.int(ranges: [10..9999])
|
409
|
+
g.lit('/')
|
410
|
+
g.int(ranges: [10..9_999_999_999])
|
411
|
+
end
|
373
412
|
end
|
374
413
|
|
375
414
|
##
|
@@ -554,7 +593,7 @@ module Faker
|
|
554
593
|
end
|
555
594
|
|
556
595
|
control = control.to_s[-1].to_i
|
557
|
-
control =
|
596
|
+
control = 10 - control unless control.zero?
|
558
597
|
|
559
598
|
%w[A B C D E F G H J U V].include?(organization_type) ? control : letters[control]
|
560
599
|
end
|
data/lib/faker/default/date.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Faker
|
4
4
|
class Date < Base
|
5
|
+
DAYS_OF_WEEK = %i[sunday monday tuesday wednesday thursday friday saturday].freeze
|
6
|
+
|
5
7
|
class << self
|
6
8
|
##
|
7
9
|
# Produce a random date between two dates.
|
@@ -53,18 +55,26 @@ module Faker
|
|
53
55
|
##
|
54
56
|
# Produce a random date in the future (up to N days).
|
55
57
|
#
|
58
|
+
# @param from [Integer] The start of the usable forward date range.
|
56
59
|
# @param days [Integer] The maximum number of days to go into the future.
|
57
60
|
# @return [Date]
|
58
61
|
#
|
59
|
-
# @example
|
62
|
+
# @example if used with or without Rails (Active Support)
|
60
63
|
# Faker::Date.forward(days: 23) #=> #<Date: 2014-10-03>
|
61
64
|
#
|
65
|
+
# @example if used with Rails (Active Support)
|
66
|
+
# Faker::Date.forward(from: Date.current, days: 17) #=> #<Date: 2022-06-22>
|
67
|
+
#
|
68
|
+
# @example if used with or without Rails (Active Support)
|
69
|
+
# Faker::Date.forward(from: '2022-06-03', days: 10) #=> #<Date: 2022-10-13>
|
70
|
+
#
|
62
71
|
# @faker.version 1.0.0
|
63
|
-
def forward(days: 365)
|
64
|
-
|
65
|
-
|
72
|
+
def forward(from: ::Date.today, days: 365)
|
73
|
+
start_date = get_date_object(from)
|
74
|
+
since = start_date + 1
|
75
|
+
to = start_date + days
|
66
76
|
|
67
|
-
between(from:
|
77
|
+
between(from: since, to: to).to_date
|
68
78
|
end
|
69
79
|
|
70
80
|
##
|
@@ -128,6 +138,52 @@ module Faker
|
|
128
138
|
between(from: from, to: to).to_date
|
129
139
|
end
|
130
140
|
|
141
|
+
##
|
142
|
+
# Produce a random date at given day(s) of the week between two dates.
|
143
|
+
#
|
144
|
+
# @param day [Symbol, Array<Symbol>] # The day(s) of the week. See {DAYS_OF_WEEK}.
|
145
|
+
# @param from [Date, String] The start of the usable date range.
|
146
|
+
# @param to [Date, String] The end of the usable date range.
|
147
|
+
# @return [Date]
|
148
|
+
#
|
149
|
+
# @example if used with or without Rails (Active Support)
|
150
|
+
# Faker::Date.on_day_of_week_between(day: :tuesday, from: '2023-01-01', to: '2023-02-01') #=> #<Date: 2032-01-10>
|
151
|
+
#
|
152
|
+
# @example if used with Rails (Active Support)
|
153
|
+
# Faker::Date.on_day_of_week_between(day: [:saturday, :sunday], from: 1.month.ago, to: Date.today) #=> #<Date: 2014-09-24>
|
154
|
+
#
|
155
|
+
# @faker.version next
|
156
|
+
def on_day_of_week_between(day:, from:, to:)
|
157
|
+
days = [day].flatten
|
158
|
+
raise ArgumentError, 'Day of week cannot be empty' if days.empty?
|
159
|
+
|
160
|
+
# Convert given days of the week to numbers used by `Date#wday` method
|
161
|
+
numeric_weekdays = days.map do |d|
|
162
|
+
DAYS_OF_WEEK.index(d.to_sym.downcase) || raise(ArgumentError, "#{d} is not a valid day of the week")
|
163
|
+
end
|
164
|
+
|
165
|
+
from = get_date_object(from)
|
166
|
+
to = get_date_object(to)
|
167
|
+
date = Faker::Base.rand_in_range(from, to)
|
168
|
+
|
169
|
+
# If the initial date is not on one of the wanted days of the week...
|
170
|
+
unless numeric_weekdays.include? date.wday
|
171
|
+
# ...pick a date nearby that is on one of the wanted days of the week instead
|
172
|
+
date += sample(numeric_weekdays) - date.wday
|
173
|
+
|
174
|
+
# Move date 1 week earlier or later if the adjusted date is now outside the date range
|
175
|
+
date += 7 if date < from
|
176
|
+
date -= 7 if date > to
|
177
|
+
|
178
|
+
if date > to || date < from
|
179
|
+
raise ArgumentError,
|
180
|
+
"There is no #{DAYS_OF_WEEK[date.wday].capitalize} between #{from} and #{to}. Increase the from/to date range or choose a different day of the week."
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
date
|
185
|
+
end
|
186
|
+
|
131
187
|
private
|
132
188
|
|
133
189
|
def birthday_date(date, age)
|
@@ -98,17 +98,28 @@ module Faker
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def gb_licence_year(dob, gender)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
generate(:string) do |g|
|
102
|
+
g.computed do
|
103
|
+
(dob.year / 10) % 10
|
104
|
+
end
|
105
|
+
g.computed do
|
106
|
+
gender_marker = gender == :female ? 50 : 0
|
107
|
+
format('%02d', (dob.month + gender_marker))
|
108
|
+
end
|
109
|
+
g.computed do
|
110
|
+
format('%02d', dob.day)
|
111
|
+
end
|
112
|
+
g.computed do
|
113
|
+
dob.year % 10
|
114
|
+
end
|
115
|
+
end
|
108
116
|
end
|
109
117
|
|
110
118
|
def gb_licence_checksum
|
111
|
-
|
119
|
+
generate(:string) do |g|
|
120
|
+
g.int
|
121
|
+
g.letter(ranges: ['A'..'Z'], length: 2)
|
122
|
+
end
|
112
123
|
end
|
113
124
|
end
|
114
125
|
end
|
data/lib/faker/default/food.rb
CHANGED
@@ -5,6 +5,19 @@ module Faker
|
|
5
5
|
flexible :food
|
6
6
|
|
7
7
|
class << self
|
8
|
+
##
|
9
|
+
# Retrieves an allergen.
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Faker::Food.allergen #=> "Peanuts"
|
15
|
+
#
|
16
|
+
# @faker.version next
|
17
|
+
def allergen
|
18
|
+
fetch('food.allergens')
|
19
|
+
end
|
20
|
+
|
8
21
|
##
|
9
22
|
# Retrieves a typical dish from each country.
|
10
23
|
#
|