faker 1.9.6 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +386 -6
  3. data/README.md +12 -5
  4. data/lib/faker.rb +56 -1
  5. data/lib/faker/blockchain/aeternity.rb +70 -0
  6. data/lib/faker/blockchain/bitcoin.rb +26 -0
  7. data/lib/faker/blockchain/ethereum.rb +10 -0
  8. data/lib/faker/blockchain/tezos.rb +62 -6
  9. data/lib/faker/books/book.rb +36 -0
  10. data/lib/faker/books/culture_series.rb +49 -0
  11. data/lib/faker/books/dune.rb +66 -5
  12. data/lib/faker/books/lovecraft.rb +221 -18
  13. data/lib/faker/creature/animal.rb +10 -1
  14. data/lib/faker/creature/cat.rb +28 -1
  15. data/lib/faker/creature/dog.rb +73 -1
  16. data/lib/faker/creature/horse.rb +19 -1
  17. data/lib/faker/default/address.rb +25 -5
  18. data/lib/faker/default/alphanumeric.rb +58 -9
  19. data/lib/faker/default/app.rb +55 -1
  20. data/lib/faker/default/appliance.rb +18 -0
  21. data/lib/faker/default/artist.rb +9 -0
  22. data/lib/faker/default/avatar.rb +43 -1
  23. data/lib/faker/default/bank.rb +10 -2
  24. data/lib/faker/default/boolean.rb +16 -1
  25. data/lib/faker/default/cannabis.rb +4 -0
  26. data/lib/faker/default/chile_rut.rb +13 -3
  27. data/lib/faker/default/chuck_norris.rb +1 -1
  28. data/lib/faker/default/code.rb +18 -5
  29. data/lib/faker/default/commerce.rb +18 -4
  30. data/lib/faker/default/company.rb +11 -3
  31. data/lib/faker/default/crypto_coin.rb +21 -4
  32. data/lib/faker/default/date.rb +122 -9
  33. data/lib/faker/default/demographic.rb +5 -1
  34. data/lib/faker/default/dessert.rb +27 -0
  35. data/lib/faker/default/device.rb +56 -2
  36. data/lib/faker/default/driving_licence.rb +13 -7
  37. data/lib/faker/default/educator.rb +0 -3
  38. data/lib/faker/default/electrical_components.rb +27 -0
  39. data/lib/faker/default/file.rb +20 -3
  40. data/lib/faker/default/fillmurray.rb +10 -2
  41. data/lib/faker/default/finance.rb +5 -1
  42. data/lib/faker/default/gender.rb +18 -0
  43. data/lib/faker/default/greek_philosophers.rb +18 -0
  44. data/lib/faker/default/hacker.rb +59 -1
  45. data/lib/faker/default/hipster.rb +55 -16
  46. data/lib/faker/default/house.rb +18 -0
  47. data/lib/faker/default/id_number.rb +85 -11
  48. data/lib/faker/default/industry_segments.rb +36 -0
  49. data/lib/faker/default/internet.rb +107 -22
  50. data/lib/faker/default/invoice.rb +16 -3
  51. data/lib/faker/default/json.rb +19 -2
  52. data/lib/faker/default/lorem.rb +91 -20
  53. data/lib/faker/default/lorem_flickr.rb +38 -5
  54. data/lib/faker/default/lorem_pixel.rb +10 -1
  55. data/lib/faker/default/markdown.rb +12 -7
  56. data/lib/faker/default/marketing.rb +9 -0
  57. data/lib/faker/default/measurement.rb +40 -8
  58. data/lib/faker/default/military.rb +45 -0
  59. data/lib/faker/default/name.rb +6 -4
  60. data/lib/faker/default/nation.rb +48 -5
  61. data/lib/faker/default/nato_phonetic_alphabet.rb +9 -0
  62. data/lib/faker/default/nhs.rb +11 -7
  63. data/lib/faker/default/number.rb +202 -30
  64. data/lib/faker/default/omniauth.rb +98 -15
  65. data/lib/faker/default/phone_number.rb +5 -1
  66. data/lib/faker/default/placeholdit.rb +11 -1
  67. data/lib/faker/default/programming_language.rb +18 -0
  68. data/lib/faker/default/relationship.rb +5 -1
  69. data/lib/faker/default/restaurant.rb +54 -2
  70. data/lib/faker/default/science.rb +27 -0
  71. data/lib/faker/default/source.rb +59 -3
  72. data/lib/faker/default/south_africa.rb +1 -1
  73. data/lib/faker/default/space.rb +2 -2
  74. data/lib/faker/default/string.rb +5 -1
  75. data/lib/faker/default/stripe.rb +20 -4
  76. data/lib/faker/default/subscription.rb +45 -0
  77. data/lib/faker/default/superhero.rb +45 -0
  78. data/lib/faker/default/time.rb +133 -8
  79. data/lib/faker/default/twitter.rb +62 -48
  80. data/lib/faker/default/types.rb +29 -7
  81. data/lib/faker/default/vehicle.rb +19 -6
  82. data/lib/faker/default/world_cup.rb +61 -2
  83. data/lib/faker/games/dota.rb +53 -2
  84. data/lib/faker/games/elder_scrolls.rb +73 -1
  85. data/lib/faker/games/fallout.rb +38 -1
  86. data/lib/faker/games/game.rb +27 -0
  87. data/lib/faker/games/half_life.rb +28 -1
  88. data/lib/faker/games/heroes.rb +28 -1
  89. data/lib/faker/games/heroes_of_the_storm.rb +37 -1
  90. data/lib/faker/games/league_of_legends.rb +55 -1
  91. data/lib/faker/games/myst.rb +46 -1
  92. data/lib/faker/games/overwatch.rb +28 -1
  93. data/lib/faker/games/pokemon.rb +28 -1
  94. data/lib/faker/games/sonic_the_hedgehog.rb +28 -1
  95. data/lib/faker/games/super_smash_bros.rb +19 -1
  96. data/lib/faker/games/witcher.rb +55 -1
  97. data/lib/faker/games/world_of_warcraft.rb +19 -1
  98. data/lib/faker/games/zelda.rb +38 -2
  99. data/lib/faker/japanese_media/dragon_ball.rb +10 -1
  100. data/lib/faker/japanese_media/one_piece.rb +55 -1
  101. data/lib/faker/japanese_media/sword_art_online.rb +37 -1
  102. data/lib/faker/movies/back_to_the_future.rb +29 -1
  103. data/lib/faker/movies/ghostbusters.rb +29 -1
  104. data/lib/faker/movies/harry_potter.rb +55 -1
  105. data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +70 -1
  106. data/lib/faker/movies/hobbit.rb +38 -1
  107. data/lib/faker/movies/lebowski.rb +28 -1
  108. data/lib/faker/movies/lord_of_the_rings.rb +29 -1
  109. data/lib/faker/movies/movie.rb +9 -0
  110. data/lib/faker/movies/princess_bride.rb +20 -1
  111. data/lib/faker/movies/star_wars.rb +101 -5
  112. data/lib/faker/movies/v_for_vendetta.rb +30 -1
  113. data/lib/faker/music/grateful_dead.rb +18 -0
  114. data/lib/faker/music/phish.rb +9 -0
  115. data/lib/faker/music/rock_band.rb +9 -0
  116. data/lib/faker/music/umphreys_mcgee.rb +9 -0
  117. data/lib/faker/sports/basketball.rb +36 -0
  118. data/lib/faker/sports/football.rb +45 -0
  119. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +10 -1
  120. data/lib/faker/tv_shows/bojack_horseman.rb +29 -1
  121. data/lib/faker/tv_shows/breaking_bad.rb +19 -1
  122. data/lib/faker/tv_shows/buffy.rb +46 -1
  123. data/lib/faker/tv_shows/community.rb +20 -1
  124. data/lib/faker/tv_shows/dr_who.rb +79 -3
  125. data/lib/faker/tv_shows/dumb_and_dumber.rb +29 -1
  126. data/lib/faker/tv_shows/family_guy.rb +29 -1
  127. data/lib/faker/tv_shows/friends.rb +28 -1
  128. data/lib/faker/tv_shows/game_of_thrones.rb +47 -1
  129. data/lib/faker/tv_shows/hey_arnold.rb +28 -1
  130. data/lib/faker/tv_shows/how_i_met_your_mother.rb +38 -1
  131. data/lib/faker/tv_shows/michael_scott.rb +14 -1
  132. data/lib/faker/tv_shows/new_girl.rb +20 -1
  133. data/lib/faker/tv_shows/parks_and_rec.rb +19 -1
  134. data/lib/faker/tv_shows/rick_and_morty.rb +29 -1
  135. data/lib/faker/tv_shows/ru_paul.rb +19 -1
  136. data/lib/faker/tv_shows/seinfeld.rb +29 -1
  137. data/lib/faker/tv_shows/silicon_valley.rb +76 -1
  138. data/lib/faker/tv_shows/simpsons.rb +29 -1
  139. data/lib/faker/tv_shows/south_park.rb +20 -1
  140. data/lib/faker/tv_shows/star_trek.rb +37 -1
  141. data/lib/faker/tv_shows/stargate.rb +29 -1
  142. data/lib/faker/tv_shows/stranger_things.rb +20 -1
  143. data/lib/faker/tv_shows/the_expanse.rb +37 -1
  144. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +29 -1
  145. data/lib/faker/tv_shows/the_it_crowd.rb +38 -1
  146. data/lib/faker/tv_shows/the_thick_of_it.rb +29 -1
  147. data/lib/faker/tv_shows/twin_peaks.rb +29 -1
  148. data/lib/faker/tv_shows/venture_bros.rb +39 -1
  149. data/lib/faker/version.rb +1 -1
  150. data/lib/locales/en-CA.yml +2 -1
  151. data/lib/locales/en-IND.yml +1 -1
  152. data/lib/locales/en-TH.yml +360 -0
  153. data/lib/locales/en.yml +4 -1
  154. data/lib/locales/en/address.yml +1 -4
  155. data/lib/locales/en/animal.yml +2 -2
  156. data/lib/locales/en/cannabis.yml +1 -0
  157. data/lib/locales/en/color.yml +1 -1
  158. data/lib/locales/en/dr_who.yml +1 -1
  159. data/lib/locales/en/science.yml +1 -1
  160. data/lib/locales/en/space.yml +1 -1
  161. data/lib/locales/en/super_smash_bros.yml +5 -0
  162. data/lib/locales/fr-CA.yml +1 -1
  163. data/lib/locales/ja.yml +12 -9
  164. data/lib/locales/th.yml +380 -0
  165. data/lib/locales/vi.yml +1 -1
  166. metadata +44 -27
  167. data/lib/faker/default/creature.rb +0 -6
  168. data/lib/faker/default/games.rb +0 -6
  169. data/lib/faker/default/japanese_media.rb +0 -6
  170. data/lib/faker/default/movies.rb +0 -6
  171. data/lib/faker/default/tv_shows.rb +0 -6
  172. data/lib/faker/deprecate/unreleased/football.rb +0 -35
  173. data/lib/faker/deprecate/unreleased/movies/grateful_dead.rb +0 -22
