faker 2.22.0 → 3.0.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 +88 -7
- data/History.md +1 -1
- data/README.md +11 -5
- 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/books/dune.rb +2 -10
- data/lib/faker/books/lovecraft.rb +7 -38
- data/lib/faker/default/address.rb +5 -25
- data/lib/faker/default/alphanumeric.rb +2 -8
- data/lib/faker/default/app.rb +1 -10
- data/lib/faker/default/avatar.rb +1 -12
- data/lib/faker/default/bank.rb +9 -17
- data/lib/faker/default/boolean.rb +1 -4
- data/lib/faker/default/chile_rut.rb +8 -14
- data/lib/faker/default/code.rb +10 -23
- data/lib/faker/default/color.rb +77 -6
- data/lib/faker/default/commerce.rb +3 -17
- data/lib/faker/default/company.rb +6 -14
- data/lib/faker/default/crypto_coin.rb +3 -15
- data/lib/faker/default/date.rb +5 -38
- data/lib/faker/default/demographic.rb +1 -5
- data/lib/faker/default/driving_licence.rb +1 -11
- data/lib/faker/default/file.rb +5 -24
- data/lib/faker/default/fillmurray.rb +1 -10
- data/lib/faker/default/finance.rb +17 -7
- data/lib/faker/default/hipster.rb +6 -45
- data/lib/faker/default/id_number.rb +108 -11
- data/lib/faker/default/internet.rb +17 -71
- data/lib/faker/default/invoice.rb +3 -16
- data/lib/faker/default/json.rb +2 -20
- data/lib/faker/default/lorem.rb +9 -66
- data/lib/faker/default/lorem_flickr.rb +4 -32
- data/lib/faker/default/lorem_pixel.rb +4 -10
- data/lib/faker/default/markdown.rb +4 -9
- data/lib/faker/default/measurement.rb +8 -40
- data/lib/faker/default/name.rb +1 -5
- data/lib/faker/default/nhs.rb +2 -6
- data/lib/faker/default/number.rb +10 -55
- data/lib/faker/default/omniauth.rb +5 -39
- data/lib/faker/default/phone_number.rb +1 -5
- data/lib/faker/default/placeholdit.rb +1 -12
- data/lib/faker/default/relationship.rb +1 -5
- data/lib/faker/default/source.rb +3 -16
- data/lib/faker/default/string.rb +1 -5
- data/lib/faker/default/stripe.rb +4 -20
- data/lib/faker/default/time.rb +4 -32
- data/lib/faker/default/twitter.rb +3 -17
- data/lib/faker/default/types.rb +5 -27
- data/lib/faker/default/vehicle.rb +21 -21
- data/lib/faker/default/vulnerability_identifier.rb +23 -0
- data/lib/faker/default/world_cup.rb +2 -11
- data/lib/faker/games/dota.rb +1 -5
- data/lib/faker/games/tarkov.rb +205 -0
- data/lib/faker/japanese_media/kamen_rider.rb +2 -2
- data/lib/faker/japanese_media/one_piece.rb +1 -1
- data/lib/faker/movies/hackers.rb +48 -0
- data/lib/faker/movies/star_wars.rb +1 -5
- data/lib/faker/sports/sport.rb +110 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +15 -63
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/unique_generator.rb +13 -11
- data/lib/locales/en/computer.yml +23 -4
- data/lib/locales/en/file.yml +9 -1
- data/lib/locales/en/finance.yml +3 -1
- data/lib/locales/en/hackers.yml +53 -0
- data/lib/locales/en/heroes.yml +2 -2
- data/lib/locales/en/one_piece.yml +1 -1
- data/lib/locales/en/opera.yml +1 -1
- data/lib/locales/en/overwatch.yml +5 -7
- data/lib/locales/en/source.yml +5 -0
- data/lib/locales/en/sport.yml +130 -0
- data/lib/locales/en/tarkov.yml +593 -0
- data/lib/locales/en/vehicle.yml +2809 -75
- data/lib/locales/en-CA.yml +1 -0
- data/lib/locales/es-AR.yml +2 -2
- data/lib/locales/fi-FI.yml +2 -1
- data/lib/locales/fr/ancient.yml +141 -0
- data/lib/locales/hy.yml +1 -1
- data/lib/locales/th.yml +76 -76
- metadata +50 -19
@@ -18,12 +18,7 @@ module Faker
|
|
18
18
|
# Faker::ChileRut.rut(min_rut: 20890156, fixed: true) #=> 20890156
|
19
19
|
#
|
20
20
|
# @faker.version 1.9.2
|
21
|
-
def rut(
|
22
|
-
warn_for_deprecated_arguments do |keywords|
|
23
|
-
keywords << :min_rut if legacy_min_rut != NOT_GIVEN
|
24
|
-
keywords << :fixed if legacy_fixed != NOT_GIVEN
|
25
|
-
end
|
26
|
-
|
21
|
+
def rut(min_rut: 1, fixed: false)
|
27
22
|
@last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
|
28
23
|
end
|
29
24
|
|
@@ -37,7 +32,7 @@ module Faker
|
|
37
32
|
#
|
38
33
|
# @faker.version 1.9.2
|
39
34
|
def dv
|
40
|
-
split_reversed_rut = @last_rut.to_s.reverse.
|
35
|
+
split_reversed_rut = @last_rut.to_s.reverse.chars
|
41
36
|
seq = [2, 3, 4, 5, 6, 7]
|
42
37
|
i = 0
|
43
38
|
digit_sum = split_reversed_rut.reduce(0) do |sum, n|
|
@@ -82,14 +77,13 @@ module Faker
|
|
82
77
|
# Faker::ChileRut.full_rut(min_rut: 20890156) #=> "30686957-4"
|
83
78
|
# Faker::ChileRut.full_rut(min_rut: 30686957, fixed: true) #=> "30686957-4"
|
84
79
|
#
|
85
|
-
# @faker.version
|
86
|
-
def full_rut(
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
# @faker.version next
|
81
|
+
def full_rut(min_rut: 0, fixed: false, formatted: false)
|
82
|
+
if formatted
|
83
|
+
"#{rut(min_rut: min_rut, fixed: fixed).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse}-#{dv}"
|
84
|
+
else
|
85
|
+
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
|
90
86
|
end
|
91
|
-
|
92
|
-
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
|
93
87
|
end
|
94
88
|
|
95
89
|
attr_reader :last_rut
|
data/lib/faker/default/code.rb
CHANGED
@@ -29,11 +29,7 @@ module Faker
|
|
29
29
|
# Faker::Code.isbn #=> "170366802-2"
|
30
30
|
#
|
31
31
|
# @faker.version 2.2.0
|
32
|
-
def isbn(
|
33
|
-
warn_for_deprecated_arguments do |keywords|
|
34
|
-
keywords << :base if legacy_base != NOT_GIVEN
|
35
|
-
end
|
36
|
-
|
32
|
+
def isbn(base: 10)
|
37
33
|
case base
|
38
34
|
when 10 then generate_base10_isbn
|
39
35
|
when 13 then generate_base13_isbn
|
@@ -53,11 +49,7 @@ module Faker
|
|
53
49
|
# Faker::Code.ean #=> "9941880131907"
|
54
50
|
#
|
55
51
|
# @faker.version 2.2.0
|
56
|
-
def ean(
|
57
|
-
warn_for_deprecated_arguments do |keywords|
|
58
|
-
keywords << :base if legacy_base != NOT_GIVEN
|
59
|
-
end
|
60
|
-
|
52
|
+
def ean(base: 13)
|
61
53
|
case base
|
62
54
|
when 8 then generate_base8_ean
|
63
55
|
when 13 then generate_base13_ean
|
@@ -99,15 +91,10 @@ module Faker
|
|
99
91
|
# Faker::Code.nric #=> "S6372958B"
|
100
92
|
#
|
101
93
|
# @faker.version 2.2.0
|
102
|
-
def nric(
|
103
|
-
warn_for_deprecated_arguments do |keywords|
|
104
|
-
keywords << :min_age if legacy_min_age != NOT_GIVEN
|
105
|
-
keywords << :max_age if legacy_max_age != NOT_GIVEN
|
106
|
-
end
|
107
|
-
|
94
|
+
def nric(min_age: 18, max_age: 65)
|
108
95
|
birthyear = Date.birthday(min_age: min_age, max_age: max_age).year
|
109
96
|
prefix = birthyear < 2000 ? 'S' : 'T'
|
110
|
-
values = birthyear.to_s[-2
|
97
|
+
values = birthyear.to_s[-2..]
|
111
98
|
values << regexify(/\d{5}/)
|
112
99
|
check_alpha = generate_nric_check_alphabet(values, prefix)
|
113
100
|
"#{prefix}#{values}#{check_alpha}"
|
@@ -206,7 +193,7 @@ module Faker
|
|
206
193
|
str[len - 1] = (10 - (sum % 10)) % 10
|
207
194
|
|
208
195
|
# Output the IMEI value.
|
209
|
-
str.join
|
196
|
+
str.join
|
210
197
|
end
|
211
198
|
|
212
199
|
def generate_base10_isbn
|
@@ -222,20 +209,20 @@ module Faker
|
|
222
209
|
end
|
223
210
|
|
224
211
|
def sum(values)
|
225
|
-
values.
|
212
|
+
values.chars.each_with_index.inject(0) do |sum, (value, index)|
|
226
213
|
sum + yield(value, index)
|
227
214
|
end
|
228
215
|
end
|
229
216
|
|
230
217
|
def generate_base8_ean
|
231
218
|
values = regexify(/\d{7}/)
|
232
|
-
check_digit = 10 - values.
|
219
|
+
check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
|
233
220
|
values << (check_digit == 10 ? 0 : check_digit).to_s
|
234
221
|
end
|
235
222
|
|
236
223
|
def generate_base13_ean
|
237
224
|
values = regexify(/\d{12}/)
|
238
|
-
check_digit = 10 - values.
|
225
|
+
check_digit = 10 - values.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
|
239
226
|
values << (check_digit == 10 ? 0 : check_digit).to_s
|
240
227
|
end
|
241
228
|
|
@@ -243,13 +230,13 @@ module Faker
|
|
243
230
|
EAN_CHECK_DIGIT13 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3].freeze
|
244
231
|
|
245
232
|
def rut_verificator_digit(rut)
|
246
|
-
total = rut.to_s.rjust(8, '0').
|
233
|
+
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
234
|
(11 - total % 11).to_s.gsub(/10/, 'k').gsub(/11/, '0')
|
248
235
|
end
|
249
236
|
|
250
237
|
def generate_nric_check_alphabet(values, prefix)
|
251
238
|
weight = %w[2 7 6 5 4 3 2]
|
252
|
-
total = values.
|
239
|
+
total = values.chars.zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
|
253
240
|
total += 4 if prefix == 'T'
|
254
241
|
%w[A B C D E F G H I Z J][10 - total % 11]
|
255
242
|
end
|
data/lib/faker/default/color.rb
CHANGED
@@ -3,17 +3,34 @@
|
|
3
3
|
module Faker
|
4
4
|
class Color < Base
|
5
5
|
class << self
|
6
|
+
LIGHTNESS_LOOKUP = {
|
7
|
+
light: 0.8,
|
8
|
+
dark: 0.2
|
9
|
+
}.freeze
|
6
10
|
##
|
7
11
|
# Produces a hex color code.
|
12
|
+
# Clients are able to specify the hue, saturation, or lightness of the required color.
|
13
|
+
# Alternatively a client can simply specify that they need a light or dark color.
|
14
|
+
#
|
15
|
+
# @param args [Hash, Symbol] Allows the client to specify what color should be return
|
8
16
|
#
|
9
17
|
# @return [String]
|
10
18
|
#
|
11
19
|
# @example
|
12
20
|
# Faker::Color.hex_color #=> "#31a785"
|
21
|
+
# @example
|
22
|
+
# Faker::Color.hex_color(hue: 118, saturation: 1, lightness: 0.53) #=> "#048700"
|
23
|
+
# @example
|
24
|
+
# Faker::Color.hex_color(:light) #=> "#FFEE99"
|
25
|
+
# @example
|
26
|
+
# Faker::Color.hex_color(:dark) #=> "#665500"
|
13
27
|
#
|
14
|
-
# @faker.version
|
15
|
-
def hex_color
|
16
|
-
|
28
|
+
# @faker.version next
|
29
|
+
def hex_color(args = nil)
|
30
|
+
hsl_hash = {}
|
31
|
+
hsl_hash = { lightness: LIGHTNESS_LOOKUP[args] } if %i[dark light].include?(args)
|
32
|
+
hsl_hash = args if args.is_a?(Hash)
|
33
|
+
hsl_to_hex(hsl_color(**hsl_hash))
|
17
34
|
end
|
18
35
|
|
19
36
|
##
|
@@ -51,14 +68,28 @@ module Faker
|
|
51
68
|
# Produces an array of floats representing an HSL color.
|
52
69
|
# The array is in the form of `[hue, saturation, lightness]`.
|
53
70
|
#
|
71
|
+
# @param hue [FLoat] Optional value to use for hue
|
72
|
+
# @param saturation [Float] Optional value to use for saturation
|
73
|
+
# @param lightness [Float] Optional value to use for lightness
|
54
74
|
# @return [Array(Float, Float, Float)]
|
55
75
|
#
|
56
76
|
# @example
|
57
77
|
# Faker::Color.hsl_color #=> [69.87, 0.66, 0.3]
|
78
|
+
# @example
|
79
|
+
# Faker::Color.hsl_color(hue: 70, saturation: 0.5, lightness: 0.8) #=> [70, 0.5, 0.8]
|
80
|
+
# @example
|
81
|
+
# Faker::Color.hsl_color(hue: 70) #=> [70, 0.66, 0.6]
|
82
|
+
# @example
|
83
|
+
# Faker::Color.hsl_color(saturation: 0.2) #=> [54, 0.2, 0.3]
|
84
|
+
# @example
|
85
|
+
# Faker::Color.hsl_color(lightness: 0.6) #=> [69.87, 0.66, 0.6]
|
58
86
|
#
|
59
|
-
# @faker.version
|
60
|
-
def hsl_color
|
61
|
-
|
87
|
+
# @faker.version next
|
88
|
+
def hsl_color(hue: nil, saturation: nil, lightness: nil)
|
89
|
+
valid_hue = hue || sample((0..360).to_a)
|
90
|
+
valid_saturation = saturation&.clamp(0, 1) || rand.round(2)
|
91
|
+
valid_lightness = lightness&.clamp(0, 1) || rand.round(2)
|
92
|
+
[valid_hue, valid_saturation, valid_lightness]
|
62
93
|
end
|
63
94
|
|
64
95
|
##
|
@@ -74,6 +105,46 @@ module Faker
|
|
74
105
|
def hsla_color
|
75
106
|
hsl_color << rand.round(1)
|
76
107
|
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
##
|
112
|
+
# Produces a hex code representation of an HSL color
|
113
|
+
#
|
114
|
+
# @param a_hsl_color [Array(Float, Float, Float)] The array that represents the HSL color
|
115
|
+
#
|
116
|
+
# @return [String]
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# hsl_to_hex([50, 100,80]) #=> #FFEE99
|
120
|
+
#
|
121
|
+
# @see https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB
|
122
|
+
# @see https://github.com/jpmckinney/color-generator/blob/master/lib/color-generator.rb
|
123
|
+
#
|
124
|
+
def hsl_to_hex(a_hsl_color)
|
125
|
+
h, s, l = a_hsl_color
|
126
|
+
c = (1 - (2 * l - 1).abs) * s
|
127
|
+
h_prime = h / 60
|
128
|
+
x = c * (1 - (h_prime % 2 - 1).abs)
|
129
|
+
m = l - 0.5 * c
|
130
|
+
|
131
|
+
rgb = case h_prime.to_i
|
132
|
+
when 0 # 0 <= H' < 1
|
133
|
+
[c, x, 0]
|
134
|
+
when 1 # 1 <= H' < 2
|
135
|
+
[x, c, 0]
|
136
|
+
when 2 # 2 <= H' < 3
|
137
|
+
[0, c, x]
|
138
|
+
when 3 # 3 <= H' < 4
|
139
|
+
[0, x, c]
|
140
|
+
when 4 # 4 <= H' < 5
|
141
|
+
[x, 0, c]
|
142
|
+
else # 5 <= H' < 6
|
143
|
+
[c, 0, x]
|
144
|
+
end.map { |value| ((value + m) * 255).round }
|
145
|
+
|
146
|
+
format('#%02x%02x%02x', rgb[0], rgb[1], rgb[2])
|
147
|
+
end
|
77
148
|
end
|
78
149
|
end
|
79
150
|
end
|
@@ -27,11 +27,7 @@ module Faker
|
|
27
27
|
# Faker::Commerce.promotion_code(digits: 2) #=> "AmazingPrice57"
|
28
28
|
#
|
29
29
|
# @faker.version 1.7.0
|
30
|
-
def promotion_code(
|
31
|
-
warn_for_deprecated_arguments do |keywords|
|
32
|
-
keywords << :digits if legacy_digits != NOT_GIVEN
|
33
|
-
end
|
34
|
-
|
30
|
+
def promotion_code(digits: 6)
|
35
31
|
[
|
36
32
|
fetch('commerce.promotion_code.adjective'),
|
37
33
|
fetch('commerce.promotion_code.noun'),
|
@@ -52,12 +48,7 @@ module Faker
|
|
52
48
|
# Faker::Commerce.department(max: 2, fixed_amount: true) #=> "Books & Tools"
|
53
49
|
#
|
54
50
|
# @faker.version 1.2.0
|
55
|
-
def department(
|
56
|
-
warn_for_deprecated_arguments do |keywords|
|
57
|
-
keywords << :max if legacy_max != NOT_GIVEN
|
58
|
-
keywords << :fixed_amount if legacy_fixed_amount != NOT_GIVEN
|
59
|
-
end
|
60
|
-
|
51
|
+
def department(max: 3, fixed_amount: false)
|
61
52
|
num = max if fixed_amount
|
62
53
|
num ||= 1 + rand(max)
|
63
54
|
|
@@ -112,12 +103,7 @@ module Faker
|
|
112
103
|
# Faker::Commerce.price(range: 0..10.0, as_string: true) #=> "2.18"
|
113
104
|
#
|
114
105
|
# @faker.version 1.2.0
|
115
|
-
def price(
|
116
|
-
warn_for_deprecated_arguments do |keywords|
|
117
|
-
keywords << :range if legacy_range != NOT_GIVEN
|
118
|
-
keywords << :as_string if legacy_as_string != NOT_GIVEN
|
119
|
-
end
|
120
|
-
|
106
|
+
def price(range: 0..100.0, as_string: false)
|
121
107
|
price = (rand(range) * 100).floor / 100.0
|
122
108
|
if as_string
|
123
109
|
price_parts = price.to_s.split('.')
|
@@ -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
|
##
|
@@ -309,11 +309,7 @@ module Faker
|
|
309
309
|
#
|
310
310
|
# @faker.version 1.9.1
|
311
311
|
# Get a random Polish register of national economy number. More info https://pl.wikipedia.org/wiki/REGON
|
312
|
-
def polish_register_of_national_economy(
|
313
|
-
warn_for_deprecated_arguments do |keywords|
|
314
|
-
keywords << :length if legacy_length != NOT_GIVEN
|
315
|
-
end
|
316
|
-
|
312
|
+
def polish_register_of_national_economy(length: 9)
|
317
313
|
raise ArgumentError, 'Length should be 9 or 14' unless [9, 14].include? length
|
318
314
|
|
319
315
|
random_digits = []
|
@@ -321,7 +317,7 @@ module Faker
|
|
321
317
|
random_digits = Array.new(length) { rand(10) }
|
322
318
|
break if collect_regon_sum(random_digits) == random_digits.last
|
323
319
|
end
|
324
|
-
random_digits.join
|
320
|
+
random_digits.join
|
325
321
|
end
|
326
322
|
|
327
323
|
##
|
@@ -385,11 +381,7 @@ module Faker
|
|
385
381
|
# Faker::Company.brazilian_company_number #=> "37205322000500"
|
386
382
|
#
|
387
383
|
# @faker.version 1.9.2
|
388
|
-
def brazilian_company_number(
|
389
|
-
warn_for_deprecated_arguments do |keywords|
|
390
|
-
keywords << :formatted if legacy_formatted != NOT_GIVEN
|
391
|
-
end
|
392
|
-
|
384
|
+
def brazilian_company_number(formatted: false)
|
393
385
|
digits = Array.new(8) { Faker::Number.digit.to_i } + [0, 0, 0, Faker::Number.non_zero_digit.to_i]
|
394
386
|
|
395
387
|
factors = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 6].cycle
|
@@ -459,7 +451,7 @@ module Faker
|
|
459
451
|
def luhn_algorithm(number)
|
460
452
|
multiplications = []
|
461
453
|
|
462
|
-
number.to_s.reverse.
|
454
|
+
number.to_s.reverse.chars.each_with_index do |digit, i|
|
463
455
|
multiplications << if i.even?
|
464
456
|
digit.to_i * 2
|
465
457
|
else
|
@@ -553,7 +545,7 @@ module Faker
|
|
553
545
|
def spanish_cif_control_digit(organization_type, code)
|
554
546
|
letters = %w[J A B C D E F G H I]
|
555
547
|
|
556
|
-
control = code.
|
548
|
+
control = code.chars.each_with_index.inject(0) do |sum, (value, index)|
|
557
549
|
if (index + 1).even?
|
558
550
|
sum + value.to_i
|
559
551
|
else
|
@@ -16,11 +16,7 @@ module Faker
|
|
16
16
|
# Faker::CryptoCoin.coin_name #=> "Bitcoin"
|
17
17
|
#
|
18
18
|
# @faker.version 1.9.2
|
19
|
-
def coin_name(
|
20
|
-
warn_for_deprecated_arguments do |keywords|
|
21
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
22
|
-
end
|
23
|
-
|
19
|
+
def coin_name(coin: coin_array)
|
24
20
|
coin[COIN_NAME]
|
25
21
|
end
|
26
22
|
|
@@ -33,11 +29,7 @@ module Faker
|
|
33
29
|
# Faker::CryptoCoin.acronym #=> "BTC"
|
34
30
|
#
|
35
31
|
# @faker.version 1.9.2
|
36
|
-
def acronym(
|
37
|
-
warn_for_deprecated_arguments do |keywords|
|
38
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
39
|
-
end
|
40
|
-
|
32
|
+
def acronym(coin: coin_array)
|
41
33
|
coin[ACRONYM]
|
42
34
|
end
|
43
35
|
|
@@ -50,11 +42,7 @@ module Faker
|
|
50
42
|
# Faker::CryptoCoin.url_logo #=> "https://i.imgur.com/EFz61Ei.png"
|
51
43
|
#
|
52
44
|
# @faker.version 1.9.2
|
53
|
-
def url_logo(
|
54
|
-
warn_for_deprecated_arguments do |keywords|
|
55
|
-
keywords << :coin if legacy_coin != NOT_GIVEN
|
56
|
-
end
|
57
|
-
|
45
|
+
def url_logo(coin: coin_array)
|
58
46
|
coin[URL_LOGO]
|
59
47
|
end
|
60
48
|
|
data/lib/faker/default/date.rb
CHANGED
@@ -17,20 +17,13 @@ module Faker
|
|
17
17
|
# Faker::Date.between(from: 2.days.ago, to: Date.today) #=> #<Date: 2014-09-24>
|
18
18
|
#
|
19
19
|
# @faker.version 1.0.0
|
20
|
-
def between(
|
21
|
-
warn_for_deprecated_arguments do |keywords|
|
22
|
-
keywords << :from if legacy_from != NOT_GIVEN
|
23
|
-
keywords << :to if legacy_to != NOT_GIVEN
|
24
|
-
end
|
25
|
-
|
20
|
+
def between(from:, to:)
|
26
21
|
from = get_date_object(from)
|
27
22
|
to = get_date_object(to)
|
28
23
|
|
29
24
|
Faker::Base.rand_in_range(from, to)
|
30
25
|
end
|
31
26
|
|
32
|
-
# rubocop:disable Metrics/ParameterLists
|
33
|
-
|
34
27
|
##
|
35
28
|
# Produce a random date between two dates.
|
36
29
|
#
|
@@ -46,17 +39,7 @@ module Faker
|
|
46
39
|
# Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today) #=> #<Date: 2014-10-03>
|
47
40
|
#
|
48
41
|
# @faker.version 1.6.2
|
49
|
-
def between_except(
|
50
|
-
warn_for_deprecated_arguments do |keywords|
|
51
|
-
keywords << :from if legacy_from != NOT_GIVEN
|
52
|
-
end
|
53
|
-
warn_for_deprecated_arguments do |keywords|
|
54
|
-
keywords << :to if legacy_to != NOT_GIVEN
|
55
|
-
end
|
56
|
-
warn_for_deprecated_arguments do |keywords|
|
57
|
-
keywords << :excepted if legacy_excepted != NOT_GIVEN
|
58
|
-
end
|
59
|
-
|
42
|
+
def between_except(from:, to:, excepted:)
|
60
43
|
raise ArgumentError, 'From date, to date and excepted date must not be the same' if from == to && to == excepted
|
61
44
|
|
62
45
|
excepted = get_date_object(excepted)
|
@@ -66,7 +49,6 @@ module Faker
|
|
66
49
|
break date.to_date if date != excepted
|
67
50
|
end
|
68
51
|
end
|
69
|
-
# rubocop:enable Metrics/ParameterLists
|
70
52
|
|
71
53
|
##
|
72
54
|
# Produce a random date in the future (up to N days).
|
@@ -78,11 +60,7 @@ module Faker
|
|
78
60
|
# Faker::Date.forward(days: 23) #=> #<Date: 2014-10-03>
|
79
61
|
#
|
80
62
|
# @faker.version 1.0.0
|
81
|
-
def forward(
|
82
|
-
warn_for_deprecated_arguments do |keywords|
|
83
|
-
keywords << :days if legacy_days != NOT_GIVEN
|
84
|
-
end
|
85
|
-
|
63
|
+
def forward(days: 365)
|
86
64
|
from = ::Date.today + 1
|
87
65
|
to = ::Date.today + days
|
88
66
|
|
@@ -99,11 +77,7 @@ module Faker
|
|
99
77
|
# Faker::Date.backward(days: 14) #=> #<Date: 2019-09-12>
|
100
78
|
#
|
101
79
|
# @faker.version 1.0.0
|
102
|
-
def backward(
|
103
|
-
warn_for_deprecated_arguments do |keywords|
|
104
|
-
keywords << :days if legacy_days != NOT_GIVEN
|
105
|
-
end
|
106
|
-
|
80
|
+
def backward(days: 365)
|
107
81
|
from = ::Date.today - days
|
108
82
|
to = ::Date.today - 1
|
109
83
|
|
@@ -121,14 +95,7 @@ module Faker
|
|
121
95
|
# Faker::Date.birthday(min_age: 18, max_age: 65) #=> #<Date: 1986-03-28>
|
122
96
|
#
|
123
97
|
# @faker.version 1.4.3
|
124
|
-
def birthday(
|
125
|
-
warn_for_deprecated_arguments do |keywords|
|
126
|
-
keywords << :min_age if legacy_min_age != NOT_GIVEN
|
127
|
-
end
|
128
|
-
warn_for_deprecated_arguments do |keywords|
|
129
|
-
keywords << :max_age if legacy_max_age != NOT_GIVEN
|
130
|
-
end
|
131
|
-
|
98
|
+
def birthday(min_age: 18, max_age: 65)
|
132
99
|
t = ::Date.today
|
133
100
|
|
134
101
|
from = birthday_date(t, max_age)
|
@@ -80,11 +80,7 @@ module Faker
|
|
80
80
|
# Faker::Demographic.height(unit: :imperial) #=> "6 ft, 2 in"
|
81
81
|
#
|
82
82
|
# @faker.version 1.7.3
|
83
|
-
def height(
|
84
|
-
warn_for_deprecated_arguments do |keywords|
|
85
|
-
keywords << :unit if legacy_unit != NOT_GIVEN
|
86
|
-
end
|
87
|
-
|
83
|
+
def height(unit: :metric)
|
88
84
|
case unit
|
89
85
|
when :imperial
|
90
86
|
inches = rand_in_range(57, 86)
|
@@ -6,8 +6,6 @@ module Faker
|
|
6
6
|
NI_CHANCE = 0.03 # NI Pop is about 3% of total UK population
|
7
7
|
|
8
8
|
class << self
|
9
|
-
# rubocop:disable Metrics/ParameterLists
|
10
|
-
|
11
9
|
##
|
12
10
|
# Produces a random British driving licence number.
|
13
11
|
#
|
@@ -25,14 +23,7 @@ module Faker
|
|
25
23
|
# date_of_birth: Date.parse("1986-10-24")) #=> "OCARR815246J91HT"
|
26
24
|
#
|
27
25
|
# @faker.version 1.9.2
|
28
|
-
def british_driving_licence(
|
29
|
-
warn_for_deprecated_arguments do |keywords|
|
30
|
-
keywords << :last_name if legacy_last_name != NOT_GIVEN
|
31
|
-
keywords << :initials if legacy_initials != NOT_GIVEN
|
32
|
-
keywords << :gender if legacy_gender != NOT_GIVEN
|
33
|
-
keywords << :date_of_birth if legacy_date_of_birth != NOT_GIVEN
|
34
|
-
end
|
35
|
-
|
26
|
+
def british_driving_licence(last_name: Faker::Name.last_name, initials: Faker::Name.initials, gender: random_gender, date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65))
|
36
27
|
[
|
37
28
|
gb_licence_padding(last_name, 5),
|
38
29
|
gb_licence_year(date_of_birth, gender),
|
@@ -40,7 +31,6 @@ module Faker
|
|
40
31
|
gb_licence_checksum
|
41
32
|
].join
|
42
33
|
end
|
43
|
-
# rubocop:enable Metrics/ParameterLists
|
44
34
|
|
45
35
|
##
|
46
36
|
# Produces a random Northern Irish licence number.
|
data/lib/faker/default/file.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
module Faker
|
4
4
|
class File < Base
|
5
5
|
class << self
|
6
|
-
# rubocop:disable Metrics/ParameterLists
|
7
|
-
|
8
6
|
##
|
9
7
|
# Produces a random directory name.
|
10
8
|
#
|
@@ -20,13 +18,7 @@ module Faker
|
|
20
18
|
# Faker::File.dir(segment_count: 3, root: nil, directory_separator: '\\') #=> "aut-ullam\\quia_quisquam\\ut-eos"
|
21
19
|
#
|
22
20
|
# @faker.version 1.6.4
|
23
|
-
def dir(
|
24
|
-
warn_for_deprecated_arguments do |keywords|
|
25
|
-
keywords << :segment_count if legacy_segment_count != NOT_GIVEN
|
26
|
-
keywords << :root if legacy_root != NOT_GIVEN
|
27
|
-
keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
|
28
|
-
end
|
29
|
-
|
21
|
+
def dir(segment_count: 3, root: nil, directory_separator: ::File::Separator)
|
30
22
|
Array
|
31
23
|
.new(segment_count) { Faker::Internet.slug }
|
32
24
|
.unshift(root)
|
@@ -34,7 +26,6 @@ module Faker
|
|
34
26
|
.join(directory_separator)
|
35
27
|
.squeeze(directory_separator)
|
36
28
|
end
|
37
|
-
# rubocop:enable Metrics/ParameterLists
|
38
29
|
|
39
30
|
##
|
40
31
|
# Produces a random file extension.
|
@@ -57,13 +48,11 @@ module Faker
|
|
57
48
|
# @example
|
58
49
|
# Faker::File.mime_type #=> "application/pdf"
|
59
50
|
#
|
60
|
-
# @faker.version
|
61
|
-
def mime_type
|
62
|
-
fetch('file.mime_type')
|
51
|
+
# @faker.version next
|
52
|
+
def mime_type(media_type: nil)
|
53
|
+
media_type ? fetch("file.mime_type.#{media_type}") : sample(sample(translate('faker.file.mime_type').values))
|
63
54
|
end
|
64
55
|
|
65
|
-
# rubocop:disable Metrics/ParameterLists
|
66
|
-
|
67
56
|
##
|
68
57
|
# Produces a random file name.
|
69
58
|
#
|
@@ -80,21 +69,13 @@ module Faker
|
|
80
69
|
# Faker::File.file_name(dir: 'foo/bar', name: 'baz', ext: 'mp3', directory_separator: '\\') #=> "foo/bar\\baz.mp3"
|
81
70
|
#
|
82
71
|
# @faker.version 1.6.4
|
83
|
-
def file_name(
|
84
|
-
warn_for_deprecated_arguments do |keywords|
|
85
|
-
keywords << :dir if legacy_dir != NOT_GIVEN
|
86
|
-
keywords << :name if legacy_name != NOT_GIVEN
|
87
|
-
keywords << :ext if legacy_ext != NOT_GIVEN
|
88
|
-
keywords << :directory_separator if legacy_directory_separator != NOT_GIVEN
|
89
|
-
end
|
90
|
-
|
72
|
+
def file_name(dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
|
91
73
|
dir ||= dir(segment_count: 1)
|
92
74
|
name ||= Faker::Lorem.word.downcase
|
93
75
|
ext ||= extension
|
94
76
|
|
95
77
|
[dir, name].join(directory_separator) + ".#{ext}"
|
96
78
|
end
|
97
|
-
# rubocop:enable Metrics/ParameterLists
|
98
79
|
end
|
99
80
|
end
|
100
81
|
end
|
@@ -3,8 +3,6 @@
|
|
3
3
|
module Faker
|
4
4
|
class Fillmurray < Base
|
5
5
|
class << self
|
6
|
-
# rubocop:disable Metrics/ParameterLists
|
7
|
-
|
8
6
|
##
|
9
7
|
# Produces the URL of an image from Fill Murray, a site which hosts
|
10
8
|
# exclusively photographs of actor Bill Murray.
|
@@ -26,20 +24,13 @@ module Faker
|
|
26
24
|
# #=> "https://fillmurray.com/200/400"
|
27
25
|
#
|
28
26
|
# @faker.version 1.7.1
|
29
|
-
def image(
|
30
|
-
warn_for_deprecated_arguments do |keywords|
|
31
|
-
keywords << :grayscale if legacy_grayscale != NOT_GIVEN
|
32
|
-
keywords << :width if legacy_width != NOT_GIVEN
|
33
|
-
keywords << :height if legacy_height != NOT_GIVEN
|
34
|
-
end
|
35
|
-
|
27
|
+
def image(grayscale: false, width: 200, height: 200)
|
36
28
|
raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
|
37
29
|
raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
|
38
30
|
raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)
|
39
31
|
|
40
32
|
"https://www.fillmurray.com#{'/g' if grayscale == true}/#{width}/#{height}"
|
41
33
|
end
|
42
|
-
# rubocop:enable Metrics/ParameterLists
|
43
34
|
end
|
44
35
|
end
|
45
36
|
end
|
@@ -28,9 +28,9 @@ module Faker
|
|
28
28
|
|
29
29
|
# calculate the luhn checksum digit
|
30
30
|
multiplier = 1
|
31
|
-
luhn_sum = template.gsub(/[^0-9]/, '').
|
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
|
@@ -52,11 +52,7 @@ module Faker
|
|
52
52
|
# Faker::Finance.vat_number('ZA') #=> "ZA79494416181"
|
53
53
|
#
|
54
54
|
# @faker.version 1.9.2
|
55
|
-
def vat_number(
|
56
|
-
warn_for_deprecated_arguments do |keywords|
|
57
|
-
keywords << :country if legacy_country != NOT_GIVEN
|
58
|
-
end
|
59
|
-
|
55
|
+
def vat_number(country: 'BR')
|
60
56
|
numerify(fetch("finance.vat_number.#{country}"))
|
61
57
|
rescue I18n::MissingTranslationData
|
62
58
|
raise ArgumentError, "Could not find vat number for #{country}"
|
@@ -97,6 +93,20 @@ module Faker
|
|
97
93
|
def stock_market
|
98
94
|
fetch('finance.stock_market')
|
99
95
|
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Returns a random condominium fiscal code.
|
99
|
+
#
|
100
|
+
# @param country [String] Two capital letter country code to use for the vat number.
|
101
|
+
# @return [String]
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# Faker::Finance.condominium_fiscal_code #=> "012345678"
|
105
|
+
#
|
106
|
+
# @faker.version next
|
107
|
+
def condominium_fiscal_code(country: 'IT')
|
108
|
+
numerify(fetch("finance.condominium_fiscal_code.#{country}"))
|
109
|
+
end
|
100
110
|
end
|
101
111
|
end
|
102
112
|
end
|