faker 2.22.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf9982602494b75bec172760f6eb2e685b7370eed2ca8e726d1790fc4cbeec89
4
- data.tar.gz: a9a282259c77b223ea0688cb02147de544fd199b50e72a0625a7245ed34c7c83
3
+ metadata.gz: 5d8cd66a58c224a6a003a614df1b81c934ddf8eb4033d51f4cc4df2a0b377193
4
+ data.tar.gz: f761e03f47cd4e7b04d5c5f70e9639576e628613b5f3eca232b21a38e3aa810d
5
5
  SHA512:
6
- metadata.gz: a4088353a5fce47a5d5585c8e6684c7361d0a44c850b4f937fc00c0d573110bedc4446b5594e590ec6b6d4107a8c0bd59c2c9a6bf304c049f88cc5c4436f812a
7
- data.tar.gz: d8b21e7c1b550a3ae85aaac3afe6a259b92c651b88acf61bc4c163804416a47d03b4d159527c79e2cf4f40d62bb613eecf9afe1be7ad15ae044c984a60b3c8ee
6
+ metadata.gz: 6a902462978f950d791e6ba96b1ce48fdd3b2db3e1336871a48b98410c6dd5f6f29397f8763f1c3786398162a140e1f664849ee6469c538d8d68d81d0c875b35
7
+ data.tar.gz: c4996e30be72c6f8b747e236bc139585695c9e554982794ab5b78961a9944b632ae4c408218b47a5799e015d536164356538dbf748a1290ff69353e1e3aa390a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Change Log
2
2
 
3
+ ## [v2.23.0](https://github.com/faker-ruby/faker/tree/v2.23.0) (2022-09-01)
4
+
5
+ * Fix Japanese plural by @akmhmgc in https://github.com/faker-ruby/faker/pull/2517
6
+ * Update rubocop requirement from = 1.26.0 to = 1.28.2 by @dependabot in https://github.com/faker-ruby/faker/pull/2483
7
+ * Add sports to `Faker::Sport` by @matt17r in https://github.com/faker-ruby/faker/pull/2397
8
+ * [Internet::Password] Improve mix_case and special_characters support by @meuble in https://github.com/faker-ruby/faker/pull/2308
9
+ * Danish id number by @jokklan in https://github.com/faker-ruby/faker/pull/2511
10
+ * Add generator for vulnerability identifiers by @NobodysNightmare in https://github.com/faker-ruby/faker/pull/2367
11
+ * Add the ability to generate a mime type of a specific media type by @ric2b in https://github.com/faker-ruby/faker/pull/2518
12
+ * Add IDNumber.french_insee_number by @Spone in https://github.com/faker-ruby/faker/pull/2455
13
+ * fix flaky user agent test by @thdaraujo in https://github.com/faker-ruby/faker/pull/2530
14
+ * Update GitHub Issues and Pull Request Templates [ci-skip] by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2531
15
+ * fix: ensure generated passwords have correct characters when mixed_case & special_characters enabled by @tiff-o in https://github.com/faker-ruby/faker/pull/2532
16
+ * Thread safety by @kiskoza in https://github.com/faker-ruby/faker/pull/2520
17
+ * Fix warning instance variable uninitialized by @akmhmgc in https://github.com/faker-ruby/faker/pull/2535
18
+ * fix italy VAT and add italy condominium fiscal code generator by @FiloSpaTeam in https://github.com/faker-ruby/faker/pull/2491
19
+ * Add ChileRut.full_formatted_rut by @KarlHeitmann in https://github.com/faker-ruby/faker/pull/2460
20
+ * Updated versions and added more operating systems by @abrahamparayil in https://github.com/faker-ruby/faker/pull/2536
21
+ * Add vehicle version generator by @trinaldi in https://github.com/faker-ruby/faker/pull/2540
22
+ * Fix computer test by @trinaldi in https://github.com/faker-ruby/faker/pull/2543
23
+ * Drop support for EOL Ruby versions (`2.5` and `2.6`) by @nickmendezFlatiron in https://github.com/faker-ruby/faker/pull/2538
24
+ * Update minitest requirement from = 5.15.0 to = 5.16.3 by @dependabot in https://github.com/faker-ruby/faker/pull/2547
25
+ * Update rubocop requirement from = 1.28.2 to = 1.35.1 by @dependabot in https://github.com/faker-ruby/faker/pull/2548
26
+ * Fix `fma_brotherhood` usage example by @y0n0zawa in https://github.com/faker-ruby/faker/pull/2552
27
+
28
+ ------------------------------------------------------------------------------
29
+
3
30
  ## [v2.22.0](https://github.com/faker-ruby/faker/tree/v2.22.0) (2022-07-28)
