faker 2.0.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -1
  3. data/README.md +3 -3
  4. data/lib/faker.rb +22 -1
  5. data/lib/faker/books/dune.rb +12 -2
  6. data/lib/faker/books/lovecraft.rb +54 -7
  7. data/lib/faker/default/address.rb +30 -5
  8. data/lib/faker/default/alphanumeric.rb +45 -7
  9. data/lib/faker/default/app.rb +16 -1
  10. data/lib/faker/default/avatar.rb +24 -1
  11. data/lib/faker/default/bank.rb +12 -2
  12. data/lib/faker/default/boolean.rb +6 -1
  13. data/lib/faker/default/chile_rut.rb +20 -2
  14. data/lib/faker/default/code.rb +22 -3
  15. data/lib/faker/default/commerce.rb +26 -3
  16. data/lib/faker/default/company.rb +12 -2
  17. data/lib/faker/default/crypto_coin.rb +18 -3
  18. data/lib/faker/default/date.rb +48 -5
  19. data/lib/faker/default/demographic.rb +6 -1
  20. data/lib/faker/default/driving_licence.rb +20 -4
  21. data/lib/faker/default/file.rb +36 -2
  22. data/lib/faker/default/fillmurray.rb +16 -1
  23. data/lib/faker/default/finance.rb +6 -1
  24. data/lib/faker/default/hipster.rb +78 -6
  25. data/lib/faker/default/id_number.rb +50 -3
  26. data/lib/faker/default/internet.rb +124 -13
  27. data/lib/faker/default/invoice.rb +22 -3
  28. data/lib/faker/default/json.rb +26 -2
  29. data/lib/faker/default/lorem.rb +120 -10
  30. data/lib/faker/default/lorem_flickr.rb +69 -5
  31. data/lib/faker/default/lorem_pixel.rb +26 -1
  32. data/lib/faker/default/markdown.rb +10 -1
  33. data/lib/faker/default/measurement.rb +48 -8
  34. data/lib/faker/default/name.rb +6 -1
  35. data/lib/faker/default/nhs.rb +6 -1
  36. data/lib/faker/default/number.rb +81 -11
  37. data/lib/faker/default/omniauth.rb +84 -5
  38. data/lib/faker/default/phone_number.rb +6 -1
  39. data/lib/faker/default/placeholdit.rb +24 -1
  40. data/lib/faker/default/relationship.rb +6 -1
  41. data/lib/faker/default/source.rb +22 -3
  42. data/lib/faker/default/string.rb +6 -1
  43. data/lib/faker/default/stripe.rb +24 -4
  44. data/lib/faker/default/time.rb +68 -4
  45. data/lib/faker/default/twitter.rb +26 -3
  46. data/lib/faker/default/types.rb +38 -5
  47. data/lib/faker/default/vehicle.rb +22 -3
  48. data/lib/faker/default/world_cup.rb +16 -2
  49. data/lib/faker/games/dota.rb +6 -1
  50. data/lib/faker/movies/star_wars.rb +6 -1
  51. data/lib/faker/version.rb +1 -1
  52. data/lib/locales/en.yml +0 -47
  53. metadata +11 -11
@@ -3,7 +3,22 @@
3
3
  module Faker
4
4
  class Fillmurray < Base
5
5
  class << self
6
- def image(grayscale: false, width: 200, height: 200)
6
+ # rubocop:disable Metrics/ParameterLists
7
+ def image(legacy_grayscale = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_height = NOT_GIVEN, grayscale: false, width: 200, height: 200)
8
+ # rubocop:enable Metrics/ParameterLists
9
+ if legacy_grayscale != NOT_GIVEN
10
+ warn_with_uplevel 'Passing `grayscale` with the 1st argument of `Fillmurray.image` is deprecated. Use keyword argument like `Fillmurray.image(grayscale: ...)` instead.', uplevel: 1
11
+ grayscale = legacy_grayscale
12
+ end
13
+ if legacy_width != NOT_GIVEN
14
+ warn_with_uplevel 'Passing `width` with the 2nd argument of `Fillmurray.image` is deprecated. Use keyword argument like `Fillmurray.image(width: ...)` instead.', uplevel: 1
15
+ width = legacy_width
16
+ end
17
+ if legacy_height != NOT_GIVEN
18
+ warn_with_uplevel 'Passing `height` with the 3rd argument of `Fillmurray.image` is deprecated. Use keyword argument like `Fillmurray.image(height: ...)` instead.', uplevel: 1
19
+ height = legacy_height
20
+ end
21
+
7
22
  raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
