faker 2.20.0 → 3.2.1

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.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +346 -7
  3. data/History.md +1 -1
  4. data/README.md +193 -107
  5. data/lib/faker/blockchain/aeternity.rb +1 -1
  6. data/lib/faker/blockchain/ethereum.rb +1 -1
  7. data/lib/faker/blockchain/tezos.rb +1 -1
  8. data/lib/faker/books/dune.rb +2 -10
  9. data/lib/faker/books/lovecraft.rb +7 -38
  10. data/lib/faker/default/address.rb +5 -25
  11. data/lib/faker/default/alphanumeric.rb +2 -8
  12. data/lib/faker/default/app.rb +1 -10
  13. data/lib/faker/default/avatar.rb +1 -12
  14. data/lib/faker/default/bank.rb +9 -17
  15. data/lib/faker/default/boolean.rb +1 -4
  16. data/lib/faker/default/chile_rut.rb +25 -25
  17. data/lib/faker/default/code.rb +68 -39
  18. data/lib/faker/default/color.rb +77 -6
  19. data/lib/faker/default/commerce.rb +3 -17
  20. data/lib/faker/default/company.rb +50 -19
  21. data/lib/faker/default/crypto_coin.rb +3 -15
  22. data/lib/faker/default/date.rb +65 -42
  23. data/lib/faker/default/demographic.rb +1 -5
  24. data/lib/faker/default/driving_licence.rb +20 -19
  25. data/lib/faker/default/drone.rb +1 -1
  26. data/lib/faker/default/file.rb +5 -24
  27. data/lib/faker/default/finance.rb +17 -7
  28. data/lib/faker/default/food.rb +14 -1
  29. data/lib/faker/default/hipster.rb +6 -45
  30. data/lib/faker/default/html.rb +230 -0
  31. data/lib/faker/default/id_number.rb +125 -14
  32. data/lib/faker/default/internet.rb +116 -111
  33. data/lib/faker/default/invoice.rb +4 -17
  34. data/lib/faker/default/json.rb +2 -20
  35. data/lib/faker/default/lorem.rb +25 -74
  36. data/lib/faker/default/lorem_flickr.rb +4 -32
  37. data/lib/faker/default/markdown.rb +6 -11
  38. data/lib/faker/default/marketing.rb +1 -1
  39. data/lib/faker/default/measurement.rb +16 -48
  40. data/lib/faker/default/name.rb +1 -5
  41. data/lib/faker/default/nhs.rb +2 -6
  42. data/lib/faker/default/number.rb +10 -55
  43. data/lib/faker/default/omniauth.rb +6 -40
  44. data/lib/faker/default/phone_number.rb +2 -6
  45. data/lib/faker/default/placeholdit.rb +1 -12
  46. data/lib/faker/default/relationship.rb +1 -5
  47. data/lib/faker/default/release notes.md +59 -0
  48. data/lib/faker/default/source.rb +3 -16
  49. data/lib/faker/default/string.rb +1 -5
  50. data/lib/faker/default/stripe.rb +4 -20
  51. data/lib/faker/default/time.rb +4 -32
  52. data/lib/faker/default/twitter.rb +7 -23
  53. data/lib/faker/default/types.rb +7 -28
  54. data/lib/faker/default/vehicle.rb +40 -51
  55. data/lib/faker/default/vulnerability_identifier.rb +23 -0
  56. data/lib/faker/default/world_cup.rb +2 -11
  57. data/lib/faker/games/clash_of_clans.rb +1 -1
  58. data/lib/faker/games/dnd.rb +49 -7
  59. data/lib/faker/games/dota.rb +1 -5
  60. data/lib/faker/games/final_fantasy_xiv.rb +73 -0
  61. data/lib/faker/games/minecraft.rb +1 -1
  62. data/lib/faker/games/myst.rb +1 -1
  63. data/lib/faker/games/tarkov.rb +205 -0
  64. data/lib/faker/japanese_media/cowboy_bebop.rb +61 -0
  65. data/lib/faker/japanese_media/kamen_rider.rb +2 -2
  66. data/lib/faker/japanese_media/one_piece.rb +1 -1
  67. data/lib/faker/movies/avatar.rb +49 -0
  68. data/lib/faker/movies/hackers.rb +48 -0
  69. data/lib/faker/movies/star_wars.rb +1 -5
  70. data/lib/faker/movies/tron.rb +161 -0
  71. data/lib/faker/quotes/quote.rb +13 -0
  72. data/lib/faker/sports/chess.rb +90 -0
  73. data/lib/faker/sports/mountaineering.rb +22 -0
  74. data/lib/faker/sports/sport.rb +116 -0
  75. data/lib/faker/travel/airport.rb +43 -0
  76. data/lib/faker/travel/train_station.rb +54 -0
  77. data/lib/faker/tv_shows/archer.rb +51 -0
  78. data/lib/faker/tv_shows/south_park.rb +15 -0
  79. data/lib/faker/tv_shows/spongebob.rb +50 -0
  80. data/lib/faker/version.rb +1 -1
  81. data/lib/faker.rb +26 -67
  82. data/lib/helpers/base58.rb +1 -1
  83. data/lib/helpers/positional_generator.rb +480 -0
  84. data/lib/helpers/unique_generator.rb +13 -11
  85. data/lib/locales/README.md +18 -2
  86. data/lib/locales/ar.yml +1 -0
  87. data/lib/locales/bg.yml +1 -1
  88. data/lib/locales/da-DK.yml +1 -1
  89. data/lib/locales/de-AT.yml +1 -2
  90. data/lib/locales/de-CH.yml +4336 -12
  91. data/lib/locales/de.yml +1 -1
  92. data/lib/locales/en/airport.yml +381 -0
  93. data/lib/locales/en/archer.yml +75 -0
  94. data/lib/locales/en/australia.yml +3 -4
  95. data/lib/locales/en/avatar.yml +31 -0
  96. data/lib/locales/en/chess.yml +103 -0
  97. data/lib/locales/en/company.yml +1 -0
  98. data/lib/locales/en/computer.yml +23 -4
  99. data/lib/locales/en/cowboy_bebop.yml +163 -0
  100. data/lib/locales/en/dnd.yml +186 -1
  101. data/lib/locales/en/dota.yml +113 -0
  102. data/lib/locales/en/file.yml +9 -1
  103. data/lib/locales/en/final_fantasy_xiv.yml +754 -0
  104. data/lib/locales/en/finance.yml +3 -1
  105. data/lib/locales/en/food.yml +12 -0
  106. data/lib/locales/en/game.yml +0 -1
  107. data/lib/locales/en/hackers.yml +53 -0
  108. data/lib/locales/en/heroes.yml +2 -2
  109. data/lib/locales/en/internet.yml +32 -0
  110. data/lib/locales/en/minecraft.yml +4 -4
  111. data/lib/locales/en/mitch_hedberg.yml +46 -0
  112. data/lib/locales/en/mountaineering.yml +14 -0
  113. data/lib/locales/en/movie.yml +2 -1
  114. data/lib/locales/en/naruto.yml +2 -3
  115. data/lib/locales/en/one_piece.yml +1 -1
  116. data/lib/locales/en/opera.yml +2 -2
  117. data/lib/locales/en/overwatch.yml +5 -7
  118. data/lib/locales/en/source.yml +5 -0
  119. data/lib/locales/en/south_park.yml +360 -2
  120. data/lib/locales/en/spongebob.yml +489 -0
  121. data/lib/locales/en/sport.yml +130 -0
  122. data/lib/locales/en/star_wars.yml +1 -1
  123. data/lib/locales/en/tarkov.yml +593 -0
  124. data/lib/locales/en/train_station.yml +280 -0
  125. data/lib/locales/en/tron.yml +227 -0
  126. data/lib/locales/en/vehicle.yml +2809 -75
  127. data/lib/locales/en-AU.yml +2 -2
  128. data/lib/locales/en-CA.yml +2 -1
  129. data/lib/locales/en-GB.yml +2 -1
  130. data/lib/locales/en-MS.yml +1 -0
  131. data/lib/locales/en-NG.yml +1 -0
  132. data/lib/locales/en-NZ.yml +1 -0
  133. data/lib/locales/en-PAK.yml +1 -0
  134. data/lib/locales/en-SG.yml +1 -0
  135. data/lib/locales/en-UG.yml +1 -0
  136. data/lib/locales/en-US.yml +1 -1
  137. data/lib/locales/en-ZA.yml +1 -1
  138. data/lib/locales/en-au-ocker.yml +2 -0
  139. data/lib/locales/es-AR.yml +3 -2
  140. data/lib/locales/es-MX.yml +1 -1
  141. data/lib/locales/es.yml +2 -2
  142. data/lib/locales/fi-FI.yml +3 -1
  143. data/lib/locales/fr/address.yml +0 -1
  144. data/lib/locales/fr/adjective.yml +266 -0
  145. data/lib/locales/fr/ancient.yml +141 -0
  146. data/lib/locales/fr/name.yml +2 -1
  147. data/lib/locales/fr-CA.yml +1 -1
  148. data/lib/locales/fr-CH.yml +1 -1
  149. data/lib/locales/hy.yml +2 -1
  150. data/lib/locales/it.yml +1 -0
  151. data/lib/locales/ja/adjective.yml +148 -0
  152. data/lib/locales/ja/dog.yml +1 -0
  153. data/lib/locales/ja/emotion.yml +51 -0
  154. data/lib/locales/ja/naruto.yml +230 -0
  155. data/lib/locales/ja/relationship.yml +10 -0
  156. data/lib/locales/ja/sport.yml +130 -0
  157. data/lib/locales/ja/super_mario.yml +1 -1
  158. data/lib/locales/ko.yml +1 -0
  159. data/lib/locales/lt.yml +0 -1
  160. data/lib/locales/mi-NZ.yml +2 -0
  161. data/lib/locales/nb-NO.yml +1 -0
  162. data/lib/locales/nl.yml +1 -0
  163. data/lib/locales/pl.yml +2 -2
  164. data/lib/locales/pt-BR.yml +1 -0
  165. data/lib/locales/pt.yml +1 -1
  166. data/lib/locales/ru.yml +1 -0
  167. data/lib/locales/sk.yml +1 -0
  168. data/lib/locales/sv.yml +1 -0
  169. data/lib/locales/th.yml +76 -76
  170. data/lib/locales/tr.yml +1 -0
  171. data/lib/locales/uk.yml +3 -0
  172. data/lib/locales/vi.yml +1 -0
  173. data/lib/locales/zh-CN.yml +1 -0
  174. data/lib/locales/zh-TW.yml +1 -0
  175. metadata +46 -127
  176. data/lib/faker/default/fillmurray.rb +0 -45
  177. data/lib/faker/default/lorem_pixel.rb +0 -70
  178. /data/lib/faker/default/{faker_adjective.rb → adjective.rb} +0 -0