4
31
 
5
32
  ## Bug/Fixes
data/README.md CHANGED
@@ -217,6 +217,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'mast
217
217
  - [Faker::University](doc/default/university.md)
218
218
  - [Faker::Vehicle](doc/default/vehicle.md)
219
219
  - [Faker::Verbs](doc/default/verbs.md)
220
+ - [Faker::VulnerabilityIdentifier](doc/default/vulnerability_identifier.md)
220
221
  - [Faker::WorldCup](doc/default/world_cup.md)
221
222
 
222
223
  ### Blockchain
@@ -61,7 +61,7 @@ module Faker
61
61
  def rand_strings(length = 50)
62
62
  hex_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
63
63
  var = +''
64
- length.times { var << sample(shuffle(hex_alphabet.split(''))) }
64
+ length.times { var << sample(shuffle(hex_alphabet.chars)) }
65
65
  var
66
66
  end
67
67
  end
@@ -17,7 +17,7 @@ module Faker
17
17
  def address
18
18
  hex_alphabet = '0123456789abcdef'
19
19
  var = +'0x'
20
- 40.times { var << sample(shuffle(hex_alphabet.split(''))) }
20
+ 40.times { var << sample(shuffle(hex_alphabet.chars)) }
21
21
  var
22
22
  end
23
23
  end
@@ -125,7 +125,7 @@ module Faker
125
125
  # @return [String]
126
126
  def encode_tz(prefix, payload_size)
127
127
  prefix = PREFIXES.fetch(prefix)
128
- packed = prefix.map(&:chr).join('') + Faker::Config.random.bytes(payload_size)
128
+ packed = prefix.map(&:chr).join + Faker::Config.random.bytes(payload_size)
129
129
  checksum = OpenSSL::Digest::SHA256.digest(OpenSSL::Digest::SHA256.digest(packed))[0..3]
130
130
  Faker::Base58.encode(packed + checksum)
131
131
  end
@@ -23,7 +23,7 @@ module Faker
23
23
 
24
24
  output = ''
25
25
 
26
- output += rand.to_s[2..-1] while output.length < digits
26
+ output += rand.to_s[2..] while output.length < digits
27
27
 
28
28
  output[0...digits]
29
29
  end
@@ -145,7 +145,7 @@ module Faker
145
145
  private
146
146
 
147
147
  def checksum(num_string)
148
- num_array = num_string.split('').map(&:to_i)
148
+ num_array = num_string.chars.map(&:to_i)
149
149
  (
150
150
  7 * (num_array[0] + num_array[3] + num_array[6]) +
151
151
  3 * (num_array[1] + num_array[4] + num_array[7]) +
@@ -194,8 +194,8 @@ module Faker
194
194
 
195
195
  def compile_fraction(routing_num)
196
196
  prefix = (1..50).to_a.map(&:to_s).sample
197
- numerator = routing_num.split('')[5..8].join.to_i.to_s
198
- denominator = routing_num.split('')[0..4].join.to_i.to_s
197
+ numerator = routing_num.chars[5..8].join.to_i.to_s
198
+ denominator = routing_num.chars[0..4].join.to_i.to_s
199
199
  "#{prefix}-#{numerator}/#{denominator}"
200
200
  end
201
201
 
@@ -37,7 +37,7 @@ module Faker
37
37
  #
38
38
  # @faker.version 1.9.2
39
39
  def dv
40
- split_reversed_rut = @last_rut.to_s.reverse.split('')
40
+ split_reversed_rut = @last_rut.to_s.reverse.chars
41
41
  seq = [2, 3, 4, 5, 6, 7]
42
42
  i = 0
43
43
  digit_sum = split_reversed_rut.reduce(0) do |sum, n|
@@ -82,14 +82,18 @@ module Faker
82
82
  # Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30686957-4"
83
83
  # Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4"
84
84
  #
85
- # @faker.version 1.9.2
86
- def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false)
85
+ # @faker.version next
86
+ def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false, formatted: false)
87
87
  warn_for_deprecated_arguments do |keywords|