8
23
  raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
9
24
  raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)
@@ -26,7 +26,12 @@ module Faker
26
26
  template.gsub('L', luhn_digit.to_s)
27
27
  end
28
28
 
29
- def vat_number(country: 'BR')
29
+ def vat_number(legacy_country = NOT_GIVEN, country: 'BR')
30
+ if legacy_country != NOT_GIVEN
31
+ warn_with_uplevel 'Passing `country` with the 1st argument of `Finance.vat_number` is deprecated. Use keyword argument like `Finance.vat_number(country: ...)` instead.', uplevel: 1
32
+ country = legacy_country
33
+ end
34
+
30
35
  numerify(fetch("finance.vat_number.#{country}"))
31
36
  rescue I18n::MissingTranslationData
32
37
  raise ArgumentError, "Could not find vat number for #{country}"
@@ -8,7 +8,22 @@ module Faker
8
8
  random_word =~ /\s/ ? word : random_word
9
9
  end
10
10
 
11
- def words(number: 3, supplemental: false, spaces_allowed: false)
11
+ # rubocop:disable Metrics/ParameterLists
12
+ def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false)
13
+ # rubocop:enable Metrics/ParameterLists
14
+ if legacy_number != NOT_GIVEN
15
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(number: ...)` instead.', uplevel: 1
16
+ number = legacy_number
17
+ end
18
+ if legacy_supplemental != NOT_GIVEN
19
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(supplemental: ...)` instead.', uplevel: 1
20
+ supplemental = legacy_supplemental
21
+ end
22
+ if legacy_spaces_allowed != NOT_GIVEN
23
+ warn_with_uplevel 'Passing `spaces_allowed` with the 3rd argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(spaces_allowed: ...)` instead.', uplevel: 1
24
+ spaces_allowed = legacy_spaces_allowed
25
+ end
26
+
12
27
  resolved_num = resolve(number)
13
28
  word_list = (
14
29
  translate('faker.hipster.words') +
@@ -22,11 +37,35 @@ module Faker
22
37
  words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
23
38
  end
24
39
 
25
- def sentence(word_count: 4, supplemental: false, random_words_to_add: 6)
40
+ # rubocop:disable Metrics/ParameterLists
41
+ 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)
42
+ # rubocop:enable Metrics/ParameterLists
43
+ if legacy_word_count != NOT_GIVEN
44
+ warn_with_uplevel 'Passing `word_count` with the 1st argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(word_count: ...)` instead.', uplevel: 1
45
+ word_count = legacy_word_count
46
+ end
47
+ if legacy_supplemental != NOT_GIVEN
48
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(supplemental: ...)` instead.', uplevel: 1
49
+ supplemental = legacy_supplemental
50
+ end
51
+ if legacy_random_words_to_add != NOT_GIVEN
52
+ warn_with_uplevel 'Passing `random_words_to_add` with the 3rd argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(random_words_to_add: ...)` instead.', uplevel: 1
53
+ random_words_to_add = legacy_random_words_to_add
54
+ end
55
+
26
56
  words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.'
27
57
  end
28
58
 
29
- def sentences(number: 3, supplemental: false)
59
+ def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
60
+ if legacy_number != NOT_GIVEN
61
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.sentences` is deprecated. Use keyword argument like `Hipster.sentences(number: ...)` instead.', uplevel: 1
62
+ number = legacy_number
63
+ end
64
+ if legacy_supplemental != NOT_GIVEN
65
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.sentences` is deprecated. Use keyword argument like `Hipster.sentences(supplemental: ...)` instead.', uplevel: 1
66
+ supplemental = legacy_supplemental
67
+ end
68
+
30
69
  [].tap do |sentences|
31
70
  1.upto(resolve(number)) do
32
71
  sentences << sentence(word_count: 3, supplemental: supplemental)
@@ -34,11 +73,35 @@ module Faker
34
73
  end
35
74
  end
36
75
 
