faker 2.20.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +184 -7
  3. data/History.md +1 -1
  4. data/README.md +15 -11
  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/{faker_adjective.rb → adjective.rb} +0 -0
  12. data/lib/faker/default/alphanumeric.rb +2 -8
  13. data/lib/faker/default/app.rb +1 -10
  14. data/lib/faker/default/avatar.rb +1 -12
  15. data/lib/faker/default/bank.rb +9 -17
  16. data/lib/faker/default/boolean.rb +1 -4
  17. data/lib/faker/default/chile_rut.rb +8 -14
  18. data/lib/faker/default/code.rb +10 -23
  19. data/lib/faker/default/color.rb +77 -6
  20. data/lib/faker/default/commerce.rb +3 -17
  21. data/lib/faker/default/company.rb +6 -14
  22. data/lib/faker/default/crypto_coin.rb +3 -15
  23. data/lib/faker/default/date.rb +5 -38
  24. data/lib/faker/default/demographic.rb +1 -5
  25. data/lib/faker/default/driving_licence.rb +1 -11
  26. data/lib/faker/default/file.rb +5 -24
  27. data/lib/faker/default/fillmurray.rb +1 -10
  28. data/lib/faker/default/finance.rb +17 -7
  29. data/lib/faker/default/hipster.rb +6 -45
  30. data/lib/faker/default/id_number.rb +108 -11
  31. data/lib/faker/default/internet.rb +34 -71
  32. data/lib/faker/default/invoice.rb +3 -16
  33. data/lib/faker/default/json.rb +2 -20
  34. data/lib/faker/default/lorem.rb +9 -66
  35. data/lib/faker/default/lorem_flickr.rb +4 -32
  36. data/lib/faker/default/lorem_pixel.rb +4 -10
  37. data/lib/faker/default/markdown.rb +6 -11
  38. data/lib/faker/default/measurement.rb +8 -40
  39. data/lib/faker/default/name.rb +1 -5
  40. data/lib/faker/default/nhs.rb +2 -6
  41. data/lib/faker/default/number.rb +10 -55
  42. data/lib/faker/default/omniauth.rb +5 -39
  43. data/lib/faker/default/phone_number.rb +1 -5
  44. data/lib/faker/default/placeholdit.rb +1 -12
  45. data/lib/faker/default/relationship.rb +1 -5
  46. data/lib/faker/default/source.rb +3 -16
  47. data/lib/faker/default/string.rb +1 -5
  48. data/lib/faker/default/stripe.rb +4 -20
  49. data/lib/faker/default/time.rb +4 -32
  50. data/lib/faker/default/twitter.rb +3 -17
  51. data/lib/faker/default/types.rb +5 -27
  52. data/lib/faker/default/vehicle.rb +21 -21
  53. data/lib/faker/default/vulnerability_identifier.rb +23 -0
  54. data/lib/faker/default/world_cup.rb +2 -11
  55. data/lib/faker/games/dota.rb +1 -5
  56. data/lib/faker/games/tarkov.rb +205 -0
  57. data/lib/faker/japanese_media/kamen_rider.rb +2 -2
  58. data/lib/faker/japanese_media/one_piece.rb +1 -1
  59. data/lib/faker/movies/hackers.rb +48 -0
  60. data/lib/faker/movies/star_wars.rb +1 -5
  61. data/lib/faker/movies/tron.rb +161 -0
  62. data/lib/faker/sports/mountaineering.rb +22 -0
  63. data/lib/faker/sports/sport.rb +110 -0
  64. data/lib/faker/version.rb +1 -1
  65. data/lib/faker.rb +15 -63
  66. data/lib/helpers/base58.rb +1 -1
  67. data/lib/helpers/unique_generator.rb +13 -11
  68. data/lib/locales/en/australia.yml +3 -4
  69. data/lib/locales/en/computer.yml +23 -4
  70. data/lib/locales/en/dota.yml +113 -0
  71. data/lib/locales/en/file.yml +9 -1
  72. data/lib/locales/en/finance.yml +3 -1
  73. data/lib/locales/en/game.yml +0 -1
  74. data/lib/locales/en/hackers.yml +53 -0
  75. data/lib/locales/en/heroes.yml +2 -2
  76. data/lib/locales/en/internet.yml +29 -0
  77. data/lib/locales/en/mountaineering.yml +14 -0
  78. data/lib/locales/en/movie.yml +2 -1
  79. data/lib/locales/en/naruto.yml +2 -3
  80. data/lib/locales/en/one_piece.yml +1 -1
  81. data/lib/locales/en/opera.yml +1 -1
  82. data/lib/locales/en/overwatch.yml +5 -7
  83. data/lib/locales/en/source.yml +5 -0
  84. data/lib/locales/en/sport.yml +130 -0
  85. data/lib/locales/en/tarkov.yml +593 -0
  86. data/lib/locales/en/tron.yml +227 -0
  87. data/lib/locales/en/vehicle.yml +2809 -75
  88. data/lib/locales/en-AU.yml +1 -1
  89. data/lib/locales/en-CA.yml +1 -0
  90. data/lib/locales/es-AR.yml +2 -2
  91. data/lib/locales/fi-FI.yml +2 -1
  92. data/lib/locales/fr/adjective.yml +266 -0
  93. data/lib/locales/fr/ancient.yml +141 -0
  94. data/lib/locales/hy.yml +1 -1
  95. data/lib/locales/ja/adjective.yml +148 -0
  96. data/lib/locales/ja/dog.yml +1 -0
  97. data/lib/locales/ja/emotion.yml +51 -0
  98. data/lib/locales/ja/naruto.yml +230 -0
  99. data/lib/locales/ja/relationship.yml +10 -0
  100. data/lib/locales/pl.yml +1 -1
  101. data/lib/locales/th.yml +76 -76
  102. metadata +65 -25