@@ -12,6 +12,11 @@ module Faker
12
12
  ].freeze
13
13
  ZA_RACE_DIGIT = '8'
14
14
  ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
15
+ BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/.freeze
16
+ BRAZILIAN_ID_FROM = 10_000_000
17
+ BRAZILIAN_ID_TO = 99_999_999
18
+
19
+ CHILEAN_MODULO = 11
15
20
 
16
21
  class << self
17
22
  def valid
@@ -29,7 +34,7 @@ module Faker
29
34
  end
30
35
 
31
36
  def spanish_citizen_number
32
- num = Faker::Number.number(8)
37
+ num = Faker::Number.number(digits: 8)
33
38
  mod = num.to_i % 23
34
39
  check = CHECKS[mod]
35
40
  "#{num}-#{check}"
@@ -37,7 +42,7 @@ module Faker
37
42
 
38
43
  def spanish_foreign_citizen_number
39
44
  code = 'XYZ'
40
- digits = Faker::Number.number(7)
45
+ digits = Faker::Number.number(digits: 7)
41
46
  prefix = code[rand(code.length)]
42
47
  prefix_val = 'XYZ'.index(prefix).to_s
43
48
  mod = "#{prefix_val}#{digits}".to_i % 23
@@ -48,7 +53,7 @@ module Faker
48
53
  def valid_south_african_id_number
