faker 2.20.0 → 3.2.1
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 +346 -7
- data/History.md +1 -1
- data/README.md +193 -107
- 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 +25 -25
- data/lib/faker/default/code.rb +68 -39
- data/lib/faker/default/color.rb +77 -6
- data/lib/faker/default/commerce.rb +3 -17
- data/lib/faker/default/company.rb +50 -19
- data/lib/faker/default/crypto_coin.rb +3 -15
- data/lib/faker/default/date.rb +65 -42
- data/lib/faker/default/demographic.rb +1 -5
- data/lib/faker/default/driving_licence.rb +20 -19
- data/lib/faker/default/drone.rb +1 -1
- data/lib/faker/default/file.rb +5 -24
- data/lib/faker/default/finance.rb +17 -7
- data/lib/faker/default/food.rb +14 -1
- data/lib/faker/default/hipster.rb +6 -45
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +125 -14
- data/lib/faker/default/internet.rb +116 -111
- data/lib/faker/default/invoice.rb +4 -17
- data/lib/faker/default/json.rb +2 -20
- data/lib/faker/default/lorem.rb +25 -74
- data/lib/faker/default/lorem_flickr.rb +4 -32
- data/lib/faker/default/markdown.rb +6 -11
- data/lib/faker/default/marketing.rb +1 -1
- data/lib/faker/default/measurement.rb +16 -48
- 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 +6 -40
- data/lib/faker/default/phone_number.rb +2 -6
- data/lib/faker/default/placeholdit.rb +1 -12
- data/lib/faker/default/relationship.rb +1 -5
- data/lib/faker/default/release notes.md +59 -0
- 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 +7 -23
- data/lib/faker/default/types.rb +7 -28
- data/lib/faker/default/vehicle.rb +40 -51
- data/lib/faker/default/vulnerability_identifier.rb +23 -0
- data/lib/faker/default/world_cup.rb +2 -11
- data/lib/faker/games/clash_of_clans.rb +1 -1
- data/lib/faker/games/dnd.rb +49 -7
- data/lib/faker/games/dota.rb +1 -5
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/minecraft.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/games/tarkov.rb +205 -0
- data/lib/faker/japanese_media/cowboy_bebop.rb +61 -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/avatar.rb +49 -0
- data/lib/faker/movies/hackers.rb +48 -0
- data/lib/faker/movies/star_wars.rb +1 -5
- data/lib/faker/movies/tron.rb +161 -0
- data/lib/faker/quotes/quote.rb +13 -0
- data/lib/faker/sports/chess.rb +90 -0
- data/lib/faker/sports/mountaineering.rb +22 -0
- data/lib/faker/sports/sport.rb +116 -0
- data/lib/faker/travel/airport.rb +43 -0
- data/lib/faker/travel/train_station.rb +54 -0
- data/lib/faker/tv_shows/archer.rb +51 -0
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/tv_shows/spongebob.rb +50 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +26 -67
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/positional_generator.rb +480 -0
- data/lib/helpers/unique_generator.rb +13 -11
- data/lib/locales/README.md +18 -2
- data/lib/locales/ar.yml +1 -0
- data/lib/locales/bg.yml +1 -1
- data/lib/locales/da-DK.yml +1 -1
- data/lib/locales/de-AT.yml +1 -2
- data/lib/locales/de-CH.yml +4336 -12
- data/lib/locales/de.yml +1 -1
- data/lib/locales/en/airport.yml +381 -0
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/australia.yml +3 -4
- data/lib/locales/en/avatar.yml +31 -0
- data/lib/locales/en/chess.yml +103 -0
- data/lib/locales/en/company.yml +1 -0
- data/lib/locales/en/computer.yml +23 -4
- data/lib/locales/en/cowboy_bebop.yml +163 -0
- data/lib/locales/en/dnd.yml +186 -1
- data/lib/locales/en/dota.yml +113 -0
- data/lib/locales/en/file.yml +9 -1
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/finance.yml +3 -1
- data/lib/locales/en/food.yml +12 -0
- data/lib/locales/en/game.yml +0 -1
- data/lib/locales/en/hackers.yml +53 -0
- data/lib/locales/en/heroes.yml +2 -2
- data/lib/locales/en/internet.yml +32 -0
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/mitch_hedberg.yml +46 -0
- data/lib/locales/en/mountaineering.yml +14 -0
- data/lib/locales/en/movie.yml +2 -1
- data/lib/locales/en/naruto.yml +2 -3
- data/lib/locales/en/one_piece.yml +1 -1
- data/lib/locales/en/opera.yml +2 -2
- data/lib/locales/en/overwatch.yml +5 -7
- data/lib/locales/en/source.yml +5 -0
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/spongebob.yml +489 -0
- data/lib/locales/en/sport.yml +130 -0
- data/lib/locales/en/star_wars.yml +1 -1
- data/lib/locales/en/tarkov.yml +593 -0
- data/lib/locales/en/train_station.yml +280 -0
- data/lib/locales/en/tron.yml +227 -0
- data/lib/locales/en/vehicle.yml +2809 -75
- data/lib/locales/en-AU.yml +2 -2
- data/lib/locales/en-CA.yml +2 -1
- data/lib/locales/en-GB.yml +2 -1
- data/lib/locales/en-MS.yml +1 -0
- data/lib/locales/en-NG.yml +1 -0
- data/lib/locales/en-NZ.yml +1 -0
- data/lib/locales/en-PAK.yml +1 -0
- data/lib/locales/en-SG.yml +1 -0
- data/lib/locales/en-UG.yml +1 -0
- data/lib/locales/en-US.yml +1 -1
- data/lib/locales/en-ZA.yml +1 -1
- data/lib/locales/en-au-ocker.yml +2 -0
- data/lib/locales/es-AR.yml +3 -2
- data/lib/locales/es-MX.yml +1 -1
- data/lib/locales/es.yml +2 -2
- data/lib/locales/fi-FI.yml +3 -1
- data/lib/locales/fr/address.yml +0 -1
- data/lib/locales/fr/adjective.yml +266 -0
- data/lib/locales/fr/ancient.yml +141 -0
- data/lib/locales/fr/name.yml +2 -1
- data/lib/locales/fr-CA.yml +1 -1
- data/lib/locales/fr-CH.yml +1 -1
- data/lib/locales/hy.yml +2 -1
- data/lib/locales/it.yml +1 -0
- data/lib/locales/ja/adjective.yml +148 -0
- data/lib/locales/ja/dog.yml +1 -0
- data/lib/locales/ja/emotion.yml +51 -0
- data/lib/locales/ja/naruto.yml +230 -0
- data/lib/locales/ja/relationship.yml +10 -0
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ja/super_mario.yml +1 -1
- data/lib/locales/ko.yml +1 -0
- data/lib/locales/lt.yml +0 -1
- data/lib/locales/mi-NZ.yml +2 -0
- data/lib/locales/nb-NO.yml +1 -0
- data/lib/locales/nl.yml +1 -0
- data/lib/locales/pl.yml +2 -2
- data/lib/locales/pt-BR.yml +1 -0
- data/lib/locales/pt.yml +1 -1
- data/lib/locales/ru.yml +1 -0
- data/lib/locales/sk.yml +1 -0
- data/lib/locales/sv.yml +1 -0
- data/lib/locales/th.yml +76 -76
- data/lib/locales/tr.yml +1 -0
- data/lib/locales/uk.yml +3 -0
- data/lib/locales/vi.yml +1 -0
- data/lib/locales/zh-CN.yml +1 -0
- data/lib/locales/zh-TW.yml +1 -0
- metadata +46 -127
- data/lib/faker/default/fillmurray.rb +0 -45
- data/lib/faker/default/lorem_pixel.rb +0 -70
- /data/lib/faker/default/{faker_adjective.rb → adjective.rb} +0 -0
|
@@ -18,11 +18,7 @@ module Faker
|
|
|
18
18
|
# #=> "Northfort, California"
|
|
19
19
|
#
|
|
20
20
|
# @faker.version 0.3.0
|
|
21
|
-
def city(
|
|
22
|
-
warn_for_deprecated_arguments do |keywords|
|
|
23
|
-
keywords << :options if legacy_options != NOT_GIVEN
|
|
24
|
-
end
|
|
25
|
-
|
|
21
|
+
def city(options: {})
|
|
26
22
|
parse(options[:with_state] ? 'address.city_with_state' : 'address.city')
|
|
27
23
|
end
|
|
28
24
|
|
|
@@ -49,11 +45,7 @@ module Faker
|
|
|
49
45
|
# Faker::Address.street_address #=> "282 Kevin Brook"
|
|
50
46
|
#
|
|
51
47
|
# @faker.version 0.3.0
|
|
52
|
-
def street_address(
|
|
53
|
-
warn_for_deprecated_arguments do |keywords|
|
|
54
|
-
keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN
|
|
55
|
-
end
|
|
56
|
-
|
|
48
|
+
def street_address(include_secondary: false)
|
|
57
49
|
numerify(parse('address.street_address') + (include_secondary ? " #{secondary_address}" : ''))
|
|
58
50
|
end
|
|
59
51
|
|
|
@@ -121,11 +113,7 @@ module Faker
|
|
|
121
113
|
# Faker::Address.zip_code(state_abbreviation: 'CO') #=> "80011"
|
|
122
114
|
#
|
|
123
115
|
# @faker.version 0.3.0
|
|
124
|
-
def zip_code(
|
|
125
|
-
warn_for_deprecated_arguments do |keywords|
|
|
126
|
-
keywords << :state_abbreviation if legacy_state_abbreviation != NOT_GIVEN
|
|
127
|
-
end
|
|
128
|
-
|
|
116
|
+
def zip_code(state_abbreviation: '')
|
|
129
117
|
if state_abbreviation.empty?
|
|
130
118
|
letterified_string = letterify(fetch('address.postcode'))
|
|
131
119
|
return numerify(letterified_string, leading_zero: true)
|
|
@@ -242,11 +230,7 @@ module Faker
|
|
|
242
230
|
# Faker::Address.country_by_code(code: 'NL') #=> "Netherlands"
|
|
243
231
|
#
|
|
244
232
|
# @faker.version 1.9.2
|
|
245
|
-
def country_by_code(
|
|
246
|
-
warn_for_deprecated_arguments do |keywords|
|
|
247
|
-
keywords << :code if legacy_code != NOT_GIVEN
|
|
248
|
-
end
|
|
249
|
-
|
|
233
|
+
def country_by_code(code: 'US')
|
|
250
234
|
fetch("address.country_by_code.#{code}")
|
|
251
235
|
end
|
|
252
236
|
|
|
@@ -260,11 +244,7 @@ module Faker
|
|
|
260
244
|
# Faker::Address.country_name_to_code(name: 'united_states') #=> "US"
|
|
261
245
|
#
|
|
262
246
|
# @faker.version 1.9.2
|
|
263
|
-
def country_name_to_code(
|
|
264
|
-
warn_for_deprecated_arguments do |keywords|
|
|
265
|
-
keywords << :name if legacy_name != NOT_GIVEN
|
|
266
|
-
end
|
|
267
|
-
|
|
247
|
+
def country_name_to_code(name: 'united_states')
|
|
268
248
|
fetch("address.country_by_name.#{name}")
|
|
269
249
|
end
|
|
270
250
|
|
|
@@ -19,10 +19,7 @@ module Faker
|
|
|
19
19
|
# Faker::Alphanumeric.alpha(number: 10) #=> "zlvubkrwga"
|
|
20
20
|
#
|
|
21
21
|
# @faker.version 1.9.2
|
|
22
|
-
def alpha(
|
|
23
|
-
warn_for_deprecated_arguments do |keywords|
|
|
24
|
-
keywords << :number if legacy_number != NOT_GIVEN
|
|
25
|
-
end
|
|
22
|
+
def alpha(number: 32)
|
|
26
23
|
char_count = resolve(number)
|
|
27
24
|
return '' if char_count.to_i < 1
|
|
28
25
|
|
|
@@ -46,10 +43,7 @@ module Faker
|
|
|
46
43
|
# Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3) #=> "3yfq2phx8b"
|
|
47
44
|
#
|
|
48
45
|
# @faker.version 2.1.3
|
|
49
|
-
def alphanumeric(
|
|
50
|
-
warn_for_deprecated_arguments do |keywords|
|
|
51
|
-
keywords << :number if legacy_number != NOT_GIVEN
|
|
52
|
-
end
|
|
46
|
+
def alphanumeric(number: 32, min_alpha: 0, min_numeric: 0)
|
|
53
47
|
char_count = resolve(number)
|
|
54
48
|
return '' if char_count.to_i < 1
|
|
55
49
|
raise ArgumentError, 'min_alpha must be greater than or equal to 0' if min_alpha&.negative?
|
data/lib/faker/default/app.rb
CHANGED
|
@@ -42,8 +42,6 @@ module Faker
|
|
|
42
42
|
parse('app.author')
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
# rubocop:disable Metrics/ParameterLists
|
|
46
|
-
|
|
47
45
|
##
|
|
48
46
|
# Produces a String representing a semantic version identifier.
|
|
49
47
|
#
|
|
@@ -62,16 +60,9 @@ module Faker
|
|
|
62
60
|
# Faker::App.semantic_version(patch: 5..6) #=> "7.2.6"
|
|
63
61
|
#
|
|
64
62
|
# @faker.version 1.4.3
|
|
65
|
-
def semantic_version(
|
|
66
|
-
warn_for_deprecated_arguments do |keywords|
|
|
67
|
-
keywords << :major if legacy_major != NOT_GIVEN
|
|
68
|
-
keywords << :minor if legacy_minor != NOT_GIVEN
|
|
69
|
-
keywords << :patch if legacy_patch != NOT_GIVEN
|
|
70
|
-
end
|
|
71
|
-
|
|
63
|
+
def semantic_version(major: 0..9, minor: 0..9, patch: 1..9)
|
|
72
64
|
[major, minor, patch].map { |chunk| sample(Array(chunk)) }.join('.')
|
|
73
65
|
end
|
|
74
|
-
# rubocop:enable Metrics/ParameterLists
|
|
75
66
|
end
|
|
76
67
|
end
|
|
77
68
|
end
|
data/lib/faker/default/avatar.rb
CHANGED
|
@@ -6,8 +6,6 @@ module Faker
|
|
|
6
6
|
# @private
|
|
7
7
|
SUPPORTED_FORMATS = %w[png jpg bmp].freeze
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Metrics/ParameterLists
|
|
10
|
-
|
|
11
9
|
##
|
|
12
10
|
# Produces a URL for an avatar from robohash.org
|
|
13
11
|
#
|
|
@@ -38,15 +36,7 @@ module Faker
|
|
|
38
36
|
# #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1&bgset=bg1"
|
|
39
37
|
#
|
|
40
38
|
# @faker.version 1.4.3
|
|
41
|
-
def image(
|
|
42
|
-
warn_for_deprecated_arguments do |keywords|
|
|
43
|
-
keywords << :slug if legacy_slug != NOT_GIVEN
|
|
44
|
-
keywords << :size if legacy_size != NOT_GIVEN
|
|
45
|
-
keywords << :format if legacy_format != NOT_GIVEN
|
|
46
|
-
keywords << :set if legacy_set != NOT_GIVEN
|
|
47
|
-
keywords << :bgset if legacy_bgset != NOT_GIVEN
|
|
48
|
-
end
|
|
49
|
-
|
|
39
|
+
def image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
|
|
50
40
|
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
|
51
41
|
raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
|
|
52
42
|
|
|
@@ -54,7 +44,6 @@ module Faker
|
|
|
54
44
|
bgset_query = "&bgset=#{bgset}" if bgset
|
|
55
45
|
"https://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}#{bgset_query}"
|
|
56
46
|
end
|
|
57
|
-
# rubocop:enable Metrics/ParameterLists
|
|
58
47
|
end
|
|
59
48
|
end
|
|
60
49
|
end
|
data/lib/faker/default/bank.rb
CHANGED
|
@@ -16,14 +16,10 @@ module Faker
|
|
|
16
16
|
# Faker::Bank.account_number(digits: 13) #=> 673858237902
|
|
17
17
|
#
|
|
18
18
|
# @faker.version 1.9.1
|
|
19
|
-
def account_number(
|
|
20
|
-
warn_for_deprecated_arguments do |keywords|
|
|
21
|
-
keywords << :digits if legacy_digits != NOT_GIVEN
|
|
22
|
-
end
|
|
23
|
-
|
|
19
|
+
def account_number(digits: 10)
|
|
24
20
|
output = ''
|
|
25
21
|
|
|
26
|
-
output += rand.to_s[2
|
|
22
|
+
output += rand.to_s[2..] while output.length < digits
|
|
27
23
|
|
|
28
24
|
output[0...digits]
|
|
29
25
|
end
|
|
@@ -40,14 +36,10 @@ module Faker
|
|
|
40
36
|
# Faker::Bank.iban(country_code: nil) #=> "DE45186738071857270067"
|
|
41
37
|
#
|
|
42
38
|
# @faker.version 1.7.0
|
|
43
|
-
def iban(
|
|
39
|
+
def iban(country_code: 'GB')
|
|
44
40
|
# Each country has its own format for bank accounts
|
|
45
41
|
# Many of them use letters in certain parts of the account
|
|
46
42
|
# Using regex patterns we can create virtually any type of bank account
|
|
47
|
-
warn_for_deprecated_arguments do |keywords|
|
|
48
|
-
keywords << :country_code if legacy_country_code != NOT_GIVEN
|
|
49
|
-
end
|
|
50
|
-
|
|
51
43
|
country_code ||= iban_country_code
|
|
52
44
|
|
|
53
45
|
begin
|
|
@@ -145,7 +137,7 @@ module Faker
|
|
|
145
137
|
private
|
|
146
138
|
|
|
147
139
|
def checksum(num_string)
|
|
148
|
-
num_array = num_string.
|
|
140
|
+
num_array = num_string.chars.map(&:to_i)
|
|
149
141
|
(
|
|
150
142
|
7 * (num_array[0] + num_array[3] + num_array[6]) +
|
|
151
143
|
3 * (num_array[1] + num_array[4] + num_array[7]) +
|
|
@@ -166,15 +158,15 @@ module Faker
|
|
|
166
158
|
end
|
|
167
159
|
|
|
168
160
|
# Calculates the mandatory checksum in 3rd and 4th characters in IBAN format
|
|
169
|
-
# source: https://en.wikipedia.org/wiki/International_Bank_Account_Number#
|
|
161
|
+
# source: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
|
|
170
162
|
def iban_checksum(country_code, account)
|
|
171
163
|
# Converts letters to numbers according the iban rules, A=10..Z=35
|
|
172
164
|
account_to_number = "#{account}#{country_code}00".upcase.chars.map do |d|
|
|
173
165
|
d =~ /[A-Z]/ ? (d.ord - 55).to_s : d
|
|
174
166
|
end.join.to_i
|
|
175
167
|
|
|
176
|
-
# This is answer to (iban_to_num + checksum) % 97 == 1
|
|
177
|
-
checksum =
|
|
168
|
+
# This is the correct answer to (iban_to_num + checksum) % 97 == 1
|
|
169
|
+
checksum = 98 - (account_to_number % 97)
|
|
178
170
|
|
|
179
171
|
# Use leftpad to make the size always to 2
|
|
180
172
|
checksum.to_s.rjust(2, '0')
|
|
@@ -194,8 +186,8 @@ module Faker
|
|
|
194
186
|
|
|
195
187
|
def compile_fraction(routing_num)
|
|
196
188
|
prefix = (1..50).to_a.map(&:to_s).sample
|
|
197
|
-
numerator = routing_num.
|
|
198
|
-
denominator = routing_num.
|
|
189
|
+
numerator = routing_num.chars[5..8].join.to_i.to_s
|
|
190
|
+
denominator = routing_num.chars[0..4].join.to_i.to_s
|
|
199
191
|
"#{prefix}-#{numerator}/#{denominator}"
|
|
200
192
|
end
|
|
201
193
|
|
|
@@ -15,10 +15,7 @@ module Faker
|
|
|
15
15
|
# Faker::Boolean.boolean(true_ratio: 0.2) #=> false
|
|
16
16
|
#
|
|
17
17
|
# @faker.version 1.6.2
|
|
18
|
-
def boolean(
|
|
19
|
-
warn_for_deprecated_arguments do |keywords|
|
|
20
|
-
keywords << :true_ratio if legacy_true_ratio != NOT_GIVEN
|
|
21
|
-
end
|
|
18
|
+
def boolean(true_ratio: 0.5)
|
|
22
19
|
(rand < true_ratio)
|
|
23
20
|
end
|
|
24
21
|
end
|
|
@@ -8,23 +8,19 @@ module Faker
|
|
|
8
8
|
##
|
|
9
9
|
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits).
|
|
10
10
|
#
|
|
11
|
-
# @param min_rut [Integer] Specifies the minimum value of the
|
|
12
|
-
# @param
|
|
11
|
+
# @param min_rut [Integer] Specifies the minimum value of the RUT.
|
|
12
|
+
# @param max_rut [Integer] Specifies the maximum value of the RUT.
|
|
13
|
+
# @param fixed [Boolean] Determines if the RUT is fixed (returns the min_rut value).
|
|
13
14
|
# @return [Number]
|
|
14
15
|
#
|
|
15
16
|
# @example
|
|
16
17
|
# Faker::ChileRut.rut #=> 11235813
|
|
17
|
-
# Faker::ChileRut.rut(min_rut:
|
|
18
|
-
# Faker::ChileRut.rut(min_rut:
|
|
18
|
+
# Faker::ChileRut.rut(min_rut: 10_000_000, max_rut: 30_000_000) #=> 21853211
|
|
19
|
+
# Faker::ChileRut.rut(min_rut: 20_890_156, fixed: true) #=> 20890156
|
|
19
20
|
#
|
|
20
|
-
# @faker.version
|
|
21
|
-
def rut(
|
|
22
|
-
|
|
23
|
-
keywords << :min_rut if legacy_min_rut != NOT_GIVEN
|
|
24
|
-
keywords << :fixed if legacy_fixed != NOT_GIVEN
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
@last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
|
|
21
|
+
# @faker.version next
|
|
22
|
+
def rut(min_rut: 1, max_rut: 99_999_999, fixed: false)
|
|
23
|
+
@last_rut = fixed ? min_rut : rand_in_range(min_rut, max_rut)
|
|
28
24
|
end
|
|
29
25
|
|
|
30
26
|
##
|
|
@@ -37,7 +33,7 @@ module Faker
|
|
|
37
33
|
#
|
|
38
34
|
# @faker.version 1.9.2
|
|
39
35
|
def dv
|
|
40
|
-
split_reversed_rut = @last_rut.to_s.reverse.
|
|
36
|
+
split_reversed_rut = @last_rut.to_s.reverse.chars
|
|
41
37
|
seq = [2, 3, 4, 5, 6, 7]
|
|
42
38
|
i = 0
|
|
43
39
|
digit_sum = split_reversed_rut.reduce(0) do |sum, n|
|
|
@@ -73,26 +69,30 @@ module Faker
|
|
|
73
69
|
##
|
|
74
70
|
# Produces a random Chilean RUT (Rol Unico Tributario, ID with 8 digits) with a dv (digito verificador, check-digit).
|
|
75
71
|
#
|
|
76
|
-
# @param min_rut [Integer] Specifies the minimum value of the
|
|
77
|
-
# @param
|
|
72
|
+
# @param min_rut [Integer] Specifies the minimum value of the RUT.
|
|
73
|
+
# @param max_rut [Integer] Specifies the maximum value of the RUT.
|
|
74
|
+
# @param fixed [Boolean] Determines if the RUT is fixed (returns the min_rut value).
|
|
78
75
|
# @return [String]
|
|
79
76
|
#
|
|
80
77
|
# @example
|
|
81
78
|
# Faker::ChileRut.full_rut #=> "30686957-4"
|
|
82
|
-
# Faker::ChileRut.full_rut(min_rut:
|
|
83
|
-
# Faker::ChileRut.full_rut(min_rut:
|
|
79
|
+
# Faker::ChileRut.full_rut(min_rut: 10_000_000, max_rut: 30_000_000) #=> "20686957-4"
|
|
80
|
+
# Faker::ChileRut.full_rut(min_rut: 30_686_957, fixed: true) #=> "30686957-4"
|
|
84
81
|
#
|
|
85
|
-
# @faker.version
|
|
86
|
-
def full_rut(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
|
|
82
|
+
# @faker.version next
|
|
83
|
+
def full_rut(min_rut: 1, max_rut: 99_999_999, fixed: false, formatted: false)
|
|
84
|
+
this_rut = rut(min_rut: min_rut, max_rut: max_rut, fixed: fixed)
|
|
85
|
+
this_rut = format_rut(this_rut) if formatted
|
|
86
|
+
"#{this_rut}-#{dv}"
|
|
93
87
|
end
|
|
94
88
|
|
|
95
89
|
attr_reader :last_rut
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def format_rut(rut)
|
|
94
|
+
rut.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
|
|
95
|
+
end
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
end
|
data/lib/faker/default/code.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Faker
|
|
|
5
5
|
flexible :code
|
|
6
6
|
class << self
|
|
7
7
|
##
|
|
8
|
-
# Produces a random NPI (National Provider
|
|
8
|
+
# Produces a random NPI (National Provider Identifier) code.
|
|
9
9
|
#
|
|
10
10
|
# @return [String]
|
|
11
11
|
#
|
|
@@ -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,18 +91,25 @@ 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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
96
|
+
|
|
97
|
+
generate(:string) do |g|
|
|
98
|
+
g.computed(name: :prefix) do
|
|
99
|
+
if birthyear < 2000
|
|
100
|
+
'S'
|
|
101
|
+
else
|
|
102
|
+
'T'
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
g.computed(name: :yy) do
|
|
106
|
+
birthyear.to_s[-2..]
|
|
107
|
+
end
|
|
108
|
+
g.int(name: :values, length: 5)
|
|
109
|
+
g.computed(name: :check, deps: %i[prefix yy values]) do |prefix, yy, values|
|
|
110
|
+
generate_nric_check_alphabet("#{yy}#{values}", prefix)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
114
113
|
end
|
|
115
114
|
|
|
116
115
|
##
|
|
@@ -206,50 +205,80 @@ module Faker
|
|
|
206
205
|
str[len - 1] = (10 - (sum % 10)) % 10
|
|
207
206
|
|
|
208
207
|
# Output the IMEI value.
|
|
209
|
-
str.join
|
|
208
|
+
str.join
|
|
210
209
|
end
|
|
211
210
|
|
|
212
211
|
def generate_base10_isbn
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
generate(:string) do |g|
|
|
213
|
+
g.int(name: :values, length: 9)
|
|
214
|
+
g.lit('-')
|
|
215
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
|
216
|
+
remainder = sum(values.to_s) { |value, offset| (offset + 1) * value.to_i } % 11
|
|
217
|
+
if remainder == 10
|
|
218
|
+
'X'
|
|
219
|
+
else
|
|
220
|
+
remainder.to_s
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
216
224
|
end
|
|
217
225
|
|
|
218
226
|
def generate_base13_isbn
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
227
|
+
generate(:string) do |g|
|
|
228
|
+
g.int(name: :values, length: 12)
|
|
229
|
+
g.lit('-')
|
|
230
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
|
231
|
+
remainder = sum(values.to_s) { |value, offset| offset.even? ? value.to_i : value.to_i * 3 } % 10
|
|
232
|
+
(10 - remainder) % 10
|
|
233
|
+
end
|
|
234
|
+
end
|
|
222
235
|
end
|
|
223
236
|
|
|
224
237
|
def sum(values)
|
|
225
|
-
values.
|
|
238
|
+
values.chars.each_with_index.inject(0) do |sum, (value, index)|
|
|
226
239
|
sum + yield(value, index)
|
|
227
240
|
end
|
|
228
241
|
end
|
|
229
242
|
|
|
230
243
|
def generate_base8_ean
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
244
|
+
generate(:string) do |g|
|
|
245
|
+
g.int(name: :values, length: 7)
|
|
246
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
|
247
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT8[i] } % 10
|
|
248
|
+
if check_digit == 10
|
|
249
|
+
0
|
|
250
|
+
else
|
|
251
|
+
check_digit
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
234
255
|
end
|
|
235
256
|
|
|
236
257
|
def generate_base13_ean
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
258
|
+
generate(:string) do |g|
|
|
259
|
+
g.int(name: :values, length: 12)
|
|
260
|
+
g.computed(name: :checksum, deps: [:values]) do |values|
|
|
261
|
+
check_digit = 10 - values.to_s.chars.each_with_index.inject(0) { |s, (v, i)| s + v.to_i * EAN_CHECK_DIGIT13[i] } % 10
|
|
262
|
+
if check_digit == 10
|
|
263
|
+
0
|
|
264
|
+
else
|
|
265
|
+
check_digit
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
240
269
|
end
|
|
241
270
|
|
|
242
271
|
EAN_CHECK_DIGIT8 = [3, 1, 3, 1, 3, 1, 3].freeze
|
|
243
272
|
EAN_CHECK_DIGIT13 = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3].freeze
|
|
244
273
|
|
|
245
274
|
def rut_verificator_digit(rut)
|
|
246
|
-
total = rut.to_s.rjust(8, '0').
|
|
247
|
-
(11 - total % 11).to_s.gsub(
|
|
275
|
+
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(:+)
|
|
276
|
+
(11 - total % 11).to_s.gsub('10', 'k').gsub('11', '0')
|
|
248
277
|
end
|
|
249
278
|
|
|
250
279
|
def generate_nric_check_alphabet(values, prefix)
|
|
251
280
|
weight = %w[2 7 6 5 4 3 2]
|
|
252
|
-
total = values.
|
|
281
|
+
total = values.chars.zip(weight).collect { |a, b| a.to_i * b.to_i }.inject(:+)
|
|
253
282
|
total += 4 if prefix == 'T'
|
|
254
283
|
%w[A B C D E F G H I Z J][10 - total % 11]
|
|
255
284
|
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('.')
|