@@ -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
@@ -3,8 +3,6 @@
3
3
  module Faker
4
4
  class Fillmurray < Base
5
5
  class << self
6
- # rubocop:disable Metrics/ParameterLists
7
-
8
6
  ##
9
7
  # Produces the URL of an image from Fill Murray, a site which hosts
10
8
  # exclusively photographs of actor Bill Murray.
@@ -26,20 +24,13 @@ module Faker
26
24
  # #=> "https://fillmurray.com/200/400"
27
25
  #
28
26
  # @faker.version 1.7.1
29
- def image(legacy_grayscale = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_height = NOT_GIVEN, grayscale: false, width: 200, height: 200)
30
- warn_for_deprecated_arguments do |keywords|
31
- keywords << :grayscale if legacy_grayscale != NOT_GIVEN
32
- keywords << :width if legacy_width != NOT_GIVEN
33
- keywords << :height if legacy_height != NOT_GIVEN
34
- end
35
-
27
+ def image(grayscale: false, width: 200, height: 200)
36
28
  raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
37
29
  raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
38
30
  raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)
39
31
 
40
32
  "https://www.fillmurray.com#{'/g' if grayscale == true}/#{width}/#{height}"
41
33
  end
42
- # rubocop:enable Metrics/ParameterLists
43
34
  end
44
35
  end
45
36
  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
@@ -17,8 +17,6 @@ module Faker
17
17
  random_word =~ /\s/ ? word : random_word
18
18
  end
19
19
 
20
- # rubocop:disable Metrics/ParameterLists
21
-
22
20
  ##
23
21
  # Produces a random hipster word.
24
22
  #
@@ -34,13 +32,7 @@ module Faker
34
32
  # Faker::Hipster.words(number: 4, supplemental: true, spaces_allowed: true) #=> ["qui", "magni", "craft beer", "est"]
35
33
  #
36
34
  # @faker.version 1.6.0
37
- def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false)
38
- warn_for_deprecated_arguments do |keywords|
39
- keywords << :number if legacy_number != NOT_GIVEN
40
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
41
- keywords << :spaces_allowed if legacy_spaces_allowed != NOT_GIVEN
42
- end
43
-
35
+ def words(number: 3, supplemental: false, spaces_allowed: false)
44
36
  resolved_num = resolve(number)