@@ -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(legacy_length = NOT_GIVEN, length: 9)
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
- regexify(%r{\d{4}/\d{4,10}/07})
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
- regexify(%r{(CK\d{2}|\d{4})/\d{4,10}/23})
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
- regexify(%r{\d{4}/\d{4,10}/06})
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
- regexify(%r{IT\d{2,4}/\d{2,10}})
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(legacy_formatted = NOT_GIVEN, formatted: false)
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
@@ -459,7 +490,7 @@ module Faker
459
490
  def luhn_algorithm(number)
460
491
  multiplications = []
461
492
 
462
- number.to_s.reverse.split(//).each_with_index do |digit, i|
493
+ number.to_s.reverse.chars.each_with_index do |digit, i|
463
494
  multiplications << if i.even?
464
495
  digit.to_i * 2
465
496
  else
@@ -553,7 +584,7 @@ module Faker
553
584
  def spanish_cif_control_digit(organization_type, code)
554
585
  letters = %w[J A B C D E F G H I]
555
586
 
556
- control = code.split('').each_with_index.inject(0) do |sum, (value, index)|
587
+ control = code.chars.each_with_index.inject(0) do |sum, (value, index)|
557
588
  if (index + 1).even?
558
589
  sum + value.to_i
559
590
  else
@@ -562,7 +593,7 @@ module Faker
562
593
  end
563
594
 
564
595
  control = control.to_s[-1].to_i
565
- control = control.zero? ? control : 10 - control
596
+ control = 10 - control unless control.zero?
566
597
 
567
598
  %w[A B C D E F G H J U V].include?(organization_type) ? control : letters[control]
568
599
  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(legacy_coin = NOT_GIVEN, coin: coin_array)
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(legacy_coin = NOT_GIVEN, coin: coin_array)
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(legacy_coin = NOT_GIVEN, coin: coin_array)
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
 
@@ -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(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from:, to:)
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(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_excepted = NOT_GIVEN, from:, to:, excepted:)
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(legacy_days = NOT_GIVEN, days: 365)
82
- warn_for_deprecated_arguments do |keywords|
83
- keywords << :days if legacy_days != NOT_GIVEN
84
- end
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 = ::Date.today + 1
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(legacy_days = NOT_GIVEN, days: 365)
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(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, min_age: 18, max_age: 65)
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(legacy_unit = NOT_GIVEN, unit: :metric)
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)
@@ -6,8 +6,6 @@ module Faker
6
6
  NI_CHANCE = 0.03 # NI Pop is about 3% of total UK population