49
54
  id_number = [
50
55
  Faker::Date.birthday.strftime('%y%m%d'),
51
- Faker::Number.number(4),
56
+ Faker::Number.number(digits: 4),
52
57
  ZA_CITIZENSHIP_DIGITS.sample(random: Faker::Config.random),
53
58
  ZA_RACE_DIGIT
54
59
  ].join
@@ -60,14 +65,14 @@ module Faker
60
65
 
61
66
  def invalid_south_african_id_number
62
67
  invalid_date_of_birth = [
63
- Faker::Number.number(2),
64
- Faker::Number.between(13, 99),
65
- Faker::Number.between(32, 99)
68
+ Faker::Number.number(digits: 2),
69
+ Faker::Number.between(from: 13, to: 99),
70
+ Faker::Number.between(from: 32, to: 99)
66
71
  ].map(&:to_s).join
67
72
 
68
73
  id_number = [
69
74
  invalid_date_of_birth,
70
- Faker::Number.number(4),
75
+ Faker::Number.number(digits: 4),
71
76
  ZA_CITIZENSHIP_DIGITS.sample(random: Faker::Config.random),
72
77
  ZA_RACE_DIGIT
73
78
  ].join
@@ -75,16 +80,62 @@ module Faker
75
80
  [id_number, south_african_id_checksum_digit(id_number)].join