45
37
  word_list = (
46
38
  translate('faker.hipster.words') +
@@ -73,16 +65,9 @@ module Faker
73
65
  # Faker::Hipster.sentence(word_count: 3, supplemental: true, random_words_to_add: 0, open_compounds_allowed: false) #=> "Dreamcatcher umami fixie."
74
66
  #
75
67
  # @faker.version 1.6.0
76
- def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true)
77
- warn_for_deprecated_arguments do |keywords|
78
- keywords << :word_count if legacy_word_count != NOT_GIVEN
79
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
80
- keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN
81
- end
82
-
68
+ def sentence(word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true)
83
69
  "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: open_compounds_allowed).join(' ').capitalize}."
84
70
  end
85
- # rubocop:enable Metrics/ParameterLists
86
71
 
87
72
  ##
88
73
  # Produces random hipster sentences.
@@ -97,12 +82,7 @@ module Faker
97
82
  # Faker::Hipster.sentences(number: 1, supplemental: true) #=> ["Et sustainable optio aesthetic et."]
98
83
  #
99
84
  # @faker.version 1.6.0
100
- def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
101
- warn_for_deprecated_arguments do |keywords|
102
- keywords << :number if legacy_number != NOT_GIVEN
103
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
104
- end
105
-
85
+ def sentences(number: 3, supplemental: false)
106
86
  [].tap do |sentences|
107
87
  1.upto(resolve(number)) do
108
88
  sentences << sentence(word_count: 3, supplemental: supplemental)
@@ -110,8 +90,6 @@ module Faker
110
90
  end
111
91
  end
112
92
 
113
- # rubocop:disable Metrics/ParameterLists
114
-
115
93
  ##
116
94
  # Produces a random hipster paragraph.
117
95
  #
@@ -128,16 +106,9 @@ module Faker
128
106
  # Faker::Hipster.paragraph(sentence_count: 2, supplemental: true, random_sentences_to_add: 4) #=> "Deep v gluten-free unde waistcoat aperiam migas voluptas dolorum. Aut drinking illo sustainable sapiente. Direct trade fanny pack kale chips ennui semiotics."
129
107
  #
130
108
  # @faker.version 1.6.0
131
- def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
132
- warn_for_deprecated_arguments do |keywords|
133
- keywords << :sentence_count if legacy_sentence_count != NOT_GIVEN
134
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
135
- keywords << :random_sentences_to_add if legacy_random_sentences_to_add != NOT_GIVEN
136
- end
137
-
109
+ def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
138
110
  sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
139
111
  end
140
- # rubocop:enable Metrics/ParameterLists
141
112
 
142
113
  ##
143
114
  # Produces random hipster paragraphs.
@@ -152,12 +123,7 @@ module Faker
152
123
  # Faker::Hipster.paragraphs(number: 1, supplemental: true) #=> ["Quae direct trade pbr&b quo taxidermy autem loko. Umami quas ratione migas cardigan sriracha minima. Tenetur perspiciatis pickled sed eum doloribus truffaut. Excepturi dreamcatcher meditation."]
153
124
  #
154
125
  # @faker.version 1.6.0
155
- def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
156
- warn_for_deprecated_arguments do |keywords|
157
- keywords << :number if legacy_number != NOT_GIVEN
158
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
159
- end
160
-
126
+ def paragraphs(number: 3, supplemental: false)
161
127
  [].tap do |paragraphs|
162
128
  1.upto(resolve(number)) do
163
129
  paragraphs << paragraph(sentence_count: 3, supplemental: supplemental)
@@ -177,12 +143,7 @@ module Faker
177
143
  # Faker::Hipster.paragraph_by_chars(characters: 256, supplemental: false) #=> "Hella kogi blog narwhal sartorial selfies mustache schlitz. Bespoke normcore kitsch cred hella fixie. Park aesthetic fixie migas twee. Cliche mustache brunch tumblr fixie godard. Drinking pop-up synth hoodie dreamcatcher typewriter. Kitsch biodiesel green."
178
144
  #