7
7
 
8
8
  class << self
9
- # rubocop:disable Metrics/ParameterLists
10
-
11
9
  ##
12
10
  # Produces a random British driving licence number.
13
11
  #
@@ -25,14 +23,7 @@ module Faker
25
23
  # date_of_birth: Date.parse("1986-10-24")) #=> "OCARR815246J91HT"
26
24
  #
27
25
  # @faker.version 1.9.2
28
- 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))
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),
@@ -40,7 +31,6 @@ module Faker
40
31
  gb_licence_checksum
41
32
  ].join
42
33
  end
43
- # rubocop:enable Metrics/ParameterLists
44
34
 
45
35
  ##
46
36
  # Produces a random Northern Irish licence number.
@@ -108,17 +98,28 @@ module Faker
108
98
  end
109
99
 
110
100
  def gb_licence_year(dob, gender)
111
- decade = (dob.year / 10) % 10
112
- year = dob.year % 10
113
- month = gender == :female ? dob.month + 50 : dob.month
114
- # Rubocop's preferred formatting is pretty gory
115
- # rubocop:disable Style/FormatString
116
- "#{decade}#{'%02d' % month}#{'%02d' % dob.day}#{year}"
117
- # rubocop:enable Style/FormatString
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
118
116
  end
119
117
 