37
- def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
76
+ # rubocop:disable Metrics/ParameterLists
77
+ 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)
78
+ # rubocop:enable Metrics/ParameterLists
79
+ if legacy_sentence_count != NOT_GIVEN
80
+ warn_with_uplevel 'Passing `sentence_count` with the 1st argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(sentence_count: ...)` instead.', uplevel: 1
81
+ sentence_count = legacy_sentence_count
82
+ end
83
+ if legacy_supplemental != NOT_GIVEN
84
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(supplemental: ...)` instead.', uplevel: 1
85
+ supplemental = legacy_supplemental
86
+ end
87
+ if legacy_random_sentences_to_add != NOT_GIVEN
88
+ warn_with_uplevel 'Passing `random_sentences_to_add` with the 3rd argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(random_sentences_to_add: ...)` instead.', uplevel: 1
89
+ random_sentences_to_add = legacy_random_sentences_to_add
90
+ end
91
+
38
92
  sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
39
93
  end
40
94
 
41
- def paragraphs(number: 3, supplemental: false)
95
+ def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
96
+ if legacy_number != NOT_GIVEN
97
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.paragraphs` is deprecated. Use keyword argument like `Hipster.paragraphs(number: ...)` instead.', uplevel: 1
98
+ number = legacy_number
99
+ end
100
+ if legacy_supplemental != NOT_GIVEN
101
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraphs` is deprecated. Use keyword argument like `Hipster.paragraphs(supplemental: ...)` instead.', uplevel: 1
102
+ supplemental = legacy_supplemental
103
+ end
104
+
42
105
  [].tap do |paragraphs|
43
106
  1.upto(resolve(number)) do
44
107
  paragraphs << paragraph(sentence_count: 3, supplemental: supplemental)
@@ -46,7 +109,16 @@ module Faker
46
109
  end
47
110
  end
48
111
 
49
- def paragraph_by_chars(characters: 256, supplemental: false)
112
+ def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false)
113
+ if legacy_characters != NOT_GIVEN
114
+ warn_with_uplevel 'Passing `characters` with the 1st argument of `Hipster.paragraph_by_chars` is deprecated. Use keyword argument like `Hipster.paragraph_by_chars(characters: ...)` instead.', uplevel: 1
115
+ characters = legacy_characters
116
+ end
117
+ if legacy_supplemental != NOT_GIVEN
118
+ warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraph_by_chars` is deprecated. Use keyword argument like `Hipster.paragraph_by_chars(supplemental: ...)` instead.', uplevel: 1
119
+ supplemental = legacy_supplemental
120
+ end
121
+
50
122
  paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
51
123
 
52
124
  paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < characters
@@ -12,6 +12,9 @@ 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])/
16
+ BRAZILIAN_ID_FROM = 10_000_000
17
+ BRAZILIAN_ID_TO = 99_999_999
15
18
 
16
19
  class << self
17
20
  def valid
@@ -75,7 +78,12 @@ module Faker
75
78
  [id_number, south_african_id_checksum_digit(id_number)].join
76
79
  end
77
80
 
78
- def brazilian_citizen_number(formatted: false)
81
+ def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
82
+ if legacy_formatted != NOT_GIVEN
83
+ warn_with_uplevel 'Passing `formatted` with the 1st argument of `IDNumber.brazilian_citizen_number` is deprecated. Use keyword argument like `IDNumber.brazilian_citizen_number(formatted: ...)` instead.', uplevel: 1
84
+ formatted = legacy_formatted
85
+ end
86
+
79
87
  digits = Faker::Number.leading_zero_number(digits: 9) until digits&.match(/(\d)((?!\1)\d)+/)
80
88
  first_digit = brazilian_citizen_number_checksum_digit(digits)
81
89
  second_digit = brazilian_citizen_number_checksum_digit(digits + first_digit)
@@ -83,6 +91,22 @@ module Faker
83
91
  formatted ? format('%s.%s.%s-%s', *number.scan(/\d{2,3}/).flatten) : number
84
92
  end
85
93
 
94
+ alias brazilian_cpf brazilian_citizen_number
95
+
96
+ def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
97
+ if legacy_formatted != NOT_GIVEN
98
+ warn_with_uplevel 'Passing `formatted` with the 1st argument of `IDNumber.brazilian_id` is deprecated. Use keyword argument like `IDNumber.brazilian_id(formatted: ...)` instead.', uplevel: 1
99
+ formatted = legacy_formatted
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
+
86
110
  private
87
111
 
88
112
  def south_african_id_checksum_digit(id_number)
@@ -104,13 +128,36 @@ module Faker
104
128
  end
105
129
 
106
130
  def brazilian_citizen_number_checksum_digit(digits)
107
- digit_sum = digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
131
+ checksum = brazilian_document_checksum(digits)
132
+ brazilian_document_digit(checksum)
133
+ end
134
+
135
+ def brazilian_id_checksum_digit(digits)
136
+ checksum = brazilian_document_checksum(digits)
137
+ brazilian_document_digit(checksum, id: true)
138
+ end
139
+
140
+ def brazilian_document_checksum(digits)
141
+ digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
108
142
  acc + digit.to_i * (digits.size + 1 - i)
109
143
  end * 10
110
- remainder = digit_sum % 11
144
+ end
145
+
146
+ def brazilian_document_digit(checksum, id = false)
147
+ remainder = checksum % 11
148
+ id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
149
+ end
150
+
151
+ def brazilian_citizen_number_digit(remainder)
111
152
  remainder == 10 ? '0' : remainder.to_s
112
153
  end
113
154
 
155
+ def brazilian_id_digit(remainder)
156
+ subtraction = 11 - remainder.to_i
157
+ digits = { 10 => 'X', 11 => '0' }
158
+ digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
159
+ end
160
+
114
161
  def _translate(key)
115
162
  parse("id_number.#{key}")
116
163
  end
@@ -3,7 +3,16 @@
3
3
  module Faker
4
4
  class Internet < Base
5
5
  class << self
6
- def email(name: nil, separators: nil)
6
+ def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil)
7
+ if legacy_name != NOT_GIVEN
8
+ warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.email` is deprecated. Use keyword argument like `Internet.email(name: ...)` instead.', uplevel: 1
9
+ name = legacy_name
10
+ end
11
+ if legacy_separators != NOT_GIVEN
12
+ warn_with_uplevel 'Passing `separators` with the 2nd argument of `Internet.email` is deprecated. Use keyword argument like `Internet.email(separators: ...)` instead.', uplevel: 1
13
+ separators = legacy_separators
14
+ end
15
+
7
16
  if separators