179
145
  # @faker.version 1.6.0
180
- def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false)
181
- warn_for_deprecated_arguments do |keywords|
182
- keywords << :characters if legacy_characters != NOT_GIVEN
183
- keywords << :supplemental if legacy_supplemental != NOT_GIVEN
184
- end
185
-
146
+ def paragraph_by_chars(characters: 256, supplemental: false)
186
147
  paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
187
148
 
188
149
  paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters
@@ -146,11 +146,7 @@ module Faker
146
146
  # Faker::IDNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21"
147
147
  #
148
148
  # @faker.version 1.9.2
149
- def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
150
- warn_for_deprecated_arguments do |keywords|
151
- keywords << :formatted if legacy_formatted != NOT_GIVEN
152
- end
153
-
149
+ def brazilian_citizen_number(formatted: false)
154
150
  digits = Faker::Number.leading_zero_number(digits: 9) until digits&.match(/(\d)((?!\1)\d)+/)
155
151
  first_digit = brazilian_citizen_number_checksum_digit(digits)
156
152
  second_digit = brazilian_citizen_number_checksum_digit(digits + first_digit)
@@ -171,11 +167,7 @@ module Faker
171
167
  # Faker::IDNumber.brazilian_id(formatted: true) #=> "49.305.402-9"
172
168
  #
173
169
  # @faker.version 2.1.2
174
- def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
175
- warn_for_deprecated_arguments do |keywords|
176
- keywords << :formatted if legacy_formatted != NOT_GIVEN
177
- end
178
-
170
+ def brazilian_id(formatted: false)
179
171
  digits = Faker::Number.between(to: BRAZILIAN_ID_FROM, from: BRAZILIAN_ID_TO).to_s
180
172
  check_digit = brazilian_id_checksum_digit(digits)
181
173
  number = [digits, check_digit].join
@@ -219,6 +211,72 @@ module Faker
219
211
  "#{prefix}#{digits}#{checksum_digit}"
220
212
  end
221
213
 
214
+ ##
215
+ # Produces a random Danish ID Number (CPR number).
216
+ # CPR number is 10 digits. Digit 1-6 is the birthdate (format "DDMMYY").
217
+ # Digit 7-10 is a sequence number.
218
+ # Digit 7 digit is a control digit that determines the century of birth.
219
+ # Digit 10 reveals the gender: # even is female, odd is male.
220
+ #
221
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
222
+ # @param birthday [Date] Specifies the birthday for the id number.
223
+ # @param gender [Symbol] Specifies the gender for the id number. Must be one :male or :female if present.
224
+ # @return [String]
225
+ #
226
+ # @example
227
+ # Faker::IDNumber.danish_id_number #=> "0503909980"
228
+ # Faker::IDNumber.danish_id_number(formatted: true) #=> "050390-9980"
229
+ # Faker::IDNumber.danish_id_number(birthday: Date.new(1990, 3, 5)) #=> "0503909980"
230
+ # Faker::IDNumber.danish_id_number(gender: :female) #=> "0503909980"
231
+ #
232
+ # @faker.version next
233
+ def danish_id_number(formatted: false, birthday: Faker::Date.birthday, gender: nil)
234
+ valid_control_digits = danish_control_digits(birthday)
235
+ control_digit = sample(valid_control_digits)
236
+ digits = (0..9).to_a
237
+ gender = gender.to_sym if gender.respond_to?(:to_sym)
238
+ gender_digit = case gender
239
+ when nil
240
+ sample(digits)
241
+ when :male
242
+ sample(digits.select(&:odd?))
243
+ when :female
244
+ sample(digits.select(&:even?))
245
+ else
246
+ raise ArgumentError, "Invalid gender #{gender}. Must be one of male, female, or be omitted."
247
+ end
248
+
249
+ [
250
+ birthday.strftime('%d%m%y'),
251
+ formatted ? '-' : '',
252
+ control_digit,
253
+ Faker::Number.number(digits: 2),
254
+ gender_digit
255
+ ].join
256
+ end
257
+
258
+ ##
259
+ # Produces a random French social security number (INSEE number).
260
+ #
261
+ # @return [String]
262
+ #
263
+ # @example
264
+ # Faker::IDNumber.french_insee_number #=> "53290236-H"
265
+ #
266
+ # @faker.version next
267
+ def french_insee_number
268
+ num = [
269
+ [1, 2].sample(random: Faker::Config.random), # gender
270
+ Faker::Number.between(from: 0, to: 99).to_s.rjust(2, '0'), # year of birth
271
+ Faker::Number.between(from: 1, to: 12).to_s.rjust(2, '0'), # month of birth
272
+ Faker::Number.number(digits: 5), # place of birth
273
+ Faker::Number.number(digits: 3) # order number
274
+ ].join
275
+ mod = num.to_i % 97
276
+ check = (97 - mod).to_s.rjust(2, '0')
277
+ "#{num}#{check}"
278
+ end
279
+
222
280
  private