120
118
  def gb_licence_checksum
121
- regexify(/[0-9][A-Z][A-Z]/)
119
+ generate(:string) do |g|
120
+ g.int
121
+ g.letter(ranges: ['A'..'Z'], length: 2)
122
+ end
122
123
  end
123
124
  end
124
125
  end
@@ -147,7 +147,7 @@ module Faker
147
147
  end
148
148
 
149
149
  ##
150
- # Returns operating temprature for drone in Fahrenheit
150
+ # Returns operating temperature for drone in Fahrenheit
151
151
  #
152
152
  # @return [String]
153
153
  #
@@ -3,8 +3,6 @@
3
3
  module Faker
4
4
  class File < Base
5
5
  class << self
6
- # rubocop:disable Metrics/ParameterLists
7
-
8
6
  ##
9
7
  # Produces a random directory name.
10
8
  #
@@ -20,13 +18,7 @@ module Faker
20
18
  # Faker::File.dir(segment_count: 3, root: nil, directory_separator: '\\') #=> "aut-ullam\\quia_quisquam\\ut-eos"
21
19
  #
22
20
  # @faker.version 1.6.4
23
- def dir(legacy_segment_count = NOT_GIVEN, legacy_root = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, segment_count: 3, root: nil, directory_separator: ::File::Separator)
24
- warn_for_deprecated_arguments do |keywords|
25
- keywords << :segment_count if legacy_segment_count != NOT_GIVEN
26
- keywords << :root if legacy_root != NOT_GIVEN
27
- keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
28
- end
29
-
21
+ def dir(segment_count: 3, root: nil, directory_separator: ::File::Separator)
30
22
  Array
31
23
  .new(segment_count) { Faker::Internet.slug }
32
24
  .unshift(root)
@@ -34,7 +26,6 @@ module Faker
34
26
  .join(directory_separator)
35
27
  .squeeze(directory_separator)
36
28
  end