88
88
  keywords << :min_rut if legacy_min_rut != NOT_GIVEN
89
89
  keywords << :fixed if legacy_fixed != NOT_GIVEN
90
90
  end
91
91
 
92
- "#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
92
+ if formatted
93
+ "#{rut(min_rut: min_rut, fixed: fixed).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse}-#{dv}"
94
+ else
95
+ "#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
96
+ end
93
97
  end
94
98
 
95
99
  attr_reader :last_rut
@@ -107,7 +107,7 @@ module Faker
107
107
 
108
108
  birthyear = Date.birthday(min_age: min_age, max_age: max_age).year
109
109
  prefix = birthyear < 2000 ? 'S' : 'T'
110
- values = birthyear.to_s[-2..-1]
110
+ values = birthyear.to_s[-2..]
111
111
  values << regexify(/\d{5}/)
112
112
  check_alpha = generate_nric_check_alphabet(values, prefix)
113
113
  "#{prefix}#{values}#{check_alpha}"
@@ -206,7 +206,7 @@ module Faker
206
206
  str[len - 1] = (10 - (sum % 10)) % 10
207
207
 
208
208
  # Output the IMEI value.
209
- str.join('')
209
+ str.join
210
210
  end
211
211
 
212
212
  def generate_base10_isbn
@@ -222,20 +222,20 @@ module Faker
222
222
  end
223
223
 
224
224
  def sum(values)