223
281
 
224
282
  def croatian_id_checksum_digit(digits)
@@ -266,7 +324,7 @@ module Faker
266
324
  .with_index { |_, i| (i + 1).odd? }
267
325
 
268
326
  sum_of_odd_digits = odd_digits_without_last_character.map(&:to_i).reduce(:+)
269
- even_digits_times_two = (even_digits.join('').to_i * 2).to_s
327
+ even_digits_times_two = (even_digits.join.to_i * 2).to_s
270
328
  sum_of_even_digits = even_digits_times_two.chars.map(&:to_i).reduce(:+)
271
329
 
272
330
  total_sum = sum_of_odd_digits + sum_of_even_digits
@@ -305,6 +363,45 @@ module Faker
305
363
  digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
306
364
  end
307
365
 
366
+ def danish_control_digits(birthday)
367
+ year = birthday.year
368
+ century = year.to_s.slice(0, 2).to_i
369
+ year_digits = year.to_s.slice(2, 2).to_i
370
+ error_message = "Invalid birthday: #{birthday}. Danish CPR numbers are only distributed to persons born between 1858 and 2057."
371
+
372
+ case century
373
+ when 18
374
+ # If 5, 6, 7 or 8 and the year numbers are greater than or equal to 58, you were born in 18XX.
375
+ case year_digits
376
+ when 58..99
377
+ [5, 6, 7, 8]
378
+ else
379
+ raise ArgumentError, error_message
380
+ end
381
+ when 19
382
+ # If 0, 1, 2 or 3, you are always born in 19XX.
383
+ # If 4 or 9, you are born in 19XX if the year digits are greater than 36.
384
+
385
+ case year_digits
386
+ when 0..36
387
+ [0, 1, 2, 3]
388
+ else # 37..99
389
+ [0, 1, 2, 3, 4, 9]
390
+ end
391
+ else
392
+ # If 4, 5, 6, 7, 8 or 9 and the year digits are less than or equal to 36, you were born in 20XX.
393
+ # 5, 6, 7 and 8 are not distributed to persons, with year digits from and including 37 to and including 57.
394
+ case year_digits
395
+ when 0..36
396
+ [4, 5, 6, 7, 8, 9]
397
+ when 37..57
398
+ [5, 6, 7, 8]
399
+ else
400
+ raise ArgumentError, error_message
401
+ end
402
+ end
403
+ end
404
+
308
405
  def _translate(key)
309
406
  parse("id_number.#{key}")
310
407
  end
@@ -29,12 +29,7 @@ module Faker
29
29
  # Faker::Internet.email(name: 'smith') #=> "smith@faker.com"
30
30
  # Faker::Internet.email(name: 'sam smith', separators: ['-']) #=> "sam-smith@faker.com"
31
31
  # Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: 'gmail') #=> "sam-smith@gmail.com"
32
- def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil, domain: nil)
33
- warn_for_deprecated_arguments do |keywords|
34
- keywords << :name if legacy_name != NOT_GIVEN
35
- keywords << :separators if legacy_separators != NOT_GIVEN
36
- end
37
-
32
+ def email(name: nil, separators: nil, domain: nil)
38
33
  local_part = if separators