37
- # rubocop:enable Metrics/ParameterLists
38
29
 
39
30
  ##
40
31
  # Produces a random file extension.
@@ -57,13 +48,11 @@ module Faker
57
48
  # @example
58
49
  # Faker::File.mime_type #=> "application/pdf"
59
50
  #
60
- # @faker.version 1.6.4
61
- def mime_type
62
- fetch('file.mime_type')
51
+ # @faker.version next
52
+ def mime_type(media_type: nil)
53
+ media_type ? fetch("file.mime_type.#{media_type}") : sample(sample(translate('faker.file.mime_type').values))
63
54
  end
64
55
 
65
- # rubocop:disable Metrics/ParameterLists
66
-
67
56
  ##
68
57
  # Produces a random file name.
69
58
  #
@@ -80,21 +69,13 @@ module Faker
80
69
  # Faker::File.file_name(dir: 'foo/bar', name: 'baz', ext: 'mp3', directory_separator: '\\') #=> "foo/bar\\baz.mp3"
81
70
  #
82
71
  # @faker.version 1.6.4
83
- def file_name(legacy_dir = NOT_GIVEN, legacy_name = NOT_GIVEN, legacy_ext = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
84
- warn_for_deprecated_arguments do |keywords|
85
- keywords << :dir if legacy_dir != NOT_GIVEN
86
- keywords << :name if legacy_name != NOT_GIVEN
87
- keywords << :ext if legacy_ext != NOT_GIVEN
88
- keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
89
- end
90
-
72
+ def file_name(dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
91
73
  dir ||= dir(segment_count: 1)
92
74
  name ||= Faker::Lorem.word.downcase
93
75
  ext ||= extension
94
76
 
95
77
  [dir, name].join(directory_separator) + ".#{ext}"
96
78
  end
97
- # rubocop:enable Metrics/ParameterLists
98
79
  end
99
80
  end
100
81
  end
@@ -28,9 +28,9 @@ module Faker
28
28
 
29
29
  # calculate the luhn checksum digit
30
30
  multiplier = 1
31
- luhn_sum = template.gsub(/[^0-9]/, '').split('').reverse.map(&:to_i).inject(0) do |sum, digit|
31
+ luhn_sum = template.gsub(/[^0-9]/, '').chars.reverse.map(&:to_i).inject(0) do |sum, digit|
32
32
  multiplier = (multiplier == 2 ? 1 : 2)
33
- sum + (digit * multiplier).to_s.split('').map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
33
+ sum + (digit * multiplier).to_s.chars.map(&:to_i).inject(0) { |digit_sum, cur| digit_sum + cur }
34
34
  end
35
35
 
36
36
  # the sum plus whatever the last digit is must be a multiple of 10. So, the
@@ -52,11 +52,7 @@ module Faker
52
52
  # Faker::Finance.vat_number('ZA') #=> "ZA79494416181"
53
53
  #
54
54
  # @faker.version 1.9.2
55
- def vat_number(legacy_country = NOT_GIVEN, country: 'BR')
56
- warn_for_deprecated_arguments do |keywords|
57
- keywords << :country if legacy_country != NOT_GIVEN
58
- end
59
-
55
+ def vat_number(country: 'BR')
60
56
  numerify(fetch("finance.vat_number.#{country}"))
61
57
  rescue I18n::MissingTranslationData
62
58
  raise ArgumentError, "Could not find vat number for #{country}"
@@ -97,6 +93,20 @@ module Faker
97
93
  def stock_market
98
94
  fetch('finance.stock_market')
99
95
  end
96
+
97
+ ##
98
+ # Returns a random condominium fiscal code.
99
+ #
100
+ # @param country [String] Two capital letter country code to use for the vat number.
101
+ # @return [String]
102
+ #
103
+ # @example
104
+ # Faker::Finance.condominium_fiscal_code #=> "012345678"
105
+ #
106
+ # @faker.version next
107
+ def condominium_fiscal_code(country: 'IT')
108
+ numerify(fetch("finance.condominium_fiscal_code.#{country}"))
109
+ end
100
110
  end
101
111
  end
102
112
  end
@@ -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 mesurements
113
+ # Retrieves metric measurements
101
114
  #
102
115
  # @return [String]
103
116
  #