8
17
  [username(specifier: name, separators: separators), domain_name].join('@')
9
18
  else
@@ -11,15 +20,34 @@ module Faker
11
20
  end
12
21
  end
13
22
 
14
- def free_email(name: nil)
23
+ def free_email(legacy_name = NOT_GIVEN, name: nil)
24
+ if legacy_name != NOT_GIVEN
25
+ warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.free_email` is deprecated. Use keyword argument like `Internet.free_email(name: ...)` instead.', uplevel: 1
26
+ name = legacy_name
27
+ end
28
+
15
29
  [username(specifier: name), fetch('internet.free_email')].join('@')
16
30
  end
17
31
 
18
- def safe_email(name: nil)
32
+ def safe_email(legacy_name = NOT_GIVEN, name: nil)
33
+ if legacy_name != NOT_GIVEN
34
+ warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.safe_email` is deprecated. Use keyword argument like `Internet.safe_email(name: ...)` instead.', uplevel: 1
35
+ name = legacy_name
36
+ end
37
+
19
38
  [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
20
39
  end
21
40
 
22
- def username(specifier: nil, separators: %w[. _])
41
+ def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
42
+ if legacy_specifier != NOT_GIVEN
43
+ warn_with_uplevel 'Passing `specifier` with the 1st argument of `Internet.username` is deprecated. Use keyword argument like `Internet.username(specifier: ...)` instead.', uplevel: 1
44
+ specifier = legacy_specifier
45
+ end
46
+ if legacy_separators != NOT_GIVEN
47
+ warn_with_uplevel 'Passing `separators` with the 2nd argument of `Internet.username` is deprecated. Use keyword argument like `Internet.username(separators: ...)` instead.', uplevel: 1
48
+ separators = legacy_separators
49
+ end
50
+
23
51
  with_locale(:en) do
24
52
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
25
53
 
@@ -55,8 +83,44 @@ module Faker
55
83
  end
56
84
  end
57
85
 
58
- def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
59
- temp = Lorem.characters(number: min_length)
86
+ ##
87
+ # Produces a randomized string of characters
88
+ #
89
+ # @param [Integer] min_length
90
+ # @param [Integer] max_length
91
+ # @param [Boolean] mix_case
92
+ # @param [Boolean] special_characters
93
+ #
94
+ # @return [String]
95
+ #
96
+ # @example Faker::Internet.password #=> "Vg5mSvY1UeRg7"
97
+ # @example Faker::Internet.password(min_length: 8) #=> "YfGjIk0hGzDqS0"
98
+ # @example Faker::Internet.password(min_length: 10, max_length: 20) #=> "EoC9ShWd1hWq4vBgFw"
99
+ # @example Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true) #=> "3k5qS15aNmG"
100
+ # @example Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true, special_characters: true) #=> "*%NkOnJsH4"
101
+ #
102
+ # @faker.version 2.1.3
103
+ # rubocop:disable Metrics/ParameterLists
104
+ 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)
105
+ if legacy_min_length != NOT_GIVEN
106
+ warn_with_uplevel 'Passing `min_length` with the 1st argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(min_length: ...)` instead.', uplevel: 1
107
+ min_length = legacy_min_length
108
+ end
109
+ if legacy_max_length != NOT_GIVEN
110
+ warn_with_uplevel 'Passing `max_length` with the 2nd argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(max_length: ...)` instead.', uplevel: 1
111
+ max_length = legacy_max_length
112
+ end
113
+ if legacy_mix_case != NOT_GIVEN
114
+ warn_with_uplevel 'Passing `mix_case` with the 3rd argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(mix_case: ...)` instead.', uplevel: 1
115
+ mix_case = legacy_mix_case
116
+ end
117
+ if legacy_special_characters != NOT_GIVEN
118
+ warn_with_uplevel 'Passing `special_characters` with the 4th argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(special_characters: ...)` instead.', uplevel: 1
119
+ special_characters = legacy_special_characters
120
+ end
121
+
122
+ min_alpha = mix_case ? 2 : 0
123
+ temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
60
124
  diff_length = max_length - min_length
