faker 2.21.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +58 -0
- data/README.md +4 -6
- data/lib/faker/blockchain/aeternity.rb +1 -1
- data/lib/faker/blockchain/ethereum.rb +1 -1
- data/lib/faker/blockchain/tezos.rb +1 -1
- data/lib/faker/default/{faker_adjective.rb → adjective.rb} +0 -0
- data/lib/faker/default/bank.rb +4 -4
- data/lib/faker/default/chile_rut.rb +8 -4
- data/lib/faker/default/code.rb +7 -7
- data/lib/faker/default/company.rb +4 -4
- data/lib/faker/default/file.rb +3 -3
- data/lib/faker/default/finance.rb +16 -2
- data/lib/faker/default/id_number.rb +106 -1
- data/lib/faker/default/internet.rb +24 -3
- data/lib/faker/default/markdown.rb +3 -3
- data/lib/faker/default/nhs.rb +1 -1
- data/lib/faker/default/vehicle.rb +18 -5
- data/lib/faker/default/vulnerability_identifier.rb +23 -0
- data/lib/faker/japanese_media/kamen_rider.rb +2 -2
- data/lib/faker/japanese_media/one_piece.rb +1 -1
- data/lib/faker/sports/mountaineering.rb +22 -0
- data/lib/faker/sports/sport.rb +110 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +15 -10
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/unique_generator.rb +13 -11
- data/lib/locales/en/australia.yml +3 -4
- data/lib/locales/en/computer.yml +23 -4
- data/lib/locales/en/dota.yml +113 -0
- data/lib/locales/en/file.yml +9 -1
- data/lib/locales/en/finance.yml +3 -1
- data/lib/locales/en/internet.yml +29 -0
- data/lib/locales/en/mountaineering.yml +14 -0
- data/lib/locales/en/one_piece.yml +1 -1
- data/lib/locales/en/sport.yml +121 -0
- data/lib/locales/en/vehicle.yml +2809 -75
- data/lib/locales/en-AU.yml +1 -1
- data/lib/locales/ja/adjective.yml +148 -0
- data/lib/locales/ja/dog.yml +1 -0
- data/lib/locales/pl.yml +1 -1
- metadata +18 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d8cd66a58c224a6a003a614df1b81c934ddf8eb4033d51f4cc4df2a0b377193
|
4
|
+
data.tar.gz: f761e03f47cd4e7b04d5c5f70e9639576e628613b5f3eca232b21a38e3aa810d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a902462978f950d791e6ba96b1ce48fdd3b2db3e1336871a48b98410c6dd5f6f29397f8763f1c3786398162a140e1f664849ee6469c538d8d68d81d0c875b35
|
7
|
+
data.tar.gz: c4996e30be72c6f8b747e236bc139585695c9e554982794ab5b78961a9944b632ae4c408218b47a5799e015d536164356538dbf748a1290ff69353e1e3aa390a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,63 @@
|
|
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
|
+
|
30
|
+
## [v2.22.0](https://github.com/faker-ruby/faker/tree/v2.22.0) (2022-07-28)
|
31
|
+
|
32
|
+
## Bug/Fixes
|
33
|
+
|
34
|
+
- [PR #2500](https://github.com/faker-ruby/faker/pull/2500) Fix: Duplicate array before concatenating [@mattr](https://github.com/mattr)
|
35
|
+
- [PR #2488](https://github.com/faker-ruby/faker/pull/2488) Fixed random selection issue [@sudeeptarlekar](https://github.com/sudeeptarlekar)
|
36
|
+
- [PR #2475](https://github.com/faker-ruby/faker/pull/2475) Update regex used for Faker::Vehicle#vin [@erayalkis](https://github.com/erayalkis)
|
37
|
+
|
38
|
+
## Chores
|
39
|
+
|
40
|
+
- [PR #2513](https://github.com/faker-ruby/faker/pull/2513) Remove broken docs [@vbrazo](https://github.com/vbrazo)
|
41
|
+
- [PR #2502](https://github.com/faker-ruby/faker/pull/2502) Update actions/checkout version in GitHub actions [@jdufresne](https://github.com/jdufresne)
|
42
|
+
- [PR #2501](https://github.com/faker-ruby/faker/pull/2501) Make ReadMe more consise [@jenniferdewan](https://github.com/jenniferdewan)
|
43
|
+
- [PR #2489](https://github.com/faker-ruby/faker/pull/2489) Change a filename to follow naming conventions [@yasuhiron777](https://github.com/yasuhiron777)
|
44
|
+
|
45
|
+
## Feature Request
|
46
|
+
|
47
|
+
- [PR #2477](https://github.com/faker-ruby/faker/pull/2477) feat: add bot_user_agent method for generate web crawle's user agents [@a-chacon](https://github.com/a-chacon)
|
48
|
+
- [PR #2465](https://github.com/faker-ruby/faker/pull/2465) Add a new sports section for mountaineers [@LeviLong01](https://github.com/LeviLong01)
|
49
|
+
|
50
|
+
## Update locales
|
51
|
+
|
52
|
+
- [PR #2509](https://github.com/faker-ruby/faker/pull/2509) Add all Dota 2 heroes [@JCFarrow](https://github.com/JCFarrow)
|
53
|
+
- [PR #2507](https://github.com/faker-ruby/faker/pull/2507) Update dog.yml [@Kedaruma-Bond](https://github.com/Kedaruma-Bond)
|
54
|
+
- [PR #2503](https://github.com/faker-ruby/faker/pull/2503) Update pl.yml [@marek-witkowski](https://github.com/marek-witkowski)
|
55
|
+
- [PR #2499](https://github.com/faker-ruby/faker/pull/2499) Fix: Use pattern to define Australian cell phone formats [@mattr](https://github.com/mattr)
|
56
|
+
- [PR #2497](https://github.com/faker-ruby/faker/pull/2497) Fix typos in Australia [@mattr](https://github.com/mattr)
|
57
|
+
- [PR #2490](https://github.com/faker-ruby/faker/pull/2490) Added Japanese adjective translations [@yasuhiron777](https://github.com/yasuhiron777)
|
58
|
+
|
59
|
+
------------------------------------------------------------------------------
|
60
|
+
|
3
61
|
## [v2.21.0](https://github.com/faker-ruby/faker/tree/v2.21.0) (2022-05-12)
|
4
62
|
|
5
63
|
## Bug/Fixes
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
[](https://inch-ci.org/github/faker-ruby/faker)
|
7
7
|
[](https://codeclimate.com/github/stympy/faker/test_coverage)
|
8
8
|
[](https://codeclimate.com/github/stympy/faker/maintainability)
|
9
|
-
[](https://dependabot.com/compatibility-score.html?dependency-name=faker&package-manager=bundler&version-scheme=semver)
|
10
9
|
|
11
10
|
This gem is a port of [Perl's Data::Faker library](https://metacpan.org/pod/Data::Faker) that generates fake data.
|
12
11
|
|
@@ -218,6 +217,7 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'mast
|
|
218
217
|
- [Faker::University](doc/default/university.md)
|
219
218
|
- [Faker::Vehicle](doc/default/vehicle.md)
|
220
219
|
- [Faker::Verbs](doc/default/verbs.md)
|
220
|
+
- [Faker::VulnerabilityIdentifier](doc/default/vulnerability_identifier.md)
|
221
221
|
- [Faker::WorldCup](doc/default/world_cup.md)
|
222
222
|
|
223
223
|
### Blockchain
|
@@ -355,11 +355,9 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'mast
|
|
355
355
|
- [Faker::TvShows::VentureBros](doc/tv_shows/venture_bros.md)
|
356
356
|
|
357
357
|
## Customization
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
formats (US postal codes are NNNNN while UK postal codes are AAN NAA),
|
362
|
-
allowing you to get different formats by switching locales.
|
358
|
+
You may want Faker to print information depending on your location in the world.
|
359
|
+
To assist you in this, Faker uses I18n gem to store strings and formats to
|
360
|
+
represent the names and postal codes of the area of your choosing.
|
363
361
|
Just set the locale you want as shown below, and Faker will take care of the rest.
|
364
362
|
|
365
363
|
```ruby
|
@@ -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.
|
64
|
+
length.times { var << sample(shuffle(hex_alphabet.chars)) }
|
65
65
|
var
|
66
66
|
end
|
67
67
|
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
|
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
|
File without changes
|
data/lib/faker/default/bank.rb
CHANGED
@@ -23,7 +23,7 @@ module Faker
|
|
23
23
|
|
24
24
|
output = ''
|
25
25
|
|
26
|
-
output += rand.to_s[2
|
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.
|
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.
|
198
|
-
denominator = routing_num.
|
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.
|
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
|
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
|
-
|
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
|
data/lib/faker/default/code.rb
CHANGED
@@ -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
|
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.
|
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.
|
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.
|
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').
|
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.
|
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.
|
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.
|
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
|
data/lib/faker/default/file.rb
CHANGED
@@ -57,9 +57,9 @@ module Faker
|
|
57
57
|
# @example
|
58
58
|
# Faker::File.mime_type #=> "application/pdf"
|
59
59
|
#
|
60
|
-
# @faker.version
|
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]/, '').
|
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.
|
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
|
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
|
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.
|
@@ -521,6 +525,23 @@ module Faker
|
|
521
525
|
sample(agents)
|
522
526
|
end
|
523
527
|
|
528
|
+
##
|
529
|
+
# Generate Web Crawler's user agents
|
530
|
+
#
|
531
|
+
# @return [String]
|
532
|
+
#
|
533
|
+
# @param vendor [String] Name of vendor, supported vendors are googlebot, bingbot, duckduckbot, baiduspider, yandexbot
|
534
|
+
#
|
535
|
+
# @example
|
536
|
+
# Faker::Internet.bot_user_agent #=> "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
|
537
|
+
# 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"
|
538
|
+
# 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"
|
539
|
+
def bot_user_agent(vendor: nil)
|
540
|
+
agent_hash = translate('faker.internet.bot_user_agent')
|
541
|
+
agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
|
542
|
+
sample(agents)
|
543
|
+
end
|
544
|
+
|
524
545
|
##
|
525
546
|
# Generated universally unique identifier
|
526
547
|
#
|
@@ -592,10 +613,10 @@ module Faker
|
|
592
613
|
Array('0'..'9'),
|
593
614
|
Array('A'..'Z'),
|
594
615
|
Array('a'..'z'),
|
595
|
-
"!#$%&'*+-/=?^_`{|}~.".
|
616
|
+
"!#$%&'*+-/=?^_`{|}~.".chars
|
596
617
|
].flatten
|
597
618
|
|
598
|
-
local_part.
|
619
|
+
local_part.chars.map do |char|
|
599
620
|
char_range.include?(char) ? char : '#'
|
600
621
|
end.join
|
601
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
|
##
|
data/lib/faker/default/nhs.rb
CHANGED
@@ -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-Z0-9]{3}[A-Z0-9]{5}[A-Z0-9]{1}[A-Z0-9]{1}[A-Z0-
|
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.
|
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(' ', '-').
|
332
|
-
padded_digits = format('%04d', plate_number[/\d+/]).
|
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.
|
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
|