76
81
  end
77
82
 
78
- def brazilian_citizen_number(formatted: false)
79
- digits = Faker::Number.leading_zero_number(9) until digits&.match(/(\d)((?!\1)\d)+/)
83
+ def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
84
+ warn_for_deprecated_arguments do |keywords|
85
+ keywords << :formatted if legacy_formatted != NOT_GIVEN
86
+ end
87
+
88
+ digits = Faker::Number.leading_zero_number(digits: 9) until digits&.match(/(\d)((?!\1)\d)+/)
80
89
  first_digit = brazilian_citizen_number_checksum_digit(digits)
81
90
  second_digit = brazilian_citizen_number_checksum_digit(digits + first_digit)
82
91
  number = [digits, first_digit, second_digit].join
83
92
  formatted ? format('%s.%s.%s-%s', *number.scan(/\d{2,3}/).flatten) : number
84
93
  end
85
94
 
95
+ alias brazilian_cpf brazilian_citizen_number
96
+
97
+ def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
98
+ warn_for_deprecated_arguments do |keywords|
99
+ keywords << :formatted if legacy_formatted != NOT_GIVEN
100
+ end
101
+
102
+ digits = Faker::Number.between(to: BRAZILIAN_ID_FROM, from: BRAZILIAN_ID_TO).to_s
103
+ check_digit = brazilian_id_checksum_digit(digits)
104
+ number = [digits, check_digit].join
105
+ formatted ? format('%s.%s.%s-%s', *number.scan(BRAZILIAN_ID_FORMAT).flatten) : number
106
+ end
107
+
108
+ alias brazilian_rg brazilian_id
109
+
110
+ def chilean_id
111
+ digits = Faker::Number.number(digits: 8)
112
+ verification_code = chilean_verification_code(digits)
113
+
114
+ digits.to_s + '-' + verification_code.to_s
115
+ end
116
+
86
117
  private
87
118
 
119
+ def chilean_verification_code(digits)
120
+ # First digit is multiplied by 3, second by 2, and so on
121
+ multiplication_rule = [3, 2, 7, 6, 5, 4, 3, 2]
122
+ digits_splitted = digits.to_s.chars.map(&:to_i)
123
+
124
+ sum = digits_splitted.map.with_index { |digit, index| digit * multiplication_rule[index] }.reduce(:+)
125
+
126
+ modulo = sum.modulo(CHILEAN_MODULO)
127
+ difference = CHILEAN_MODULO - modulo
128
+
129
+ case difference
130
+ when 0..9
131
+ difference
132
+ when 10
133
+ 'K'
134
+ when 11
135
+ 0
136
+ end
137
+ end
138
+
88
139
  def south_african_id_checksum_digit(id_number)
89
140
  value_parts = id_number.chars
90
141
  even_digits = value_parts
@@ -104,13 +155,36 @@ module Faker
104
155
  end
105
156
 
106
157
  def brazilian_citizen_number_checksum_digit(digits)