61
125
 
62
126
  if diff_length.positive?
@@ -65,8 +129,12 @@ module Faker
65
129
  end
66
130
 
67
131
  if mix_case
132
+ alpha_count = 0
68
133
  temp.chars.each_with_index do |char, index|
69
- temp[index] = char.upcase if index.even?
134
+ if char =~ /[[:alpha:]]/
135
+ temp[index] = char.upcase if alpha_count.even?
136
+ alpha_count += 1
137
+ end
70
138
  end
71
139
  end
72
140
 
@@ -80,7 +148,12 @@ module Faker
80
148
  temp
81
149
  end
82
150
 
83
- def domain_name(subdomain: false)
151
+ def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false)
152
+ if legacy_subdomain != NOT_GIVEN
153
+ warn_with_uplevel 'Passing `subdomain` with the 1st argument of `Internet.domain_name` is deprecated. Use keyword argument like `Internet.domain_name(subdomain: ...)` instead.', uplevel: 1
154
+ subdomain = legacy_subdomain
155
+ end
156
+
84
157
  with_locale(:en) do
85
158
  domain_elements = [Char.prepare(domain_word), domain_suffix]
86
159
  domain_elements.unshift(Char.prepare(domain_word)) if subdomain
@@ -88,7 +161,12 @@ module Faker
88
161
  end
89
162
  end
90
163
 
91
- def fix_umlauts(string: '')
164
+ def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
165
+ if legacy_string != NOT_GIVEN
166
+ warn_with_uplevel 'Passing `string` with the 1st argument of `Internet.fix_umlauts` is deprecated. Use keyword argument like `Internet.fix_umlauts(string: ...)` instead.', uplevel: 1
167
+ string = legacy_string
168
+ end
169
+
92
170
  Char.fix_umlauts(string)
93
171
  end
94
172
 
@@ -100,7 +178,12 @@ module Faker
100
178
  fetch('internet.domain_suffix')
101
179
  end
102
180
 
103
- def mac_address(prefix: '')
181
+ def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
182
+ if legacy_prefix != NOT_GIVEN
183
+ warn_with_uplevel 'Passing `prefix` with the 1st argument of `Internet.mac_address` is deprecated. Use keyword argument like `Internet.mac_address(prefix: ...)` instead.', uplevel: 1
184
+ prefix = legacy_prefix
185
+ end
186
+
104
187
  prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
105
188
  address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
106
189
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
@@ -174,11 +257,34 @@ module Faker
174
257
  "#{ip_v6_address}/#{rand(1..127)}"
175
258
  end
176
259
 
