faker 3.0.0 → 3.5.2
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/CHANGELOG.md +598 -1
- data/README.md +203 -107
- data/lib/faker/books/lovecraft.rb +2 -3
- data/lib/faker/default/address.rb +2 -2
- data/lib/faker/default/alphanumeric.rb +1 -1
- data/lib/faker/default/chile_rut.rb +23 -17
- data/lib/faker/default/code.rb +65 -19
- data/lib/faker/default/company.rb +112 -5
- data/lib/faker/default/crypto.rb +13 -4
- data/lib/faker/default/date.rb +61 -5
- data/lib/faker/default/driving_licence.rb +19 -8
- data/lib/faker/default/drone.rb +1 -1
- data/lib/faker/default/finance.rb +2 -2
- data/lib/faker/default/food.rb +14 -1
- data/lib/faker/default/hipster.rb +2 -3
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +38 -24
- data/lib/faker/default/internet.rb +85 -78
- data/lib/faker/default/invoice.rb +4 -4
- data/lib/faker/default/json.rb +9 -4
- data/lib/faker/default/lorem.rb +24 -16
- data/lib/faker/default/marketing.rb +1 -1
- data/lib/faker/default/measurement.rb +8 -8
- data/lib/faker/default/{nhs.rb → national_health_service.rb} +8 -4
- data/lib/faker/default/number.rb +1 -1
- data/lib/faker/default/omniauth.rb +5 -5
- data/lib/faker/default/phone_number.rb +37 -18
- data/lib/faker/default/placeholdit.rb +1 -1
- data/lib/faker/default/south_africa.rb +3 -3
- data/lib/faker/{music/show.rb → default/theater.rb} +8 -8
- data/lib/faker/default/twitter.rb +4 -6
- data/lib/faker/default/types.rb +5 -6
- data/lib/faker/default/vehicle.rb +26 -36
- data/lib/faker/games/clash_of_clans.rb +1 -1
- data/lib/faker/games/dnd.rb +49 -7
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/heroes_of_the_storm.rb +0 -11
- data/lib/faker/games/minecraft.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/japanese_media/cowboy_bebop.rb +61 -0
- data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +10 -10
- data/lib/faker/locations/australia.rb +40 -38
- data/lib/faker/movies/avatar.rb +49 -0
- data/lib/faker/movies/star_wars.rb +1 -1
- data/lib/faker/movies/{room.rb → the_room.rb} +4 -4
- data/lib/faker/music/smashing_pumpkins.rb +64 -0
- data/lib/faker/quotes/quote.rb +13 -0
- data/lib/faker/sports/chess.rb +90 -0
- data/lib/faker/sports/sport.rb +9 -3
- 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/buffy.rb +0 -13
- data/lib/faker/tv_shows/dr_who.rb +0 -13
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/tv_shows/spongebob.rb +50 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +0 -13
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +20 -9
- data/lib/helpers/deprecator.rb +118 -0
- 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 -2
- data/lib/locales/da-DK.yml +529 -35
- data/lib/locales/de-AT.yml +3487 -27
- data/lib/locales/de-CH.yml +4359 -12
- data/lib/locales/de.yml +7182 -100
- data/lib/locales/ee.yml +0 -1
- data/lib/locales/en/address.yml +1826 -561
- data/lib/locales/en/airport.yml +381 -0
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/australia.yml +106 -105
- data/lib/locales/en/avatar.yml +31 -0
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/chess.yml +103 -0
- data/lib/locales/en/company.yml +1 -0
- data/lib/locales/en/cosmere.yml +1 -1
- data/lib/locales/en/cowboy_bebop.yml +163 -0
- data/lib/locales/en/dnd.yml +186 -1
- data/lib/locales/en/dog.yml +262 -7
- data/lib/locales/en/dota.yml +120 -67
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/finance.yml +4 -4
- data/lib/locales/en/food.yml +14 -1
- data/lib/locales/en/{fma_brotherhood.yml → fullmetal_alchemist_brotherhood.yml} +3 -3
- data/lib/locales/en/harry_potter.yml +1 -1
- data/lib/locales/en/heroes.yml +0 -0
- data/lib/locales/en/id_number.yml +1 -1
- data/lib/locales/en/internet.yml +3 -4
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/mitch_hedberg.yml +46 -0
- data/lib/locales/en/music.yml +25 -25
- data/lib/locales/en/opera.yml +1 -1
- data/lib/locales/en/phone_number.yml +78 -3
- data/lib/locales/en/restaurant.yml +1 -1
- data/lib/locales/en/smashing_pumpkins.yml +382 -0
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/spongebob.yml +489 -0
- data/lib/locales/en/star_wars.yml +1 -1
- 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/train_station.yml +280 -0
- data/lib/locales/en/vehicle.yml +1 -1
- data/lib/locales/en-AU.yml +718 -47
- data/lib/locales/en-CA.yml +373 -19
- 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 +392 -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 +4569 -4599
- data/lib/locales/es-MX.yml +1 -2
- data/lib/locales/es.yml +2 -3
- data/lib/locales/fi-FI.yml +1 -0
- data/lib/locales/fr/address.yml +761 -9
- data/lib/locales/fr/internet.yml +0 -1
- data/lib/locales/fr/name.yml +2 -1
- data/lib/locales/fr-CA.yml +2733 -44
- data/lib/locales/fr-CH.yml +1 -2
- data/lib/locales/fr.yml +3 -1
- 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/book.yml +492 -3
- data/lib/locales/ja/football.yml +115 -0
- data/lib/locales/ja/lorem.yml +1 -1
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ja/super_mario.yml +1 -1
- data/lib/locales/ja/touhou.yml +466 -0
- data/lib/locales/ko.yml +1361 -20
- data/lib/locales/lt.yml +297 -17
- data/lib/locales/lv.yml +0 -1
- data/lib/locales/mi-NZ.yml +2 -0
- data/lib/locales/nb-NO.yml +518 -29
- data/lib/locales/nl.yml +10 -2
- data/lib/locales/pl.yml +1 -2
- data/lib/locales/pt-BR.yml +8205 -664
- data/lib/locales/pt.yml +844 -45
- data/lib/locales/ru.yml +1353 -69
- data/lib/locales/sk.yml +4410 -43
- data/lib/locales/sv.yml +100 -0
- 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 +37 -156
- data/History.md +0 -176
- data/lib/faker/default/fillmurray.rb +0 -36
- data/lib/faker/default/lorem_pixel.rb +0 -64
data/lib/faker/default/code.rb
CHANGED
@@ -5,7 +5,7 @@ module Faker
|
|
5
5
|
flexible :code
|
6
6
|
class << self
|
7
7
|
##
|
8
|
-
# Produces a random NPI (National Provider
|
8
|
+
# Produces a random NPI (National Provider Identifier) code.
|
9
9
|
#
|
10
10
|
# @return [String]
|
11
11
|
#
|
@@ -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
|
##
|
@@ -156,6 +168,7 @@ module Faker
|
|
156
168
|
|
157
169
|
# Reporting body identifier
|
158
170
|
RBI = %w[01 10 30 33 35 44 45 49 50 51 52 53 54 86 91 98 99].freeze
|
171
|
+
private_constant :RBI
|
159
172
|
|
160
173
|
def generate_imei
|
161
174
|
str = Array.new(15, 0)
|
@@ -197,15 +210,29 @@ module Faker
|
|
197
210
|
end
|
198
211
|
|
199
212
|
def generate_base10_isbn
|
200
|
-
|
201
|
-
|
202
|
-
|
213
|
+
generate(:string) do |g|
|
214
|
+
g.int(name: :values, length: 9)
|
215
|
+
g.lit('-')
|
216
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
217
|
+
remainder = sum(values.to_s) { |value, offset| (offset + 1) * value.to_i } % 11
|
218
|
+
if remainder == 10
|
219
|
+
'X'
|
220
|
+
else
|
221
|
+
remainder.to_s
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
203
225
|
end
|
204
226
|
|
205
227
|
def generate_base13_isbn
|
206
|
-
|
207
|
-
|
208
|
-
|
228
|
+
generate(:string) do |g|
|
229
|
+
g.int(name: :values, length: 12)
|
230
|
+
g.lit('-')
|
231
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
232
|
+
remainder = sum(values.to_s) { |value, offset| offset.even? ? value.to_i : value.to_i * 3 } % 10
|
233
|
+
(10 - remainder) % 10
|
234
|
+
end
|
235
|
+
end
|
209
236
|
end
|
210
237
|
|
211
238
|
def sum(values)
|
@@ -215,23 +242,42 @@ module Faker
|
|
215
242
|
end
|
216
243
|
|
217
244
|
def generate_base8_ean
|
218
|
-
|
219
|
-
|
220
|
-
|
245
|
+
generate(:string) do |g|
|
246
|
+
g.int(name: :values, length: 7)
|
247
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
248
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
|
249
|
+
if check_digit == 10
|
250
|
+
0
|
251
|
+
else
|
252
|
+
check_digit
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
221
256
|
end
|
222
257
|
|
223
258
|
def generate_base13_ean
|
224
|
-
|
225
|
-
|
226
|
-
|
259
|
+
generate(:string) do |g|
|
260
|
+
g.int(name: :values, length: 12)
|
261
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
262
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
|
263
|
+
if check_digit == 10
|
264
|
+
0
|
265
|
+
else
|
266
|
+
check_digit
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
227
270
|
end
|
228
271
|
|
229
272
|
EAN_CHECK_DIGIT8 = [3, 1, 3, 1, 3, 1, 3].freeze
|
273
|
+
private_constant :EAN_CHECK_DIGIT8
|
274
|
+
|
230
275
|
EAN_CHECK_DIGIT13 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3].freeze
|
276
|
+
private_constant :EAN_CHECK_DIGIT13
|
231
277
|
|
232
278
|
def rut_verificator_digit(rut)
|
233
279
|
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(
|
280
|
+
(11 - total % 11).to_s.gsub('10', 'k').gsub('11', '0')
|
235
281
|
end
|
236
282
|
|
237
283
|
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
|
##
|
@@ -425,6 +464,61 @@ module Faker
|
|
425
464
|
fetch('company.sic_code')
|
426
465
|
end
|
427
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]])
|
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
|
+
|
428
522
|
private
|
429
523
|
|
430
524
|
# Mod11 functionality from https://github.com/badmanski/mod11/blob/master/lib/mod11.rb
|
@@ -554,7 +648,7 @@ module Faker
|
|
554
648
|
end
|
555
649
|
|
556
650
|
control = control.to_s[-1].to_i
|
557
|
-
control =
|
651
|
+
control = 10 - control unless control.zero?
|
558
652
|
|
559
653
|
%w[A B C D E F G H J U V].include?(organization_type) ? control : letters[control]
|
560
654
|
end
|
@@ -566,6 +660,19 @@ module Faker
|
|
566
660
|
|
567
661
|
result.to_s[0].to_i + result.to_s[1].to_i
|
568
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
|
569
676
|
end
|
570
677
|
end
|
571
678
|
end
|
data/lib/faker/default/crypto.rb
CHANGED
@@ -5,6 +5,15 @@ require 'openssl'
|
|
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
|
-
OpenSSL::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
|
-
OpenSSL::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,7 @@ module Faker
|
|
41
50
|
#
|
42
51
|
# @faker.version 1.6.4
|
43
52
|
def sha256
|
44
|
-
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters)
|
53
|
+
OpenSSL::Digest::SHA256.hexdigest(Lorem.characters(number: SHA256_MIN_NUMBER_OF_CHARACTERS))
|
45
54
|
end
|
46
55
|
|
47
56
|
##
|
@@ -54,7 +63,7 @@ module Faker
|
|
54
63
|
#
|
55
64
|
# @faker.version next
|
56
65
|
def sha512
|
57
|
-
OpenSSL::Digest::SHA512.hexdigest(Lorem.characters)
|
66
|
+
OpenSSL::Digest::SHA512.hexdigest(Lorem.characters(number: SHA512_MIN_NUMBER_OF_CHARACTERS))
|
58
67
|
end
|
59
68
|
end
|
60
69
|
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/drone.rb
CHANGED
@@ -97,11 +97,11 @@ module Faker
|
|
97
97
|
##
|
98
98
|
# Returns a random condominium fiscal code.
|
99
99
|
#
|
100
|
-
# @param country [String] Two capital letter country code to use for the
|
100
|
+
# @param country [String] Two capital letter country code to use for the condominium fiscal code number.
|
101
101
|
# @return [String]
|
102
102
|
#
|
103
103
|
# @example
|
104
|
-
# Faker::Finance.condominium_fiscal_code #=> "
|
104
|
+
# Faker::Finance.condominium_fiscal_code #=> "01234567890"
|
105
105
|
#
|
106
106
|
# @faker.version next
|
107
107
|
def condominium_fiscal_code(country: 'IT')
|
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
|
#
|
@@ -97,7 +110,7 @@ module Faker
|
|
97
110
|
end
|
98
111
|
|
99
112
|
##
|
100
|
-
# Retrieves metric
|
113
|
+
# Retrieves metric measurements
|
101
114
|
#
|
102
115
|
# @return [String]
|
103
116
|
#
|
@@ -39,10 +39,9 @@ module Faker
|
|
39
39
|
(supplemental ? translate('faker.lorem.words') : [])
|
40
40
|
)
|
41
41
|
word_list *= ((resolved_num / word_list.length) + 1)
|
42
|
+
words = sample(word_list, resolved_num)
|
43
|
+
return words if spaces_allowed
|
42
44
|
|
43
|
-
return shuffle(word_list)[0, resolved_num] if spaces_allowed
|
44
|
-
|
45
|
-
words = shuffle(word_list)[0, resolved_num]
|
46
45
|
words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
|
47
46
|
end
|
48
47
|
|