107
- digit_sum = digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
158
+ checksum = brazilian_document_checksum(digits)
159
+ brazilian_document_digit(checksum)
160
+ end
161
+
162
+ def brazilian_id_checksum_digit(digits)
163
+ checksum = brazilian_document_checksum(digits)
164
+ brazilian_document_digit(checksum, id: true)
165
+ end
166
+
167
+ def brazilian_document_checksum(digits)
168
+ digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
108
169
  acc + digit.to_i * (digits.size + 1 - i)
109
170
  end * 10
110
- remainder = digit_sum % 11
171
+ end
172
+
173
+ def brazilian_document_digit(checksum, id = false)
174
+ remainder = checksum % 11
175
+ id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
176
+ end
177
+
178
+ def brazilian_citizen_number_digit(remainder)
111
179
  remainder == 10 ? '0' : remainder.to_s
112
180
  end
113
181
 
182
+ def brazilian_id_digit(remainder)
183
+ subtraction = 11 - remainder.to_i
184
+ digits = { 10 => 'X', 11 => '0' }
185
+ digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
186
+ end
187
+
114
188
  def _translate(key)
115
189
  parse("id_number.#{key}")
116
190
  end
@@ -5,18 +5,54 @@ module Faker
5
5
  flexible :industry_segments
6
6
 
7
7
  class << self
8
+ ##
9
+ # Produces the name of an industry.
10
+ #
11
+ # @return [String]
12
+ #
13
+ # @example
14
+ # Faker::IndustrySegments.industry #=> "Basic Materials"
15
+ #
16
+ # @faker.version 1.9.2
8
17
  def industry
9
18
  fetch('industry_segments.industry')
10
19
  end
11
20
 
21
+ ##
22
+ # Produces the name of a super-sector of an industry.
23
+ #
24
+ # @return [String]
25
+ #
26
+ # @example
27
+ # Faker::IndustrySegments.super_sector #=> "Basic Resources"
28
+ #
29
+ # @faker.version 1.9.2
12
30
  def super_sector
13
31
  fetch('industry_segments.super_sector')
14
32
  end
15
33
 
34
+ ##
35
+ # Produces the name of a sector of an industry.
36
+ #
37
+ # @return [String]
38
+ #
39
+ # @example
40
+ # Faker::IndustrySegments.sector #=> "Industrial Metals & Mining"
41
+ #
42
+ # @faker.version 1.9.2
16
43
  def sector
17
44
  fetch('industry_segments.sector')
18
45
  end
19
46
 
47
+ ##
48
+ # Produces the name of a subsector of an industry.
49
+ #
50
+ # @return [String]
51
+ #
52
+ # @example
53
+ # Faker::IndustrySegments.industry #=> "Basic Materials"
54
+ #
55
+ # @faker.version 1.9.2
20
56
  def sub_sector
21
57
  fetch('industry_segments.sub_sector')
22
58
  end
@@ -3,23 +3,41 @@
3
3
  module Faker
4
4
  class Internet < Base
5
5
  class << self
6
- def email(name = nil, *separators)
6
+ def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil)
7
+ warn_for_deprecated_arguments do |keywords|
8
+ keywords << :name if legacy_name != NOT_GIVEN
9
+ keywords << :separators if legacy_separators != NOT_GIVEN
10
+ end
11
+
7
12
  if separators
8
- [username(name, separators), domain_name].join('@')
13
+ [username(specifier: name, separators: separators), domain_name].join('@')
9
14
  else
10
- [username(name), domain_name].join('@')
15
+ [username(specifier: name), domain_name].join('@')
11
16
  end
12
17
  end
13
18
 
14
- def free_email(name = nil)
15
- [username(name), fetch('internet.free_email')].join('@')
19
+ def free_email(legacy_name = NOT_GIVEN, name: nil)
20
+ warn_for_deprecated_arguments do |keywords|
21
+ keywords << :name if legacy_name != NOT_GIVEN
22
+ end
23
+
24
+ [username(specifier: name), fetch('internet.free_email')].join('@')
16
25
  end
17
26
 