177
- def url(host: domain_name, path: "/#{username}", scheme: 'http')
260
+ def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
261
+ # rubocop:enable Metrics/ParameterLists
262
+ if legacy_host != NOT_GIVEN
263
+ warn_with_uplevel 'Passing `host` with the 1st argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(host: ...)` instead.', uplevel: 1
264
+ host = legacy_host
265
+ end
266
+ if legacy_path != NOT_GIVEN
267
+ warn_with_uplevel 'Passing `path` with the 2nd argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(path: ...)` instead.', uplevel: 1
268
+ path = legacy_path
269
+ end
270
+ if legacy_scheme != NOT_GIVEN
271
+ warn_with_uplevel 'Passing `scheme` with the 3rd argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(scheme: ...)` instead.', uplevel: 1
272
+ scheme = legacy_scheme
273
+ end
274
+
178
275
  "#{scheme}://#{host}#{path}"
179
276
  end
180
277
 
181
- def slug(words: nil, glue: nil)
278
+ def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
279
+ if legacy_words != NOT_GIVEN
280
+ warn_with_uplevel 'Passing `words` with the 1st argument of `Internet.slug` is deprecated. Use keyword argument like `Internet.slug(words: ...)` instead.', uplevel: 1
281
+ words = legacy_words
282
+ end
283
+ if legacy_glue != NOT_GIVEN
284
+ warn_with_uplevel 'Passing `glue` with the 2nd argument of `Internet.slug` is deprecated. Use keyword argument like `Internet.slug(glue: ...)` instead.', uplevel: 1
285
+ glue = legacy_glue
286
+ end
287
+
182
288
  glue ||= sample(%w[- _])
183
289
  (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
184
290
  end
@@ -187,7 +293,12 @@ module Faker
187
293
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
188
294
  end
189
295
 
190
- def user_agent(vendor: nil)
296
+ def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
297
+ if legacy_vendor != NOT_GIVEN
298
+ warn_with_uplevel 'Passing `vendor` with the 1st argument of `Internet.user_agent` is deprecated. Use keyword argument like `Internet.user_agent(vendor: ...)` instead.', uplevel: 1
299
+ vendor = legacy_vendor
300
+ end
301
+
191
302
  agent_hash = translate('faker.internet.user_agent')
192
303
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
193
304
  sample(agents)
@@ -6,13 +6,27 @@ 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
+ if legacy_from != NOT_GIVEN
11
+ warn_with_uplevel 'Passing `from` with the 1st argument of `Invoice.amount_between` is deprecated. Use keyword argument like `Invoice.amount_between(from: ...)` instead.', uplevel: 1
12
+ from = legacy_from
13
+ end
14
+ if legacy_to != NOT_GIVEN
15
+ warn_with_uplevel 'Passing `to` with the 2nd argument of `Invoice.amount_between` is deprecated. Use keyword argument like `Invoice.amount_between(to: ...)` instead.', uplevel: 1
16
+ to = legacy_to
17
+ end
18
+
10
19
  Faker::Base.rand_in_range(from, to).round(2)
11
20
  end
12
21
 
13
22
  # International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
14
23
  # ref is optional so that we can create unit tests
15
- def creditor_reference(ref: '')
24
+ def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
25
+ if legacy_ref != NOT_GIVEN
26
+ warn_with_uplevel 'Passing `ref` with the 1st argument of `Invoice.creditor_reference` is deprecated. Use keyword argument like `Invoice.creditor_reference(ref: ...)` instead.', uplevel: 1
27
+ ref = legacy_ref
28
+ end
29
+
16
30
  ref = reference if ref.empty?
17
31
 
18
32
  'RF' + iban_checksum('RF', ref) + ref
@@ -20,7 +34,12 @@ module Faker
20
34
 
21
35
  # Payment references have some rules in certain countries
22
36
  # ref is optional so that we can create unit tests
23
- def reference(ref: '')
37
+ def reference(legacy_ref = NOT_GIVEN, ref: '')
38
+ if legacy_ref != NOT_GIVEN
39
+ warn_with_uplevel 'Passing `ref` with the 1st argument of `Invoice.reference` is deprecated. Use keyword argument like `Invoice.reference(ref: ...)` instead.', uplevel: 1
40
+ ref = legacy_ref
41
+ end
42
+
24
43
  pattern = fetch('invoice.reference.pattern')
25
44
 
26
45
  ref = Base.regexify(/#{pattern}/) if ref.empty?