39
34
  username(specifier: name, separators: separators)
40
35
  else
@@ -55,11 +50,7 @@ module Faker
55
50
  # @example
56
51
  # Faker::Internet.free_email #=> "samsmith@gmail.com"
57
52
  # Faker::Internet.free_email(name: 'smith') #=> "smith@yahoo.com"
58
- def free_email(legacy_name = NOT_GIVEN, name: nil)
59
- warn_for_deprecated_arguments do |keywords|
60
- keywords << :name if legacy_name != NOT_GIVEN
61
- end
62
-
53
+ def free_email(name: nil)
63
54
  construct_email(
64
55
  sanitize_email_local_part(username(specifier: name)),
65
56
  fetch('internet.free_email')
@@ -76,11 +67,7 @@ module Faker
76
67
  # @example
77
68
  # Faker::Internet.safe_email #=> "samsmith@example.com"
78
69
  # Faker::Internet.safe_email(name: 'smith') #=> "smith@example.net"
79
- def safe_email(legacy_name = NOT_GIVEN, name: nil)
80
- warn_for_deprecated_arguments do |keywords|
81
- keywords << :name if legacy_name != NOT_GIVEN
82
- end
83
-
70
+ def safe_email(name: nil)
84
71
  construct_email(
85
72
  sanitize_email_local_part(username(specifier: name)),
86
73
  "example.#{sample(%w[org com net])}"
@@ -100,12 +87,7 @@ module Faker
100
87
  # Faker::Internet.username(specifier: 5..10) #=> "morris"
101
88
  # Faker::Internet.username(specifier: 5..10) #=> "berryberry"
102
89
  # Faker::Internet.username(specifier: 20, separators: ['-']) #=> "nikki_sawaynnikki_saway"
103
- def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
104
- warn_for_deprecated_arguments do |keywords|
105
- keywords << :specifier if legacy_specifier != NOT_GIVEN
106
- keywords << :separators if legacy_separators != NOT_GIVEN
107
- end
108
-
90
+ def username(specifier: nil, separators: %w[. _])
109
91
  with_locale(:en) do
110
92
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
111
93
 
@@ -142,8 +124,6 @@ module Faker
142
124
  end
143
125
  end
144
126
 
145
- # rubocop:disable Metrics/ParameterLists
146
-
147
127
  ##
148
128
  # Produces a randomized string of characters suitable for passwords
149
129
  #
@@ -166,13 +146,8 @@ module Faker
166
146
  # Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true, special_characters: true) #=> "*%NkOnJsH4"
167
147
  #
168
148
  # @faker.version 2.1.3
169
- def password(legacy_min_length = NOT_GIVEN, legacy_max_length = NOT_GIVEN, legacy_mix_case = NOT_GIVEN, legacy_special_characters = NOT_GIVEN, min_length: 8, max_length: 16, mix_case: true, special_characters: false)
170
- warn_for_deprecated_arguments do |keywords|
171
- keywords << :min_length if legacy_min_length != NOT_GIVEN
172
- keywords << :max_length if legacy_max_length != NOT_GIVEN
173
- keywords << :mix_case if legacy_mix_case != NOT_GIVEN
174
- keywords << :special_characters if legacy_special_characters != NOT_GIVEN
175
- end
149
+ def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
150
+ raise ArgumentError, 'Password of length 1 can not have both mixed case and special characters' if min_length <= 1 && mix_case && special_characters
176
151
 
177
152
  min_alpha = mix_case && min_length > 1 ? 2 : 0
178
153
  temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
@@ -200,9 +175,10 @@ module Faker
200
175
  end
201
176
  end
202
177
 
178
+ temp[rand(temp.size - 1)] = Lorem.characters(number: 1, min_alpha: 1).upcase if mix_case && special_characters && !temp.match(/[A-z]+/)
179
+
203
180
  temp
204
181
  end
205
- # rubocop:enable Metrics/ParameterLists
206
182
 
207
183
  ##
208
184
  # Returns the domain name
@@ -217,11 +193,7 @@ module Faker
217
193
  # Faker::Internet.domain_name(subdomain: true) #=> "test.faker.io"
218
194
  # Faker::Internet.domain_name(subdomain: true, domain: 'example') #=> "faker.example.com"
219
195
  # Faker::Internet.domain_name(domain: 'faker') #=> "faker.org"
220
- def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false, domain: nil)
221
- warn_for_deprecated_arguments do |keywords|
222
- keywords << :subdomain if legacy_subdomain != NOT_GIVEN
223
- end
224
-
196
+ def domain_name(subdomain: false, domain: nil)
225
197
  with_locale(:en) do
226
198
  if domain
227
199
  domain
@@ -250,11 +222,7 @@ module Faker
250
222
  # Faker::Internet.fix_umlauts #=> ""
251
223
  # Faker::Internet.fix_umlauts(string: 'faker') #=> "faker"
252
224
  # Faker::Internet.fix_umlauts(string: 'faküer') #=> "fakueer"
253
- def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
254
- warn_for_deprecated_arguments do |keywords|
255
- keywords << :string if legacy_string != NOT_GIVEN
256
- end
257
-
225
+ def fix_umlauts(string: '')
258
226
  Char.fix_umlauts(string)
259
227
  end
260
228
 
@@ -266,7 +234,7 @@ module Faker
266
234
  # @example
267
235
  # Faker::Internet.domain_word #=> "senger"
268
236
  def domain_word
269
- with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
237
+ with_locale(:en) { Char.prepare(Company.name.split.first) }
270
238
  end
271
239
 
272
240
  ## Returns the domain suffix e.g. com, org, co, biz, info etc.
@@ -290,11 +258,7 @@ module Faker
290
258
  # Faker::Internet.mac_address(prefix: 'a') #=> "0a:91:ce:24:89:3b"
291
259
  # Faker::Internet.mac_address(prefix: 'aa') #=> "aa:38:a0:3e:e8:41"
292
260
  # Faker::Internet.mac_address(prefix: 'aa:44') #=> "aa:44:30:88:6e:95"
293
- def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
294
- warn_for_deprecated_arguments do |keywords|
295
- keywords << :prefix if legacy_prefix != NOT_GIVEN
296
- end
297
-
261
+ def mac_address(prefix: '')
298
262
  prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
299
263
  address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
300
264
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
@@ -436,8 +400,6 @@ module Faker
436
400
  "#{ip_v6_address}/#{rand(1..127)}"
437
401
  end
438
402
 
439
- # rubocop:disable Metrics/ParameterLists
440
-
441
403
  ##
442
404
  # Returns URL
443
405
  #
@@ -452,16 +414,9 @@ module Faker
452
414
  # Faker::Internet.url(host: 'faker') #=> "http://faker/shad"
453
415
  # Faker::Internet.url(host: 'faker', path: '/fake_test_path') #=> "http://faker/fake_test_path"
454
416
  # Faker::Internet.url(host: 'faker', path: '/fake_test_path', scheme: 'https') #=> "https://faker/fake_test_path"
455
- def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
456
- warn_for_deprecated_arguments do |keywords|
457
- keywords << :host if legacy_host != NOT_GIVEN
458
- keywords << :path if legacy_path != NOT_GIVEN
459
- keywords << :scheme if legacy_scheme != NOT_GIVEN
460
- end
461
-
417
+ def url(host: domain_name, path: "/#{username}", scheme: 'http')
462
418
  "#{scheme}://#{host}#{path}"
463
419
  end
464
- # rubocop:enable Metrics/ParameterLists
465
420
 
466
421
  ##
467
422
  # Returns unique string in URL
@@ -476,12 +431,7 @@ module Faker
476
431
  # Faker::Internet.slug(words: 'test, faker') #=> "test-faker"
477
432
  # Faker::Internet.slug(words: 'test. faker') #=> "test-faker"
478
433
  # Faker::Internet.slug(words: 'test. faker', glue: '$') #=> "test$faker"
479
- def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
480
- warn_for_deprecated_arguments do |keywords|
481
- keywords << :words if legacy_words != NOT_GIVEN
482
- keywords << :glue if legacy_glue != NOT_GIVEN
483
- end
484
-
434
+ def slug(words: nil, glue: nil)
485
435
  glue ||= sample(%w[- _])
486
436
  return words.delete(',.').gsub(' ', glue).downcase unless words.nil?
487
437
 
@@ -511,16 +461,29 @@ module Faker
511
461
  # Faker::Internet.user_agent(vendor: 'chrome') #=> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
512
462
  # Faker::Internet.user_agent(vendor: 'safari') #=> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"
513
463
  # Faker::Internet.user_agent(vendor: 'faker') #=> "Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285"
514
- def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
515
- warn_for_deprecated_arguments do |keywords|
516
- keywords << :vendor if legacy_vendor != NOT_GIVEN
517
- end
518
-
464
+ def user_agent(vendor: nil)
519
465
  agent_hash = translate('faker.internet.user_agent')
520
466
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
521
467
  sample(agents)
522
468
  end
523
469
 
470
+ ##
471
+ # Generate Web Crawler's user agents
472
+ #
473
+ # @return [String]
474
+ #
475
+ # @param vendor [String] Name of vendor, supported vendors are googlebot, bingbot, duckduckbot, baiduspider, yandexbot
476
+ #
477
+ # @example
478
+ # Faker::Internet.bot_user_agent #=> "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
479
+ # Faker::Internet.bot_user_agent(vendor: 'googlebot') #=> "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/99.0.4844.84 Safari/537.36"
480
+ # Faker::Internet.bot_user_agent(vendor: 'bingbot') #=> "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/86.0.4240.68 Safari/537.36 Edg/86.0.622.31"
481
+ def bot_user_agent(vendor: nil)
482
+ agent_hash = translate('faker.internet.bot_user_agent')
483
+ agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
484
+ sample(agents)
485
+ end
486
+
524
487
  ##
525
488
  # Generated universally unique identifier
526
489
  #
@@ -592,10 +555,10 @@ module Faker
592
555
  Array('0'..'9'),
593
556
  Array('A'..'Z'),
594
557
  Array('a'..'z'),
595
- "!#$%&'*+-/=?^_`{|}~.".split(//)
558
+ "!#$%&'*+-/=?^_`{|}~.".chars
596
559
  ].flatten
597
560
 
598
- local_part.split(//).map do |char|
561
+ local_part.chars.map do |char|
599
562
  char_range.include?(char) ? char : '#'
600
563
  end.join
601
564
  end
@@ -17,12 +17,7 @@ module Faker
17
17
  # Faker::Finance.amount_between(0, 10) #=> 4.33
18
18
  #
19
19
  # @faker.version 1.9.0
20
- def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0)
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
-
20
+ def amount_between(from: 0, to: 0)
26
21
  Faker::Base.rand_in_range(from, to).round(2)
27
22
  end
28
23
 
@@ -36,11 +31,7 @@ module Faker
36
31
  # Faker::Invoice.creditor_reference #=> "RF34118592570724925498"
37
32
  #
38
33
  # @faker.version 1.9.0
39
- def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
40
- warn_for_deprecated_arguments do |keywords|
41
- keywords << :ref if legacy_ref != NOT_GIVEN
42
- end
43
-
34
+ def creditor_reference(ref: '')
44
35
  ref = reference if ref.empty?
45
36
 
46
37
  "RF#{iban_checksum('RF', ref)}#{ref}"
@@ -56,11 +47,7 @@ module Faker
56
47
  # Faker::Invoice.reference #=> "45656646957845"
57
48
  #
58
49
  # @faker.version 1.9.0
59
- def reference(legacy_ref = NOT_GIVEN, ref: '')
60
- warn_for_deprecated_arguments do |keywords|
61
- keywords << :ref if legacy_ref != NOT_GIVEN
62
- end
63
-
50
+ def reference(ref: '')
64
51
  pattern = fetch('invoice.reference.pattern')
65
52
 
66
53
  ref = Base.regexify(/#{pattern}/) if ref.empty?