18
- def safe_email(name = nil)
19
- [username(name), 'example.' + sample(%w[org com net])].join('@')
27
+ def safe_email(legacy_name = NOT_GIVEN, name: nil)
28
+ warn_for_deprecated_arguments do |keywords|
29
+ keywords << :name if legacy_name != NOT_GIVEN
30
+ end
31
+
32
+ [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
20
33
  end
21
34
 
22
- def username(specifier = nil, separators = %w[. _])
35
+ def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
36
+ warn_for_deprecated_arguments do |keywords|
37
+ keywords << :specifier if legacy_specifier != NOT_GIVEN
38
+ keywords << :separators if legacy_separators != NOT_GIVEN
39
+ end
40
+
23
41
  with_locale(:en) do
24
42
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
25
43
 
@@ -30,7 +48,7 @@ module Faker
30
48
  tries = 0 # Don't try forever in case we get something like 1_000_000.
31
49
  result = nil
32
50
  loop do
33
- result = username(nil, separators)
51
+ result = username(specifier: nil, separators: separators)
34
52
  tries += 1
35
53
  break unless result.length < specifier && tries < 7
36
54
  end
@@ -39,7 +57,7 @@ module Faker
39
57
  tries = 0
40
58
  result = nil
41
59
  loop do
42
- result = username(specifier.min, separators)
60
+ result = username(specifier: specifier.min, separators: separators)
43
61
  tries += 1
44
62
  break unless !specifier.include?(result.length) && tries < 7
45
63
  end
@@ -55,21 +73,59 @@ module Faker
55
73
  end
56
74
  end
57
75
 
58
- def password(min_length = 8, max_length = 16, mix_case = true, special_chars = false)
59
- temp = Lorem.characters(min_length)
76
+ # rubocop:disable Metrics/ParameterLists
77
+
78
+ ##
79
+ # Produces a randomized string of characters suitable for passwords
80
+ #
81
+ # @param min_length [Integer] The minimum length of the password
82
+ # @param max_length [Integer] The maximum length of the password
83
+ # @param mix_case [Boolean] Toggles if uppercased letters are allowed. If true, at least one will be added.
84
+ # @param special_characters [Boolean] Toggles if special characters are allowed. If true, at least one will be added.
85
+ #
86
+ # @return [String]
87
+ #
88
+ # @example
89
+ # Faker::Internet.password #=> "Vg5mSvY1UeRg7"
90
+ # @example
91
+ # Faker::Internet.password(min_length: 8) #=> "YfGjIk0hGzDqS0"
92
+ # @example
93
+ # Faker::Internet.password(min_length: 10, max_length: 20) #=> "EoC9ShWd1hWq4vBgFw"
94
+ # @example
95
+ # Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true) #=> "3k5qS15aNmG"
96
+ # @example
97
+ # Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true, special_characters: true) #=> "*%NkOnJsH4"
98
+ #
99
+ # @faker.version 2.1.3
100
+ 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)
101
+ # rubocop:enable Metrics/ParameterLists
102
+ warn_for_deprecated_arguments do |keywords|
103
+ keywords << :min_length if legacy_min_length != NOT_GIVEN
104
+ keywords << :max_length if legacy_max_length != NOT_GIVEN
105
+ keywords << :mix_case if legacy_mix_case != NOT_GIVEN
106
+ keywords << :special_characters if legacy_special_characters != NOT_GIVEN
107
+ end
108
+
109
+ min_alpha = mix_case ? 2 : 0
110
+ temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
60
111
  diff_length = max_length - min_length
112
+
61
113
  if diff_length.positive?
62
114
  diff_rand = rand(diff_length + 1)
63
- temp += Lorem.characters(diff_rand)
115
+ temp += Lorem.characters(number: diff_rand)
64
116
  end
65
117
 
66
118
  if mix_case
119
+ alpha_count = 0
67
120
  temp.chars.each_with_index do |char, index|
68
- temp[index] = char.upcase if index.even?
121
+ if char =~ /[[:alpha:]]/
122
+ temp[index] = char.upcase if alpha_count.even?
123
+ alpha_count += 1
124
+ end
69
125
  end
70
126
  end
71
127
 
72
- if special_chars
128
+ if special_characters
73
129
  chars = %w[! @ # $ % ^ & *]
74
130
  rand(1..min_length).times do |i|
75
131
  temp[i] = chars[rand(chars.length)]
@@ -79,7 +135,11 @@ module Faker
79
135
  temp
80
136
  end
81
137
 
82
- def domain_name(subdomain = false)
138
+ def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false)
139
+ warn_for_deprecated_arguments do |keywords|
140
+ keywords << :subdomain if legacy_subdomain != NOT_GIVEN
141
+ end
142
+
83
143
  with_locale(:en) do
