faker 2.15.1 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +848 -34
- data/README.md +225 -103
- data/lib/faker/blockchain/aeternity.rb +1 -1
- data/lib/faker/blockchain/bitcoin.rb +2 -2
- data/lib/faker/blockchain/ethereum.rb +1 -1
- data/lib/faker/blockchain/tezos.rb +31 -3
- data/lib/faker/books/dune.rb +2 -10
- data/lib/faker/books/lovecraft.rb +9 -41
- data/lib/faker/books/the_kingkiller_chronicle.rb +61 -0
- data/lib/faker/creature/bird.rb +203 -0
- data/lib/faker/default/address.rb +7 -27
- data/lib/faker/default/alphanumeric.rb +2 -8
- data/lib/faker/default/app.rb +1 -10
- data/lib/faker/default/avatar.rb +1 -12
- data/lib/faker/default/bank.rb +25 -17
- data/lib/faker/default/barcode.rb +33 -22
- data/lib/faker/default/boolean.rb +1 -4
- data/lib/faker/default/cannabis.rb +10 -0
- data/lib/faker/default/chile_rut.rb +25 -25
- data/lib/faker/default/chuck_norris.rb +1 -0
- data/lib/faker/default/code.rb +71 -42
- data/lib/faker/default/color.rb +77 -6
- data/lib/faker/default/commerce.rb +31 -17
- data/lib/faker/default/company.rb +137 -22
- data/lib/faker/default/crypto.rb +26 -4
- data/lib/faker/default/crypto_coin.rb +3 -15
- data/lib/faker/default/date.rb +65 -42
- data/lib/faker/default/demographic.rb +1 -5
- data/lib/faker/default/driving_licence.rb +20 -18
- data/lib/faker/default/drone.rb +1 -1
- data/lib/faker/default/educator.rb +13 -0
- data/lib/faker/default/emotion.rb +33 -0
- data/lib/faker/default/file.rb +5 -22
- data/lib/faker/default/finance.rb +30 -7
- data/lib/faker/default/food.rb +27 -1
- data/lib/faker/default/hipster.rb +8 -48
- data/lib/faker/default/hobby.rb +22 -0
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +175 -27
- data/lib/faker/default/internet.rb +333 -114
- data/lib/faker/default/invoice.rb +4 -17
- data/lib/faker/default/json.rb +4 -21
- data/lib/faker/default/lorem.rb +175 -73
- data/lib/faker/default/lorem_flickr.rb +4 -37
- data/lib/faker/default/markdown.rb +10 -13
- data/lib/faker/default/marketing.rb +1 -1
- data/lib/faker/default/measurement.rb +16 -48
- data/lib/faker/default/name.rb +1 -5
- data/lib/faker/default/nation.rb +0 -3
- data/lib/faker/default/{nhs.rb → national_health_service.rb} +9 -8
- data/lib/faker/default/number.rb +33 -61
- data/lib/faker/default/omniauth.rb +55 -52
- data/lib/faker/default/phone_number.rb +36 -21
- data/lib/faker/default/placeholdit.rb +10 -20
- data/lib/faker/default/relationship.rb +1 -5
- data/lib/faker/default/religion.rb +6 -0
- data/lib/faker/default/science.rb +108 -0
- data/lib/faker/default/source.rb +3 -16
- data/lib/faker/default/south_africa.rb +3 -3
- data/lib/faker/default/string.rb +1 -7
- data/lib/faker/default/stripe.rb +4 -20
- data/lib/faker/default/tea.rb +41 -0
- data/lib/faker/{music/show.rb → default/theater.rb} +11 -8
- data/lib/faker/default/time.rb +4 -34
- data/lib/faker/default/twitter.rb +7 -23
- data/lib/faker/default/types.rb +12 -34
- data/lib/faker/default/vehicle.rb +44 -54
- data/lib/faker/default/vulnerability_identifier.rb +23 -0
- data/lib/faker/default/world_cup.rb +2 -11
- data/lib/faker/games/clash_of_clans.rb +1 -1
- data/lib/faker/games/dnd.rb +49 -7
- data/lib/faker/games/dota.rb +14 -5
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/minecraft.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/games/tarkov.rb +205 -0
- data/lib/faker/games/touhou.rb +75 -0
- data/lib/faker/games/witcher.rb +39 -0
- data/lib/faker/japanese_media/cowboy_bebop.rb +61 -0
- data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +51 -0
- data/lib/faker/japanese_media/kamen_rider.rb +102 -0
- data/lib/faker/japanese_media/one_piece.rb +1 -1
- data/lib/faker/locations/australia.rb +52 -0
- data/lib/faker/movies/avatar.rb +49 -0
- data/lib/faker/movies/hackers.rb +48 -0
- data/lib/faker/movies/star_wars.rb +73 -5
- data/lib/faker/movies/{room.rb → the_room.rb} +4 -4
- data/lib/faker/movies/tron.rb +161 -0
- data/lib/faker/music/hiphop.rb +3 -3
- data/lib/faker/music/music.rb +12 -0
- data/lib/faker/music/rock_band.rb +12 -0
- data/lib/faker/music/smashing_pumpkins.rb +64 -0
- data/lib/faker/quotes/quote.rb +13 -0
- data/lib/faker/quotes/rajnikanth.rb +1 -0
- data/lib/faker/quotes/shakespeare.rb +34 -0
- data/lib/faker/religion/bible.rb +50 -0
- data/lib/faker/sports/chess.rb +90 -0
- data/lib/faker/sports/mountaineering.rb +22 -0
- data/lib/faker/sports/sport.rb +116 -0
- data/lib/faker/travel/airport.rb +43 -0
- data/lib/faker/travel/train_station.rb +54 -0
- data/lib/faker/tv_shows/archer.rb +51 -0
- data/lib/faker/tv_shows/big_bang_theory.rb +1 -1
- data/lib/faker/tv_shows/brooklyn_nine_nine.rb +38 -0
- data/lib/faker/tv_shows/michael_scott.rb +0 -3
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/tv_shows/spongebob.rb +50 -0
- data/lib/faker/tv_shows/suits.rb +1 -1
- data/lib/faker/tv_shows/supernatural.rb +48 -0
- data/lib/faker/tv_shows/the_office.rb +37 -0
- data/lib/faker/version.rb +2 -2
- data/lib/faker.rb +26 -67
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/deprecator.rb +53 -0
- data/lib/helpers/positional_generator.rb +480 -0
- data/lib/helpers/unique_generator.rb +13 -14
- data/lib/locales/README.md +18 -2
- data/lib/locales/ar.yml +6 -1
- data/lib/locales/bg.yml +1 -2
- data/lib/locales/da-DK.yml +529 -35
- data/lib/locales/de-AT.yml +3487 -27
- data/lib/locales/de-CH.yml +4328 -12
- data/lib/locales/de.yml +7185 -99
- data/lib/locales/ee.yml +0 -1
- data/lib/locales/en/address.yml +1826 -562
- data/lib/locales/en/airport.yml +381 -0
- data/lib/locales/en/animal.yml +1 -1
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/australia.yml +108 -0
- data/lib/locales/en/avatar.yml +31 -0
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/bible.yml +90 -0
- data/lib/locales/en/bird.yml +1281 -0
- data/lib/locales/en/book.yml +487 -3
- data/lib/locales/en/brooklyn_nine_nine.yml +35 -0
- data/lib/locales/en/cat.yml +1 -1
- data/lib/locales/en/chess.yml +103 -0
- data/lib/locales/en/coffee.yml +1 -1
- data/lib/locales/en/commerce.yml +17 -0
- data/lib/locales/en/community.yml +17 -17
- data/lib/locales/en/company.yml +1 -0
- data/lib/locales/en/computer.yml +23 -4
- data/lib/locales/en/cowboy_bebop.yml +163 -0
- data/lib/locales/en/device.yml +112 -4
- data/lib/locales/en/dnd.yml +186 -1
- data/lib/locales/en/dog.yml +262 -7
- data/lib/locales/en/dota.yml +173 -0
- data/lib/locales/en/dune.yml +266 -397
- data/lib/locales/en/educator.yml +6 -0
- data/lib/locales/en/emotion.yml +480 -0
- data/lib/locales/en/file.yml +9 -1
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/finance.yml +27 -4
- data/lib/locales/en/food.yml +1067 -10
- data/lib/locales/en/football.yml +3 -3
- data/lib/locales/en/fullmetal_alchemist_brotherhood.yml +78 -0
- data/lib/locales/en/game.yml +11 -0
- data/lib/locales/en/hackers.yml +53 -0
- data/lib/locales/en/harry_potter.yml +1 -1
- data/lib/locales/en/heroes.yml +2 -2
- data/lib/locales/en/hobby.yml +171 -0
- data/lib/locales/en/horse.yml +2 -2
- data/lib/locales/en/id_number.yml +1 -1
- data/lib/locales/en/internet.yml +136 -3
- data/lib/locales/en/kamen_rider.yml +452 -0
- data/lib/locales/en/kpop.yml +7 -7
- data/lib/locales/en/lebowski.yml +1 -1
- data/lib/locales/en/lovecraft.yml +76 -6
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/mitch_hedberg.yml +46 -0
- data/lib/locales/en/mountain.yml +14 -1
- data/lib/locales/en/mountaineering.yml +14 -0
- data/lib/locales/en/movie.yml +2 -1
- data/lib/locales/en/music.yml +152 -142
- data/lib/locales/en/naruto.yml +2 -3
- data/lib/locales/en/one_piece.yml +1 -1
- data/lib/locales/en/opera.yml +2 -2
- data/lib/locales/en/overwatch.yml +5 -7
- data/lib/locales/en/phone_number.yml +78 -3
- data/lib/locales/en/rock_band.yml +1 -0
- data/lib/locales/en/science.yml +481 -3
- data/lib/locales/en/shakespeare.yml +21 -24
- data/lib/locales/en/smashing_pumpkins.yml +382 -0
- data/lib/locales/en/source.yml +5 -0
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/space.yml +1 -1
- data/lib/locales/en/spongebob.yml +489 -0
- data/lib/locales/en/sport.yml +130 -0
- data/lib/locales/en/star_wars.yml +1 -1
- data/lib/locales/en/stranger_thing.yml +1 -1
- data/lib/locales/en/super_smash_bros.yml +7 -2
- data/lib/locales/en/supernatural.yml +141 -0
- data/lib/locales/en/tarkov.yml +593 -0
- data/lib/locales/en/tea.yml +172 -0
- data/lib/locales/en/the_kingkiller_chronicle.yml +56 -0
- data/lib/locales/en/the_office.yml +86 -0
- data/lib/locales/en/{room.yml → the_room.yml} +1 -1
- data/lib/locales/en/{show.yml → theater.yml} +1 -1
- data/lib/locales/en/touhou.yml +839 -0
- data/lib/locales/en/train_station.yml +280 -0
- data/lib/locales/en/tron.yml +227 -0
- data/lib/locales/en/vehicle.yml +2809 -75
- data/lib/locales/en/witcher.yml +37 -0
- data/lib/locales/en-AU.yml +718 -47
- data/lib/locales/en-CA.yml +373 -18
- data/lib/locales/en-GB.yml +116 -8
- data/lib/locales/en-IND.yml +1259 -17
- data/lib/locales/en-KE.yml +212 -0
- data/lib/locales/en-MS.yml +364 -17
- data/lib/locales/en-NEP.yml +212 -38
- data/lib/locales/en-NG.yml +1 -0
- data/lib/locales/en-NZ.yml +1153 -123
- data/lib/locales/en-PAK.yml +369 -10
- data/lib/locales/en-SG.yml +581 -16
- data/lib/locales/en-UG.yml +1 -0
- data/lib/locales/en-US.yml +6914 -74
- data/lib/locales/en-ZA.yml +1 -1
- data/lib/locales/en-au-ocker.yml +266 -22
- data/lib/locales/es-AR.yml +4570 -0
- data/lib/locales/es-MX.yml +1 -2
- data/lib/locales/es.yml +2 -3
- data/lib/locales/fi-FI.yml +3 -1
- data/lib/locales/fr/address.yml +20 -0
- data/lib/locales/fr/adjective.yml +266 -0
- data/lib/locales/fr/ancient.yml +141 -0
- data/lib/locales/fr/animal.yml +5 -0
- data/lib/locales/fr/appliance.yml +4 -0
- data/lib/locales/fr/book.yml +7 -0
- data/lib/locales/fr/color.yml +4 -0
- data/lib/locales/fr/company.yml +17 -0
- data/lib/locales/fr/compass.yml +23 -0
- data/lib/locales/fr/demographic.yml +4 -0
- data/lib/locales/fr/gender.yml +6 -0
- data/lib/locales/fr/internet.yml +4 -0
- data/lib/locales/fr/lorem.yml +5 -0
- data/lib/locales/fr/measurement.yml +7 -0
- data/lib/locales/fr/name.yml +22 -0
- data/lib/locales/fr/phone_number.yml +7 -0
- data/lib/locales/fr/pokemon.yml +7 -0
- data/lib/locales/fr-CA.yml +2733 -44
- data/lib/locales/fr-CH.yml +1 -2
- data/lib/locales/fr.yml +2 -118
- data/lib/locales/hy.yml +3624 -119
- data/lib/locales/id.yml +839 -12
- data/lib/locales/it.yml +1304 -32
- data/lib/locales/ja/README.md +13 -0
- data/lib/locales/ja/address.yml +120539 -0
- data/lib/locales/ja/adjective.yml +148 -0
- data/lib/locales/ja/ancient.yml +4 -0
- data/lib/locales/ja/animal.yml +5 -0
- data/lib/locales/ja/bank.yml +4 -0
- data/lib/locales/ja/book.yml +7 -0
- data/lib/locales/ja/cat.yml +5 -0
- data/lib/locales/ja/coffee.yml +4 -0
- data/lib/locales/ja/color.yml +4 -0
- data/lib/locales/ja/commerce.yml +11 -0
- data/lib/locales/ja/company.yml +8 -0
- data/lib/locales/ja/dog.yml +6 -0
- data/lib/locales/ja/emotion.yml +51 -0
- data/lib/locales/ja/food.yml +4 -0
- data/lib/locales/ja/football.yml +115 -0
- data/lib/locales/ja/gender.yml +4 -0
- data/lib/locales/ja/lorem.yml +9 -0
- data/lib/locales/ja/name.yml +13 -0
- data/lib/locales/ja/naruto.yml +230 -0
- data/lib/locales/ja/overwatch.yml +5 -0
- data/lib/locales/ja/phone_number.yml +7 -0
- data/lib/locales/ja/pokemon.yml +7 -0
- data/lib/locales/ja/relationship.yml +10 -0
- data/lib/locales/ja/restaurant.yml +11 -0
- data/lib/locales/ja/space.yml +5 -0
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ja/studio_ghibli.yml +112 -0
- data/lib/locales/ja/subscription.yml +8 -0
- data/lib/locales/ja/super_mario.yml +9 -0
- data/lib/locales/ja/super_smash_bros.yml +8 -0
- data/lib/locales/ja/touhou.yml +466 -0
- data/lib/locales/ja/university.yml +9 -0
- data/lib/locales/ja/zelda.yml +5 -0
- data/lib/locales/ko.yml +1361 -20
- data/lib/locales/lt.yml +315 -0
- data/lib/locales/lv.yml +1 -2
- data/lib/locales/mi-NZ.yml +283 -0
- data/lib/locales/nb-NO.yml +518 -29
- data/lib/locales/nl.yml +1 -1
- data/lib/locales/pl.yml +1 -2
- data/lib/locales/pt-BR.yml +8157 -660
- data/lib/locales/pt.yml +844 -45
- data/lib/locales/ru.yml +1355 -32
- data/lib/locales/sk.yml +4410 -43
- data/lib/locales/sv.yml +100 -0
- data/lib/locales/th.yml +76 -76
- data/lib/locales/tr.yml +1 -2
- data/lib/locales/uk.yml +1808 -44
- data/lib/locales/vi.yml +1 -0
- data/lib/locales/zh-CN/bank.yml +17 -0
- data/lib/locales/zh-CN.yml +1 -0
- data/lib/locales/zh-TW.yml +1 -0
- metadata +134 -133
- data/History.md +0 -176
- data/lib/faker/default/fillmurray.rb +0 -45
- data/lib/faker/default/lorem_pixel.rb +0 -69
- data/lib/locales/ja.yml +0 -105
- /data/lib/faker/default/{faker_adjective.rb → adjective.rb} +0 -0
@@ -27,11 +27,7 @@ module Faker
|
|
27
27
|
# Faker::Commerce.promotion_code(digits: 2) #=> "AmazingPrice57"
|
28
28
|
#
|
29
29
|
# @faker.version 1.7.0
|
30
|
-
def promotion_code(
|
31
|
-
warn_for_deprecated_arguments do |keywords|
|
32
|
-
keywords << :digits if legacy_digits != NOT_GIVEN
|
33
|
-
end
|
34
|
-
|
30
|
+
def promotion_code(digits: 6)
|
35
31
|
[
|
36
32
|
fetch('commerce.promotion_code.adjective'),
|
37
33
|
fetch('commerce.promotion_code.noun'),
|
@@ -52,12 +48,7 @@ module Faker
|
|
52
48
|
# Faker::Commerce.department(max: 2, fixed_amount: true) #=> "Books & Tools"
|
53
49
|
#
|
54
50
|
# @faker.version 1.2.0
|
55
|
-
def department(
|
56
|
-
warn_for_deprecated_arguments do |keywords|
|
57
|
-
keywords << :max if legacy_max != NOT_GIVEN
|
58
|
-
keywords << :fixed_amount if legacy_fixed_amount != NOT_GIVEN
|
59
|
-
end
|
60
|
-
|
51
|
+
def department(max: 3, fixed_amount: false)
|
61
52
|
num = max if fixed_amount
|
62
53
|
num ||= 1 + rand(max)
|
63
54
|
|
@@ -112,12 +103,7 @@ module Faker
|
|
112
103
|
# Faker::Commerce.price(range: 0..10.0, as_string: true) #=> "2.18"
|
113
104
|
#
|
114
105
|
# @faker.version 1.2.0
|
115
|
-
def price(
|
116
|
-
warn_for_deprecated_arguments do |keywords|
|
117
|
-
keywords << :range if legacy_range != NOT_GIVEN
|
118
|
-
keywords << :as_string if legacy_as_string != NOT_GIVEN
|
119
|
-
end
|
120
|
-
|
106
|
+
def price(range: 0..100.0, as_string: false)
|
121
107
|
price = (rand(range) * 100).floor / 100.0
|
122
108
|
if as_string
|
123
109
|
price_parts = price.to_s.split('.')
|
@@ -126,6 +112,34 @@ module Faker
|
|
126
112
|
price
|
127
113
|
end
|
128
114
|
|
115
|
+
##
|
116
|
+
# Produces a randomized string of a brand name
|
117
|
+
# @example
|
118
|
+
# Faker::Commerce.brand #=> 'Apple'
|
119
|
+
#
|
120
|
+
# @return [string]
|
121
|
+
#
|
122
|
+
# @faker.version next
|
123
|
+
#
|
124
|
+
##
|
125
|
+
def brand
|
126
|
+
fetch('commerce.brand')
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Produces a randomized string of a vendor name
|
131
|
+
# @example
|
132
|
+
# Faker::Commerce.vendor #=> 'Dollar General'
|
133
|
+
#
|
134
|
+
# @return [string]
|
135
|
+
#
|
136
|
+
# @faker.version next
|
137
|
+
#
|
138
|
+
##
|
139
|
+
def vendor
|
140
|
+
fetch('commerce.vendor')
|
141
|
+
end
|
142
|
+
|
129
143
|
private
|
130
144
|
|
131
145
|
def categories(num)
|
@@ -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
|
#
|
@@ -296,7 +309,7 @@ module Faker
|
|
296
309
|
result = Array.new(3) { rand(1..9) } + Array.new(7) { rand(10) }
|
297
310
|
break if (weight_sum(result, weights) % 11) == result[9]
|
298
311
|
end
|
299
|
-
result.join
|
312
|
+
result.join
|
300
313
|
end
|
301
314
|
|
302
315
|
##
|
@@ -309,11 +322,7 @@ module Faker
|
|
309
322
|
#
|
310
323
|
# @faker.version 1.9.1
|
311
324
|
# Get a random Polish register of national economy number. More info https://pl.wikipedia.org/wiki/REGON
|
312
|
-
def polish_register_of_national_economy(
|
313
|
-
warn_for_deprecated_arguments do |keywords|
|
314
|
-
keywords << :length if legacy_length != NOT_GIVEN
|
315
|
-
end
|
316
|
-
|
325
|
+
def polish_register_of_national_economy(length: 9)
|
317
326
|
raise ArgumentError, 'Length should be 9 or 14' unless [9, 14].include? length
|
318
327
|
|
319
328
|
random_digits = []
|
@@ -321,7 +330,7 @@ module Faker
|
|
321
330
|
random_digits = Array.new(length) { rand(10) }
|
322
331
|
break if collect_regon_sum(random_digits) == random_digits.last
|
323
332
|
end
|
324
|
-
random_digits.join
|
333
|
+
random_digits.join
|
325
334
|
end
|
326
335
|
|
327
336
|
##
|
@@ -334,7 +343,12 @@ module Faker
|
|
334
343
|
#
|
335
344
|
# @faker.version 1.9.2
|
336
345
|
def south_african_pty_ltd_registration_number
|
337
|
-
|
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
|
338
352
|
end
|
339
353
|
|
340
354
|
##
|
@@ -347,7 +361,18 @@ module Faker
|
|
347
361
|
#
|
348
362
|
# @faker.version 1.9.2
|
349
363
|
def south_african_close_corporation_registration_number
|
350
|
-
|
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
|
351
376
|
end
|
352
377
|
|
353
378
|
##
|
@@ -360,7 +385,12 @@ module Faker
|
|
360
385
|
#
|
361
386
|
# @faker.version 1.9.2
|
362
387
|
def south_african_listed_company_registration_number
|
363
|
-
|
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
|
364
394
|
end
|
365
395
|
|
366
396
|
##
|
@@ -373,7 +403,12 @@ module Faker
|
|
373
403
|
#
|
374
404
|
# @faker.version 1.9.2
|
375
405
|
def south_african_trust_registration_number
|
376
|
-
|
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
|
377
412
|
end
|
378
413
|
|
379
414
|
##
|
@@ -385,11 +420,7 @@ module Faker
|
|
385
420
|
# Faker::Company.brazilian_company_number #=> "37205322000500"
|
386
421
|
#
|
387
422
|
# @faker.version 1.9.2
|
388
|
-
def brazilian_company_number(
|
389
|
-
warn_for_deprecated_arguments do |keywords|
|
390
|
-
keywords << :formatted if legacy_formatted != NOT_GIVEN
|
391
|
-
end
|
392
|
-
|
423
|
+
def brazilian_company_number(formatted: false)
|
393
424
|
digits = Array.new(8) { Faker::Number.digit.to_i } + [0, 0, 0, Faker::Number.non_zero_digit.to_i]
|
394
425
|
|
395
426
|
factors = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 6].cycle
|
@@ -404,7 +435,18 @@ module Faker
|
|
404
435
|
formatted ? format('%s.%s.%s/%s-%s', *number.scan(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/).flatten) : number
|
405
436
|
end
|
406
437
|
|
438
|
+
##
|
407
439
|
# Get a random Russian tax number.
|
440
|
+
# @param region [String] Any region string
|
441
|
+
# @param type [Symbol] Legeal or not, defaults to :legal
|
442
|
+
#
|
443
|
+
# @return [String]
|
444
|
+
# @example
|
445
|
+
# Faker::Company.russian_tax_number #=> "0415584064"
|
446
|
+
# Faker::Company.russian_tax_number(region: 'AZ') #=> "AZ50124562"
|
447
|
+
# Faker::Company.russian_tax_number(region: 'AZ', type: false) #=> "AZ8802315465"
|
448
|
+
#
|
449
|
+
# @faker.version 1.9.4
|
408
450
|
def russian_tax_number(region: nil, type: :legal)
|
409
451
|
inn_number(region, type)
|
410
452
|
end
|
@@ -422,6 +464,61 @@ module Faker
|
|
422
464
|
fetch('company.sic_code')
|
423
465
|
end
|
424
466
|
|
467
|
+
##
|
468
|
+
# Get a random Indian Goods and Services Tax (GST) number.
|
469
|
+
# For more on Indian tax number here:
|
470
|
+
# https://simple.wikipedia.org/wiki/GSTIN
|
471
|
+
# @params state code [String] Any state code.
|
472
|
+
#
|
473
|
+
# @return [String]
|
474
|
+
# @example
|
475
|
+
# Faker::Company.indian_gst_number #=> "15VQPNZ2126J2ZU"
|
476
|
+
# Faker::Company.indian_gst_number(state_code: "22") #=> "22ZVWEY6632K0ZN"
|
477
|
+
#
|
478
|
+
# @faker.version 3.2.1
|
479
|
+
def indian_gst_number(state_code: nil)
|
480
|
+
# Check if state code is valid
|
481
|
+
state_code_ranges = [('02'..'38'), ['98']]
|
482
|
+
if state_code && !(state_code_ranges[0].include?(state_code) || state_code == '98')
|
483
|
+
raise ArgumentError, 'state code must be in a range of 02 to 38 or 98'
|
484
|
+
end
|
485
|
+
|
486
|
+
PositionalGenerator.new(:string) do |gen|
|
487
|
+
# Generate a state code if not given
|
488
|
+
if state_code
|
489
|
+
gen.lit(state_code, name: :state_code_param)
|
490
|
+
else
|
491
|
+
gen.letter(name: :state_code_param, length: 1, ranges: state_code_ranges)
|
492
|
+
end
|
493
|
+
|
494
|
+
# Construct taxpayer number
|
495
|
+
gen.group(name: :taxpayer_number) do |g_|
|
496
|
+
g_.letter(length: 3, ranges: ['A'..'Z'])
|
497
|
+
g_.letter(length: 1, ranges: [%w[A B C F G H L J P T K]].to_a)
|
498
|
+
g_.letter(length: 1, ranges: ['A'..'Z'])
|
499
|
+
g_.int(length: 4, ranges: [0..9999])
|
500
|
+
g_.letter(length: 1, ranges: ['A'..'Z'])
|
501
|
+
end
|
502
|
+
|
503
|
+
gen.int(name: :registration_number, length: 1, ranges: [0..9])
|
504
|
+
|
505
|
+
gen.letter(name: :z_char, length: 1, ranges: [['Z']])
|
506
|
+
|
507
|
+
gen.computed(deps: %i[state_code_param taxpayer_number registration_number]) do |state_code_param, taxpayer_number, registration_number|
|
508
|
+
gst_base = "#{state_code_param}#{taxpayer_number}#{registration_number}"
|
509
|
+
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.chars
|
510
|
+
values = gst_base.chars
|
511
|
+
sum = values.map.with_index do |char, index|
|
512
|
+
product = chars.index(char) * (index.odd? ? 2 : 1)
|
513
|
+
(product / chars.length).floor + (product % chars.length)
|
514
|
+
end.reduce(:+)
|
515
|
+
|
516
|
+
checksum = (chars.length - (sum % chars.length)) % chars.length
|
517
|
+
chars[checksum]
|
518
|
+
end
|
519
|
+
end.generate
|
520
|
+
end
|
521
|
+
|
425
522
|
private
|
426
523
|
|
427
524
|
# Mod11 functionality from https://github.com/badmanski/mod11/blob/master/lib/mod11.rb
|
@@ -448,7 +545,7 @@ module Faker
|
|
448
545
|
def luhn_algorithm(number)
|
449
546
|
multiplications = []
|
450
547
|
|
451
|
-
number.to_s.reverse.
|
548
|
+
number.to_s.reverse.chars.each_with_index do |digit, i|
|
452
549
|
multiplications << if i.even?
|
453
550
|
digit.to_i * 2
|
454
551
|
else
|
@@ -500,15 +597,20 @@ module Faker
|
|
500
597
|
sum
|
501
598
|
end
|
502
599
|
|
503
|
-
# rubocop:disable Style/AsciiComments
|
504
600
|
#
|
505
601
|
# For more on Russian tax number algorithm here:
|
506
602
|
# https://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика#Вычисление_контрольных_цифр
|
507
603
|
#
|
508
604
|
# Range of regions:
|
509
605
|
# https://ru.wikipedia.org/wiki/Коды_субъектов_Российской_Федерации
|
606
|
+
# region [String] Any region string
|
607
|
+
# @param type [Symbol] Legeal or not, defaults to :legal
|
510
608
|
#
|
511
|
-
#
|
609
|
+
# @return [String]
|
610
|
+
# @example
|
611
|
+
# Faker::Comnpany.russian_tax_number
|
612
|
+
# Faker::Comnpany.russian_tax_number(region: 'AZ')
|
613
|
+
# Faker::Comnpany.russian_tax_number(region: 'AZ', type: false)
|
512
614
|
def inn_number(region, type)
|
513
615
|
n10 = [2, 4, 10, 3, 5, 9, 4, 6, 8]
|
514
616
|
n11 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8]
|
@@ -535,9 +637,9 @@ module Faker
|
|
535
637
|
end
|
536
638
|
|
537
639
|
def spanish_cif_control_digit(organization_type, code)
|
538
|
-
letters = %w[J A B C D E F G H]
|
640
|
+
letters = %w[J A B C D E F G H I]
|
539
641
|
|
540
|
-
control = code.
|
642
|
+
control = code.chars.each_with_index.inject(0) do |sum, (value, index)|
|
541
643
|
if (index + 1).even?
|
542
644
|
sum + value.to_i
|
543
645
|
else
|
@@ -546,7 +648,7 @@ module Faker
|
|
546
648
|
end
|
547
649
|
|
548
650
|
control = control.to_s[-1].to_i
|
549
|
-
control =
|
651
|
+
control = 10 - control unless control.zero?
|
550
652
|
|
551
653
|
%w[A B C D E F G H J U V].include?(organization_type) ? control : letters[control]
|
552
654
|
end
|
@@ -558,6 +660,19 @@ module Faker
|
|
558
660
|
|
559
661
|
result.to_s[0].to_i + result.to_s[1].to_i
|
560
662
|
end
|
663
|
+
|
664
|
+
def calculate_gst_checksum(state_code, taxpayer_number, registration_number)
|
665
|
+
gst_base = "#{state_code}#{taxpayer_number}#{registration_number}"
|
666
|
+
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.chars
|
667
|
+
values = gst_base.upcase.chars
|
668
|
+
sum = values.map.with_index do |char, index|
|
669
|
+
product = chars.index(char) * (index.odd? ? 2 : 1)
|
670
|
+
(product / chars.length).floor + (product % chars.length)
|
671
|
+
end.reduce(:+)
|
672
|
+
|
673
|
+
checksum = (chars.length - (sum % chars.length)) % chars.length
|
674
|
+
chars[checksum]
|
675
|
+
end
|
561
676
|
end
|
562
677
|
end
|
563
678
|
end
|
data/lib/faker/default/crypto.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'openssl'
|
4
4
|
|
5
5
|
module Faker
|
6
6
|
class Crypto < Base
|
7
7
|
class << self
|
8
|
+
# Setting the lorem character number lower than the default of
|
9
|
+
# 255 reduces the time complexity of each hash algorithm while
|
10
|
+
# still returning deterministically unique values. See
|
11
|
+
# https://github.com/faker-ruby/faker/pull/2938 for more info.
|
12
|
+
MD5_MIN_NUMBER_OF_CHARACTERS = 25
|
13
|
+
SHA1_MIN_NUMBER_OF_CHARACTERS = 31
|
14
|
+
SHA256_MIN_NUMBER_OF_CHARACTERS = 50
|
15
|
+
SHA512_MIN_NUMBER_OF_CHARACTERS = 100
|
16
|
+
|
8
17
|
##
|
9
18
|
# Produces an MD5 hash.
|
10
19
|
#
|
@@ -15,7 +24,7 @@ module Faker
|
|
15
24
|
#
|
16
25
|
# @faker.version 1.6.4
|
17
26
|
def md5
|
18
|
-
Digest::MD5.hexdigest(Lorem.characters)
|
27
|
+
OpenSSL::Digest::MD5.hexdigest(Lorem.characters(number: MD5_MIN_NUMBER_OF_CHARACTERS))
|
19
28
|
end
|
20
29
|
|
21
30
|
##
|
@@ -28,7 +37,7 @@ module Faker
|
|
28
37
|
#
|
29
38
|
# @faker.version 1.6.4
|
30
39
|
def sha1
|
31
|
-
Digest::SHA1.hexdigest(Lorem.characters)
|
40
|
+
OpenSSL::Digest::SHA1.hexdigest(Lorem.characters(number: SHA1_MIN_NUMBER_OF_CHARACTERS))
|
32
41
|
end
|
33
42
|
|
34
43
|
##
|
@@ -41,7 +50,20 @@ module Faker
|
|
41
50
|
#
|
42
51
|
# @faker.version 1.6.4
|
43
52
|
def sha256
|
44
|
-
Digest::SHA256.hexdigest(Lorem.characters)
|
53
|
+
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters(number: SHA256_MIN_NUMBER_OF_CHARACTERS))
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Produces a SHA512 hash.
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# Faker::Crypto.sha512 #=> "7b9fc82a6642874833d01b74a7b4fae3d15373193b55cfba47327f8f0afdc8d0ea155b58639a03a887009ef997dab8dd8d36767620d430f6e787e5996e26da80"
|
63
|
+
#
|
64
|
+
# @faker.version next
|
65
|
+
def sha512
|
66
|
+
OpenSSL::Digest::SHA512.hexdigest(Lorem.characters(number: SHA512_MIN_NUMBER_OF_CHARACTERS))
|
45
67
|
end
|
46
68
|
end
|
47
69
|
end
|
@@ -16,11 +16,7 @@ module Faker
|
|
16
16
|
# Faker::CryptoCoin.coin_name #=> "Bitcoin"
|
17
17
|
#
|
18
18
|
# @faker.version 1.9.2
|
19
|
-
def coin_name(
|
20
|
-
warn_for_deprecated_arguments do |keywords|
|
21
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
22
|
-
end
|
23
|
-
|
19
|
+
def coin_name(coin: coin_array)
|
24
20
|
coin[COIN_NAME]
|
25
21
|
end
|
26
22
|
|
@@ -33,11 +29,7 @@ module Faker
|
|
33
29
|
# Faker::CryptoCoin.acronym #=> "BTC"
|
34
30
|
#
|
35
31
|
# @faker.version 1.9.2
|
36
|
-
def acronym(
|
37
|
-
warn_for_deprecated_arguments do |keywords|
|
38
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
39
|
-
end
|
40
|
-
|
32
|
+
def acronym(coin: coin_array)
|
41
33
|
coin[ACRONYM]
|
42
34
|
end
|
43
35
|
|
@@ -50,11 +42,7 @@ module Faker
|
|
50
42
|
# Faker::CryptoCoin.url_logo #=> "https://i.imgur.com/EFz61Ei.png"
|
51
43
|
#
|
52
44
|
# @faker.version 1.9.2
|
53
|
-
def url_logo(
|
54
|
-
warn_for_deprecated_arguments do |keywords|
|
55
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
56
|
-
end
|
57
|
-
|
45
|
+
def url_logo(coin: coin_array)
|
58
46
|
coin[URL_LOGO]
|
59
47
|
end
|
60
48
|
|
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.
|
@@ -17,20 +19,13 @@ module Faker
|
|
17
19
|
# Faker::Date.between(from: 2.days.ago, to: Date.today) #=> #<Date: 2014-09-24>
|
18
20
|
#
|
19
21
|
# @faker.version 1.0.0
|
20
|
-
def between(
|
21
|
-
warn_for_deprecated_arguments do |keywords|
|
22
|
-
keywords << :from if legacy_from != NOT_GIVEN
|
23
|
-
keywords << :to if legacy_to != NOT_GIVEN
|
24
|
-
end
|
25
|
-
|
22
|
+
def between(from:, to:)
|
26
23
|
from = get_date_object(from)
|
27
24
|
to = get_date_object(to)
|
28
25
|
|
29
26
|
Faker::Base.rand_in_range(from, to)
|
30
27
|
end
|
31
28
|
|
32
|
-
# rubocop:disable Metrics/ParameterLists
|
33
|
-
|
34
29
|
##
|
35
30
|
# Produce a random date between two dates.
|
36
31
|
#
|
@@ -46,17 +41,7 @@ module Faker
|
|
46
41
|
# Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today) #=> #<Date: 2014-10-03>
|
47
42
|
#
|
48
43
|
# @faker.version 1.6.2
|
49
|
-
def between_except(
|
50
|
-
warn_for_deprecated_arguments do |keywords|
|
51
|
-
keywords << :from if legacy_from != NOT_GIVEN
|
52
|
-
end
|
53
|
-
warn_for_deprecated_arguments do |keywords|
|
54
|
-
keywords << :to if legacy_to != NOT_GIVEN
|
55
|
-
end
|
56
|
-
warn_for_deprecated_arguments do |keywords|
|
57
|
-
keywords << :excepted if legacy_excepted != NOT_GIVEN
|
58
|
-
end
|
59
|
-
|
44
|
+
def between_except(from:, to:, excepted:)
|
60
45
|
raise ArgumentError, 'From date, to date and excepted date must not be the same' if from == to && to == excepted
|
61
46
|
|
62
47
|
excepted = get_date_object(excepted)
|
@@ -66,27 +51,30 @@ module Faker
|
|
66
51
|
break date.to_date if date != excepted
|
67
52
|
end
|
68
53
|
end
|
69
|
-
# rubocop:enable Metrics/ParameterLists
|
70
54
|
|
71
55
|
##
|
72
56
|
# Produce a random date in the future (up to N days).
|
73
57
|
#
|
58
|
+
# @param from [Integer] The start of the usable forward date range.
|
74
59
|
# @param days [Integer] The maximum number of days to go into the future.
|
75
60
|
# @return [Date]
|
76
61
|
#
|
77
|
-
# @example
|
62
|
+
# @example if used with or without Rails (Active Support)
|
78
63
|
# Faker::Date.forward(days: 23) #=> #<Date: 2014-10-03>
|
79
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
|
+
#
|
80
71
|
# @faker.version 1.0.0
|
81
|
-
def forward(
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
85
76
|
|
86
|
-
from
|
87
|
-
to = ::Date.today + days
|
88
|
-
|
89
|
-
between(from: from, to: to).to_date
|
77
|
+
between(from: since, to: to).to_date
|
90
78
|
end
|
91
79
|
|
92
80
|
##
|
@@ -99,11 +87,7 @@ module Faker
|
|
99
87
|
# Faker::Date.backward(days: 14) #=> #<Date: 2019-09-12>
|
100
88
|
#
|
101
89
|
# @faker.version 1.0.0
|
102
|
-
def backward(
|
103
|
-
warn_for_deprecated_arguments do |keywords|
|
104
|
-
keywords << :days if legacy_days != NOT_GIVEN
|
105
|
-
end
|
106
|
-
|
90
|
+
def backward(days: 365)
|
107
91
|
from = ::Date.today - days
|
108
92
|
to = ::Date.today - 1
|
109
93
|
|
@@ -121,14 +105,7 @@ module Faker
|
|
121
105
|
# Faker::Date.birthday(min_age: 18, max_age: 65) #=> #<Date: 1986-03-28>
|
122
106
|
#
|
123
107
|
# @faker.version 1.4.3
|
124
|
-
def birthday(
|
125
|
-
warn_for_deprecated_arguments do |keywords|
|
126
|
-
keywords << :min_age if legacy_min_age != NOT_GIVEN
|
127
|
-
end
|
128
|
-
warn_for_deprecated_arguments do |keywords|
|
129
|
-
keywords << :max_age if legacy_max_age != NOT_GIVEN
|
130
|
-
end
|
131
|
-
|
108
|
+
def birthday(min_age: 18, max_age: 65)
|
132
109
|
t = ::Date.today
|
133
110
|
|
134
111
|
from = birthday_date(t, max_age)
|
@@ -161,6 +138,52 @@ module Faker
|
|
161
138
|
between(from: from, to: to).to_date
|
162
139
|
end
|
163
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
|
+
|
164
187
|
private
|
165
188
|
|
166
189
|
def birthday_date(date, age)
|
@@ -80,11 +80,7 @@ module Faker
|
|
80
80
|
# Faker::Demographic.height(unit: :imperial) #=> "6 ft, 2 in"
|
81
81
|
#
|
82
82
|
# @faker.version 1.7.3
|
83
|
-
def height(
|
84
|
-
warn_for_deprecated_arguments do |keywords|
|
85
|
-
keywords << :unit if legacy_unit != NOT_GIVEN
|
86
|
-
end
|
87
|
-
|
83
|
+
def height(unit: :metric)
|
88
84
|
case unit
|
89
85
|
when :imperial
|
90
86
|
inches = rand_in_range(57, 86)
|
@@ -23,16 +23,7 @@ module Faker
|
|
23
23
|
# date_of_birth: Date.parse("1986-10-24")) #=> "OCARR815246J91HT"
|
24
24
|
#
|
25
25
|
# @faker.version 1.9.2
|
26
|
-
|
27
|
-
def british_driving_licence(legacy_last_name = NOT_GIVEN, legacy_initials = NOT_GIVEN, legacy_gender = NOT_GIVEN, legacy_date_of_birth = NOT_GIVEN, last_name: Faker::Name.last_name, initials: Faker::Name.initials, gender: random_gender, date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65))
|
28
|
-
# rubocop:enable Metrics/ParameterLists
|
29
|
-
warn_for_deprecated_arguments do |keywords|
|
30
|
-
keywords << :last_name if legacy_last_name != NOT_GIVEN
|
31
|
-
keywords << :initials if legacy_initials != NOT_GIVEN
|
32
|
-
keywords << :gender if legacy_gender != NOT_GIVEN
|
33
|
-
keywords << :date_of_birth if legacy_date_of_birth != NOT_GIVEN
|
34
|
-
end
|
35
|
-
|
26
|
+
def british_driving_licence(last_name: Faker::Name.last_name, initials: Faker::Name.initials, gender: random_gender, date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65))
|
36
27
|
[
|
37
28
|
gb_licence_padding(last_name, 5),
|
38
29
|
gb_licence_year(date_of_birth, gender),
|
@@ -107,17 +98,28 @@ module Faker
|
|
107
98
|
end
|
108
99
|
|
109
100
|
def gb_licence_year(dob, gender)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
117
116
|
end
|
118
117
|
|
119
118
|
def gb_licence_checksum
|
120
|
-
|
119
|
+
generate(:string) do |g|
|
120
|
+
g.int
|
121
|
+
g.letter(ranges: ['A'..'Z'], length: 2)
|
122
|
+
end
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|