225
- values.split(//).each_with_index.inject(0) do |sum, (value, index)|
225
+ values.chars.each_with_index.inject(0) do |sum, (value, index)|
226
226
  sum + yield(value, index)
227
227
  end
228
228
  end
229
229
 
230
230
  def generate_base8_ean
231
231
  values = regexify(/\d{7}/)
232
- check_digit = 10 - values.split(//).each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
232
+ check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
233
233
  values << (check_digit == 10 ? 0 : check_digit).to_s
234
234
  end
235
235
 
236
236
  def generate_base13_ean
237
237
  values = regexify(/\d{12}/)
238
- check_digit = 10 - values.split(//).each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
238
+ check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
239
239
  values << (check_digit == 10 ? 0 : check_digit).to_s
240
240
  end
241
241
 
@@ -243,13 +243,13 @@ module Faker
243
243
  EAN_CHECK_DIGIT13 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3].freeze
244
244
 
245
245
  def rut_verificator_digit(rut)
246
- total = rut.to_s.rjust(8, '0').split(//).zip(%w[3 2 7 6 5 4 3 2]).collect { |a, b| a.to_i * b.to_i }.inject(:+)
246
+ total = rut.to_s.rjust(8, '0').chars.zip(%w[3 2 7 6 5 4 3 2]).collect { |a, b| a.to_i * b.to_i }.inject(:+)
247
247
  (11 - total % 11).to_s.gsub(/10/, 'k').gsub(/11/, '0')
248
248
  end
249
249
 
250
250
  def generate_nric_check_alphabet(values, prefix)
251
251
  weight = %w[2 7 6 5 4 3 2]
252
- total = values.split(//).zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
252
+ total = values.chars.zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
253
253
  total += 4 if prefix == 'T'
254
254
  %w[A B C D E F G H I Z J][10 - total % 11]
255
255
  end
@@ -296,7 +296,7 @@ module Faker
296
296
  result = Array.new(3) { rand(1..9) } + Array.new(7) { rand(10) }
297
297
  break if (weight_sum(result, weights) % 11) == result[9]
298
298
  end
299
- result.join('')
299
+ result.join
300
300
  end
301
301
 
302
302
  ##
@@ -321,7 +321,7 @@ module Faker
321
321
  random_digits = Array.new(length) { rand(10) }
322
322
  break if collect_regon_sum(random_digits) == random_digits.last
323
323
  end
324
- random_digits.join('')
324
+ random_digits.join
325
325
  end
326
326
 
327
327
  ##
@@ -459,7 +459,7 @@ module Faker
459
459
  def luhn_algorithm(number)
460
460
  multiplications = []
461
461
 
462
- number.to_s.reverse.split(//).each_with_index do |digit, i|
462
+ number.to_s.reverse.chars.each_with_index do |digit, i|
463
463
  multiplications << if i.even?
464
464
  digit.to_i * 2
465
465
  else
@@ -553,7 +553,7 @@ module Faker
553
553
  def spanish_cif_control_digit(organization_type, code)
554
554
  letters = %w[J A B C D E F G H I]
555
555
 
556
- control = code.split('').each_with_index.inject(0) do |sum, (value, index)|
556
+ control = code.chars.each_with_index.inject(0) do |sum, (value, index)|
557
557
  if (index + 1).even?
558
558
  sum + value.to_i
559
559
  else
@@ -57,9 +57,9 @@ module Faker
57
57
  # @example
58
58
  # Faker::File.mime_type #=> "application/pdf"
59
59
  #
60
- # @faker.version 1.6.4
61
- def mime_type
62
- fetch('file.mime_type')
60
+ # @faker.version next
61
+ def mime_type(media_type: nil)
62
+ media_type ? fetch("file.mime_type.#{media_type}") : sample(sample(translate('faker.file.mime_type').values))
63
63
  end
64
64
 
65
65
  # rubocop:disable Metrics/ParameterLists
@@ -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
@@ -97,6 +97,20 @@ module Faker
97
97
  def stock_market
98
98
  fetch('finance.stock_market')
99
99
  end
100
+
101
+ ##
102
+ # Returns a random condominium fiscal code.
103
+ #
104
+ # @param country [String] Two capital letter country code to use for the vat number.
105
+ # @return [String]
106
+ #
107
+ # @example
108
+ # Faker::Finance.condominium_fiscal_code #=> "012345678"
109
+ #
110
+ # @faker.version next
111
+ def condominium_fiscal_code(country: 'IT')
112
+ numerify(fetch("finance.condominium_fiscal_code.#{country}"))
113
+ end
100
114
  end
101
115
  end
102
116
  end
@@ -219,6 +219,72 @@ module Faker
219
219
  "#{prefix}#{digits}#{checksum_digit}"
220
220
  end
221
221
 
222
+ ##
223
+ # Produces a random Danish ID Number (CPR number).
224
+ # CPR number is 10 digits. Digit 1-6 is the birthdate (format "DDMMYY").
225
+ # Digit 7-10 is a sequence number.
226
+ # Digit 7 digit is a control digit that determines the century of birth.
227
+ # Digit 10 reveals the gender: # even is female, odd is male.
228
+ #
229
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
230
+ # @param birthday [Date] Specifies the birthday for the id number.
231
+ # @param gender [Symbol] Specifies the gender for the id number. Must be one :male or :female if present.
232
+ # @return [String]
233
+ #
234
+ # @example
235
+ # Faker::IDNumber.danish_id_number #=> "0503909980"
236
+ # Faker::IDNumber.danish_id_number(formatted: true) #=> "050390-9980"
237
+ # Faker::IDNumber.danish_id_number(birthday: Date.new(1990, 3, 5)) #=> "0503909980"
238
+ # Faker::IDNumber.danish_id_number(gender: :female) #=> "0503909980"
239
+ #
240
+ # @faker.version next
241
+ def danish_id_number(formatted: false, birthday: Faker::Date.birthday, gender: nil)
242
+ valid_control_digits = danish_control_digits(birthday)
243
+ control_digit = sample(valid_control_digits)
244
+ digits = (0..9).to_a
245
+ gender = gender.to_sym if gender.respond_to?(:to_sym)
246
+ gender_digit = case gender
247
+ when nil
248
+ sample(digits)
249
+ when :male
250
+ sample(digits.select(&:odd?))
251
+ when :female
252
+ sample(digits.select(&:even?))
253
+ else
254
+ raise ArgumentError, "Invalid gender #{gender}. Must be one of male, female, or be omitted."
255
+ end
256
+
257
+ [
258
+ birthday.strftime('%d%m%y'),
259
+ formatted ? '-' : '',
260
+ control_digit,
261
+ Faker::Number.number(digits: 2),
262
+ gender_digit
263
+ ].join
264
+ end
265
+
266
+ ##
267
+ # Produces a random French social security number (INSEE number).
268
+ #
269
+ # @return [String]
270
+ #
271
+ # @example
272
+ # Faker::IDNumber.french_insee_number #=> "53290236-H"
273
+ #
274
+ # @faker.version next
275
+ def french_insee_number
276
+ num = [
277
+ [1, 2].sample(random: Faker::Config.random), # gender
278
+ Faker::Number.between(from: 0, to: 99).to_s.rjust(2, '0'), # year of birth
279
+ Faker::Number.between(from: 1, to: 12).to_s.rjust(2, '0'), # month of birth
280
+ Faker::Number.number(digits: 5), # place of birth
281
+ Faker::Number.number(digits: 3) # order number
282
+ ].join
283
+ mod = num.to_i % 97
284
+ check = (97 - mod).to_s.rjust(2, '0')
285
+ "#{num}#{check}"
286
+ end
287
+
222
288
  private
223
289
 
224
290
  def croatian_id_checksum_digit(digits)
@@ -266,7 +332,7 @@ module Faker
266
332
  .with_index { |_, i| (i + 1).odd? }
267
333
 
268
334
  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
335
+ even_digits_times_two = (even_digits.join.to_i * 2).to_s
270
336
  sum_of_even_digits = even_digits_times_two.chars.map(&:to_i).reduce(:+)
271
337
 
272
338
  total_sum = sum_of_odd_digits + sum_of_even_digits
@@ -305,6 +371,45 @@ module Faker
305
371
  digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
306
372
  end
307
373
 
374
+ def danish_control_digits(birthday)
375
+ year = birthday.year
376
+ century = year.to_s.slice(0, 2).to_i
377
+ year_digits = year.to_s.slice(2, 2).to_i
378
+ error_message = "Invalid birthday: #{birthday}. Danish CPR numbers are only distributed to persons born between 1858 and 2057."
379
+
380
+ case century
381
+ when 18
382
+ # If 5, 6, 7 or 8 and the year numbers are greater than or equal to 58, you were born in 18XX.
383
+ case year_digits
384
+ when 58..99
385
+ [5, 6, 7, 8]
386
+ else
387
+ raise ArgumentError, error_message
388
+ end
389
+ when 19
390
+ # If 0, 1, 2 or 3, you are always born in 19XX.
391
+ # If 4 or 9, you are born in 19XX if the year digits are greater than 36.
392
+
393
+ case year_digits
394
+ when 0..36
395
+ [0, 1, 2, 3]
396
+ else # 37..99
397
+ [0, 1, 2, 3, 4, 9]
398
+ end
399
+ else
400
+ # If 4, 5, 6, 7, 8 or 9 and the year digits are less than or equal to 36, you were born in 20XX.
401
+ # 5, 6, 7 and 8 are not distributed to persons, with year digits from and including 37 to and including 57.
402
+ case year_digits
403
+ when 0..36
404
+ [4, 5, 6, 7, 8, 9]
405
+ when 37..57
406
+ [5, 6, 7, 8]
407
+ else
408
+ raise ArgumentError, error_message
409
+ end
410
+ end
411
+ end
412
+
308
413
  def _translate(key)
309
414
  parse("id_number.#{key}")
310
415
  end
@@ -174,6 +174,8 @@ module Faker
174
174
  keywords << :special_characters if legacy_special_characters != NOT_GIVEN
175
175
  end
176
176
 
177
+ raise ArgumentError, 'Password of length 1 can not have both mixed case and special characters' if min_length <= 1 && mix_case && special_characters
178
+
177
179
  min_alpha = mix_case && min_length > 1 ? 2 : 0
178
180
  temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
179
181
  diff_length = max_length - min_length
@@ -200,6 +202,8 @@ module Faker
200
202
  end
201
203
  end
202
204
 
205
+ temp[rand(temp.size - 1)] = Lorem.characters(number: 1, min_alpha: 1).upcase if mix_case && special_characters && !temp.match(/[A-z]+/)
206
+
203
207
  temp
204
208
  end
205
209
  # rubocop:enable Metrics/ParameterLists
@@ -266,7 +270,7 @@ module Faker
266
270
  # @example
267
271
  # Faker::Internet.domain_word #=> "senger"
268
272
  def domain_word
269
- with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
273
+ with_locale(:en) { Char.prepare(Company.name.split.first) }
270
274
  end
271
275
 
272
276
  ## Returns the domain suffix e.g. com, org, co, biz, info etc.
@@ -609,10 +613,10 @@ module Faker
609
613
  Array('0'..'9'),
610
614
  Array('A'..'Z'),
611
615
  Array('a'..'z'),
612
- "!#$%&'*+-/=?^_`{|}~.".split(//)
616
+ "!#$%&'*+-/=?^_`{|}~.".chars
613
617
  ].flatten
614
618
 
615
- local_part.split(//).map do |char|
619
+ local_part.chars.map do |char|
616
620
  char_range.include?(char) ? char : '#'
617
621
  end.join
618
622
  end
@@ -27,7 +27,7 @@ module Faker
27
27
  # @faker.version 1.8.0
28
28
  def emphasis
29
29
  paragraph = Faker::Lorem.paragraph(sentence_count: 3)
30
- words = paragraph.split(' ')
30
+ words = paragraph.split
31
31
  position = rand(0..words.length - 1)
32
32
  formatting = fetch('markdown.emphasis')
33
33
  words[position] = "#{formatting}#{words[position]}#{formatting}"
@@ -50,7 +50,7 @@ module Faker
50
50
  number.times do |i|
51
51
  result << "#{i}. #{Faker::Lorem.sentence(word_count: 1)} \n"
52
52
  end
53
- result.join('')
53
+ result.join
54
54
  end
55
55
 
56
56
  ##
@@ -69,7 +69,7 @@ module Faker
69
69
  number.times do |_i|
70
70
  result << "* #{Faker::Lorem.sentence(word_count: 1)} \n"
71
71
  end
72
- result.join('')
72
+ result.join
73
73
  end
74
74
 
75
75
  ##
@@ -21,7 +21,7 @@ module Faker
21
21
  .chars
22
22
  .insert(3, ' ')
23
23
  .insert(7, ' ')
24
- .join('')
24
+ .join
25
25
  end
26
26
 
27
27
  ##
@@ -9,7 +9,7 @@ module Faker
9
9
  VIN_LETTERS = 'ABCDEFGHJKLMNPRSTUVWXYZ'
10
10
  VIN_MAP = '0123456789X'
11
11
  VIN_WEIGHTS = '8765432X098765432'
12
- VIN_REGEX = /^([A-HJ-NPR-Z0-9]){3}[A-HJ-NPR-Z0-9]{5}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-0]{1}[A-HJ-NPR-Z0-9]{1}\d{5}$/.freeze
12
+ VIN_REGEX = /^([A-HJ-NPR-Z0-9]){3}[A-HJ-NPR-Z0-9]{5}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-]{1}[A-HJ-NPR-Z0-9]{1}\d{5}$/.freeze
13
13
  SG_CHECKSUM_WEIGHTS = [3, 14, 2, 12, 2, 11, 1].freeze
14
14
  SG_CHECKSUM_CHARS = 'AYUSPLJGDBZXTRMKHEC'
15
15
 
@@ -297,6 +297,19 @@ module Faker
297
297
  "#{plate_number}#{singapore_checksum(plate_number)}"
298
298
  end
299
299
 
300
+ ##
301
+ # Produces a car version
302
+ #
303
+ # @return [String]
304
+ #
305
+ # @example
306
+ # Faker::Vehicle.version #=> "40 TFSI Premium"
307
+ #
308
+ # @faker.version next
309
+ def version
310
+ fetch('vehicle.version')
311
+ end
312
+
300
313
  private
301
314
 
302
315
  def first_eight(number)
@@ -320,7 +333,7 @@ module Faker
320
333
  end
321
334
 
322
335
  def vin_char_to_number(char)
323
- index = VIN_LETTERS.split('').index(char)
336
+ index = VIN_LETTERS.chars.index(char)
324
337
 
325
338
  return char.to_i if index.nil?
326
339
 
@@ -328,14 +341,14 @@ module Faker
328
341
  end
329
342
 
330
343
  def singapore_checksum(plate_number)
331
- padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').split('')
332
- padded_digits = format('%04d', plate_number[/\d+/]).split('').map(&:to_i)
344
+ padded_alphabets = format('%3s', plate_number[/^[A-Z]+/]).tr(' ', '-').chars
345
+ padded_digits = format('%04d', plate_number[/\d+/]).chars.map(&:to_i)
333
346
  sum = [*padded_alphabets, *padded_digits].each_with_index.reduce(0) do |memo, (char, i)|
334
347
  value = char.is_a?(Integer) ? char : char.ord - 64
335
348
  memo + (SG_CHECKSUM_WEIGHTS[i] * value)
336
349
  end
337
350
 
338
- SG_CHECKSUM_CHARS.split('')[sum % 19]
351
+ SG_CHECKSUM_CHARS.chars[sum % 19]
339
352
  end
340
353
  end
341
354
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class VulnerabilityIdentifier < Base
5
+ class << self
6
+ ##
7
+ # Produces a Common Vulnerabilities and Exposures (CVE) identifier.
8
+ #
9
+ # @param year [Integer] The year-part of the CVE identifier (defaults to the current year)
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::VulnerabilityIdentifier.cve #=> "CVE-2021-1337"
14
+ # Faker::VulnerabilityIdentifier.cve(year: 1999) #=> "CVE-1999-0523"
15
+ #
16
+ # @faker.version next
17
+ def cve(year: ::Date.today.year)
18
+ index = rand_in_range(1, 99_999).to_s.rjust(4, '0')
19
+ "CVE-#{year}-#{index}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -83,14 +83,14 @@ module Faker
83
83
  end
84
84
 
85
85
  def from_eras(*input_eras, field:)
86
- selected_eras = (ERAS & input_eras).yield_self do |selected|
86
+ selected_eras = (ERAS & input_eras).then do |selected|
87
87
  selected.empty? ? eras : selected
88
88
  end.dup
89
89
  yield(selected_eras) if block_given?
90
90
 
91
91
  raise UnavailableInEra, "#{field} is unavailable in the selected eras." if selected_eras.empty?
92
92
 
93
- selected_eras.sample.yield_self do |era|
93
+ selected_eras.sample.then do |era|
94
94
  fetch("kamen_rider.#{era}.#{field}")
95
95
  end
96
96
  end
@@ -79,7 +79,7 @@ module Faker
79
79
  #
80
80
  # @faker.version 1.8.5
81
81
  def akuma_no_mi
82
- fetch('one_piece.akumas_no_mi')
82
+ fetch('one_piece.akuma_no_mi')
83
83
  end
84
84
  end
85
85
  end