84
144
  domain_elements = [Char.prepare(domain_word), domain_suffix]
85
145
  domain_elements.unshift(Char.prepare(domain_word)) if subdomain
@@ -87,7 +147,11 @@ module Faker
87
147
  end
88
148
  end
89
149
 
90
- def fix_umlauts(string = '')
150
+ def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
151
+ warn_for_deprecated_arguments do |keywords|
152
+ keywords << :string if legacy_string != NOT_GIVEN
153
+ end
154
+
91
155
  Char.fix_umlauts(string)
92
156
  end
93
157
 
@@ -99,7 +163,11 @@ module Faker
99
163
  fetch('internet.domain_suffix')
100
164
  end
101
165
 
102
- def mac_address(prefix = '')
166
+ def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
167
+ warn_for_deprecated_arguments do |keywords|
168
+ keywords << :prefix if legacy_prefix != NOT_GIVEN
169
+ end
170
+
103
171
  prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
104
172
  address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
105
173
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
@@ -173,20 +241,37 @@ module Faker
173
241
  "#{ip_v6_address}/#{rand(1..127)}"
174
242
  end
175
243
 
176
- def url(host = domain_name, path = "/#{username}", scheme = 'http')
244
+ # rubocop:disable Metrics/ParameterLists
245
+ def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
246
+ # rubocop:enable Metrics/ParameterLists
247
+ warn_for_deprecated_arguments do |keywords|
248
+ keywords << :host if legacy_host != NOT_GIVEN
249
+ keywords << :path if legacy_path != NOT_GIVEN
250
+ keywords << :scheme if legacy_scheme != NOT_GIVEN
251
+ end
252
+
177
253
  "#{scheme}://#{host}#{path}"
178
254
  end
179
255
 
180
- def slug(words = nil, glue = nil)
256
+ def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
257
+ warn_for_deprecated_arguments do |keywords|
258
+ keywords << :words if legacy_words != NOT_GIVEN
259
+ keywords << :glue if legacy_glue != NOT_GIVEN
260
+ end
261
+
181
262
  glue ||= sample(%w[- _])
182
- (words || Faker::Lorem.words(2).join(' ')).delete(',.').gsub(' ', glue).downcase
263
+ (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
183
264
  end
184
265
 
185
266
  def device_token
186
267
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
187
268
  end
188
269
 
189
- def user_agent(vendor = nil)
270
+ def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
271
+ warn_for_deprecated_arguments do |keywords|
272
+ keywords << :vendor if legacy_vendor != NOT_GIVEN
273
+ end
274
+
190
275
  agent_hash = translate('faker.internet.user_agent')
191
276
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
192
277
  sample(agents)
@@ -6,13 +6,22 @@ module Faker
6
6
 
7
7
  class << self
8
8
  # Generate random amount between values with 2 decimals
9
- def amount_between(from = 0, to = 0)
9
+ def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0)
10
+ warn_for_deprecated_arguments do |keywords|
11
+ keywords << :from if legacy_from != NOT_GIVEN
12
+ keywords << :to if legacy_to != NOT_GIVEN
13
+ end
14
+
10
15
  Faker::Base.rand_in_range(from, to).round(2)
11
16
  end
12
17
 
13
18
  # International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
14
19
  # ref is optional so that we can create unit tests
15
- def creditor_reference(ref = '')
20
+ def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
21
+ warn_for_deprecated_arguments do |keywords|
22
+ keywords << :ref if legacy_ref != NOT_GIVEN
23
+ end
24
+
16
25
  ref = reference if ref.empty?
17
26
 
18
27
  'RF' + iban_checksum('RF', ref) + ref
@@ -20,7 +29,11 @@ module Faker
20
29
 
21
30
  # Payment references have some rules in certain countries
22
31
  # ref is optional so that we can create unit tests
23
- def reference(ref = '')
32
+ def reference(legacy_ref = NOT_GIVEN, ref: '')
33
+ warn_for_deprecated_arguments do |keywords|
34
+ keywords << :ref if legacy_ref != NOT_GIVEN
35
+ end
36
+
24
37
  pattern = fetch('invoice.reference.pattern')
25
38
 
26
39
  ref = Base.regexify(/#{pattern}/) if ref.empty?