faker 1.9.6 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +189 -6
- data/README.md +5 -1
- data/lib/faker/books/dune.rb +2 -2
- data/lib/faker/books/lovecraft.rb +18 -18
- data/lib/faker/creature/animal.rb +1 -1
- data/lib/faker/creature/cat.rb +1 -1
- data/lib/faker/creature/dog.rb +1 -1
- data/lib/faker/creature/horse.rb +1 -1
- data/lib/faker/default/address.rb +3 -3
- data/lib/faker/default/alphanumeric.rb +4 -4
- data/lib/faker/default/avatar.rb +1 -1
- data/lib/faker/default/bank.rb +2 -2
- data/lib/faker/default/boolean.rb +1 -1
- data/lib/faker/default/cannabis.rb +4 -0
- data/lib/faker/default/chile_rut.rb +3 -3
- data/lib/faker/default/code.rb +5 -5
- data/lib/faker/default/commerce.rb +4 -4
- data/lib/faker/default/company.rb +2 -2
- data/lib/faker/default/crypto_coin.rb +9 -4
- data/lib/faker/default/date.rb +9 -9
- data/lib/faker/default/demographic.rb +1 -1
- data/lib/faker/default/device.rb +2 -2
- data/lib/faker/default/driving_licence.rb +2 -2
- data/lib/faker/default/educator.rb +0 -3
- data/lib/faker/default/file.rb +3 -3
- data/lib/faker/default/fillmurray.rb +2 -2
- data/lib/faker/default/finance.rb +1 -1
- data/lib/faker/default/hipster.rb +16 -16
- data/lib/faker/default/id_number.rb +47 -10
- data/lib/faker/default/internet.rb +22 -21
- data/lib/faker/default/invoice.rb +3 -3
- data/lib/faker/default/json.rb +2 -2
- data/lib/faker/default/lorem.rb +20 -20
- data/lib/faker/default/lorem_flickr.rb +4 -4
- data/lib/faker/default/lorem_pixel.rb +1 -1
- data/lib/faker/default/markdown.rb +7 -7
- data/lib/faker/default/measurement.rb +8 -8
- data/lib/faker/default/name.rb +2 -4
- data/lib/faker/default/nhs.rb +7 -7
- data/lib/faker/default/number.rb +35 -32
- data/lib/faker/default/omniauth.rb +11 -11
- data/lib/faker/default/phone_number.rb +1 -1
- data/lib/faker/default/placeholdit.rb +1 -1
- data/lib/faker/default/relationship.rb +1 -1
- data/lib/faker/default/source.rb +2 -2
- data/lib/faker/default/south_africa.rb +1 -1
- data/lib/faker/default/space.rb +2 -2
- data/lib/faker/default/string.rb +1 -1
- data/lib/faker/default/stripe.rb +4 -4
- data/lib/faker/default/time.rb +23 -8
- data/lib/faker/default/twitter.rb +30 -30
- data/lib/faker/default/types.rb +7 -7
- data/lib/faker/default/vehicle.rb +5 -5
- data/lib/faker/default/world_cup.rb +2 -2
- data/lib/faker/games/dota.rb +1 -1
- data/lib/faker/games/elder_scrolls.rb +1 -1
- data/lib/faker/games/fallout.rb +1 -1
- data/lib/faker/games/half_life.rb +1 -1
- data/lib/faker/games/heroes.rb +1 -1
- data/lib/faker/games/heroes_of_the_storm.rb +1 -1
- data/lib/faker/games/league_of_legends.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/games/overwatch.rb +1 -1
- data/lib/faker/games/pokemon.rb +1 -1
- data/lib/faker/games/sonic_the_hedgehog.rb +1 -1
- data/lib/faker/games/super_smash_bros.rb +1 -1
- data/lib/faker/games/witcher.rb +1 -1
- data/lib/faker/games/world_of_warcraft.rb +1 -1
- data/lib/faker/games/zelda.rb +1 -1
- data/lib/faker/japanese_media/dragon_ball.rb +1 -1
- data/lib/faker/japanese_media/one_piece.rb +1 -1
- data/lib/faker/japanese_media/sword_art_online.rb +1 -1
- data/lib/faker/movies/back_to_the_future.rb +1 -1
- data/lib/faker/movies/ghostbusters.rb +1 -1
- data/lib/faker/movies/harry_potter.rb +1 -1
- data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +1 -1
- data/lib/faker/movies/hobbit.rb +1 -1
- data/lib/faker/movies/lebowski.rb +1 -1
- data/lib/faker/movies/lord_of_the_rings.rb +1 -1
- data/lib/faker/movies/princess_bride.rb +1 -1
- data/lib/faker/movies/star_wars.rb +2 -2
- data/lib/faker/movies/v_for_vendetta.rb +1 -1
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +1 -1
- data/lib/faker/tv_shows/bojack_horseman.rb +1 -1
- data/lib/faker/tv_shows/breaking_bad.rb +1 -1
- data/lib/faker/tv_shows/buffy.rb +1 -1
- data/lib/faker/tv_shows/community.rb +1 -1
- data/lib/faker/tv_shows/dr_who.rb +1 -1
- data/lib/faker/tv_shows/dumb_and_dumber.rb +1 -1
- data/lib/faker/tv_shows/family_guy.rb +1 -1
- data/lib/faker/tv_shows/friends.rb +1 -1
- data/lib/faker/tv_shows/game_of_thrones.rb +1 -1
- data/lib/faker/tv_shows/hey_arnold.rb +1 -1
- data/lib/faker/tv_shows/how_i_met_your_mother.rb +1 -1
- data/lib/faker/tv_shows/michael_scott.rb +1 -1
- data/lib/faker/tv_shows/new_girl.rb +1 -1
- data/lib/faker/tv_shows/parks_and_rec.rb +1 -1
- data/lib/faker/tv_shows/rick_and_morty.rb +1 -1
- data/lib/faker/tv_shows/ru_paul.rb +1 -1
- data/lib/faker/tv_shows/seinfeld.rb +1 -1
- data/lib/faker/tv_shows/silicon_valley.rb +1 -1
- data/lib/faker/tv_shows/simpsons.rb +1 -1
- data/lib/faker/tv_shows/south_park.rb +1 -1
- data/lib/faker/tv_shows/star_trek.rb +1 -1
- data/lib/faker/tv_shows/stargate.rb +1 -1
- data/lib/faker/tv_shows/stranger_things.rb +1 -1
- data/lib/faker/tv_shows/the_expanse.rb +1 -1
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +1 -1
- data/lib/faker/tv_shows/the_it_crowd.rb +1 -1
- data/lib/faker/tv_shows/the_thick_of_it.rb +1 -1
- data/lib/faker/tv_shows/twin_peaks.rb +1 -1
- data/lib/faker/tv_shows/venture_bros.rb +1 -1
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en-IND.yml +1 -1
- data/lib/locales/en.yml +4 -1
- data/lib/locales/en/address.yml +1 -4
- data/lib/locales/en/animal.yml +2 -2
- data/lib/locales/en/cannabis.yml +1 -0
- data/lib/locales/en/space.yml +1 -1
- data/lib/locales/en/super_smash_bros.yml +4 -0
- data/lib/locales/vi.yml +1 -1
- metadata +9 -17
- data/lib/faker/default/creature.rb +0 -6
- data/lib/faker/default/games.rb +0 -6
- data/lib/faker/default/japanese_media.rb +0 -6
- data/lib/faker/default/movies.rb +0 -6
- data/lib/faker/default/tv_shows.rb +0 -6
- data/lib/faker/deprecate/unreleased/football.rb +0 -35
- data/lib/faker/deprecate/unreleased/movies/grateful_dead.rb +0 -22
data/lib/faker/default/bank.rb
CHANGED
@@ -5,7 +5,7 @@ module Faker
|
|
5
5
|
flexible :bank
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def account_number(digits
|
8
|
+
def account_number(digits: 10)
|
9
9
|
output = ''
|
10
10
|
|
11
11
|
output += rand.to_s[2..-1] while output.length < digits
|
@@ -13,7 +13,7 @@ module Faker
|
|
13
13
|
output[0...digits]
|
14
14
|
end
|
15
15
|
|
16
|
-
def iban(country_code
|
16
|
+
def iban(country_code: 'GB')
|
17
17
|
# Each country has it's own format for bank accounts
|
18
18
|
# Many of them use letters in certain parts of the account
|
19
19
|
# Using regex patterns we can create virtually any type of bank account
|
@@ -6,7 +6,7 @@ module Faker
|
|
6
6
|
@last_rut = nil
|
7
7
|
|
8
8
|
# Fixed param added for testing a specific RUT and check digit combination.
|
9
|
-
def rut(min_rut
|
9
|
+
def rut(min_rut: 1, fixed: false)
|
10
10
|
@last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
|
11
11
|
end
|
12
12
|
|
@@ -34,8 +34,8 @@ module Faker
|
|
34
34
|
dv
|
35
35
|
end
|
36
36
|
|
37
|
-
def full_rut(min_rut
|
38
|
-
"#{rut(min_rut, fixed)}-#{dv}"
|
37
|
+
def full_rut(min_rut: 0, fixed: false)
|
38
|
+
"#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
|
39
39
|
end
|
40
40
|
|
41
41
|
attr_reader :last_rut
|
data/lib/faker/default/code.rb
CHANGED
@@ -12,26 +12,26 @@ module Faker
|
|
12
12
|
|
13
13
|
# By default generates 10 sign isbn code in format 123456789-X
|
14
14
|
# You can pass 13 to generate new 13 sign code
|
15
|
-
def isbn(base
|
15
|
+
def isbn(base: 10)
|
16
16
|
base == 13 ? generate_base13_isbn : generate_base10_isbn
|
17
17
|
end
|
18
18
|
|
19
19
|
# By default generates 13 sign ean code in format 1234567890123
|
20
20
|
# You can pass 8 to generate ean8 code
|
21
|
-
def ean(base
|
21
|
+
def ean(base: 13)
|
22
22
|
base == 8 ? generate_base8_ean : generate_base13_ean
|
23
23
|
end
|
24
24
|
|
25
25
|
def rut
|
26
|
-
value = Number.number(8)
|
26
|
+
value = Number.number(digits: 8).to_s
|
27
27
|
vd = rut_verificator_digit(value)
|
28
28
|
value << "-#{vd}"
|
29
29
|
end
|
30
30
|
|
31
31
|
# By default generates a Singaporean NRIC ID for someone
|
32
32
|
# who is born between the age of 18 and 65.
|
33
|
-
def nric(min_age
|
34
|
-
birthyear = Date.birthday(min_age, max_age).year
|
33
|
+
def nric(min_age: 18, max_age: 65)
|
34
|
+
birthyear = Date.birthday(min_age: min_age, max_age: max_age).year
|
35
35
|
prefix = birthyear < 2000 ? 'S' : 'T'
|
36
36
|
values = birthyear.to_s[-2..-1]
|
37
37
|
values << regexify(/\d{5}/)
|
@@ -7,15 +7,15 @@ module Faker
|
|
7
7
|
fetch('color.name')
|
8
8
|
end
|
9
9
|
|
10
|
-
def promotion_code(digits
|
10
|
+
def promotion_code(digits: 6)
|
11
11
|
[
|
12
12
|
fetch('commerce.promotion_code.adjective'),
|
13
13
|
fetch('commerce.promotion_code.noun'),
|
14
|
-
Faker::Number.number(digits)
|
14
|
+
Faker::Number.number(digits: digits)
|
15
15
|
].join
|
16
16
|
end
|
17
17
|
|
18
|
-
def department(max
|
18
|
+
def department(max: 3, fixed_amount: false)
|
19
19
|
num = max if fixed_amount
|
20
20
|
num ||= 1 + rand(max)
|
21
21
|
|
@@ -34,7 +34,7 @@ module Faker
|
|
34
34
|
fetch('commerce.product_name.material')
|
35
35
|
end
|
36
36
|
|
37
|
-
def price(range
|
37
|
+
def price(range: 0..100.0, as_string: false)
|
38
38
|
price = (rand(range) * 100).floor / 100.0
|
39
39
|
if as_string
|
40
40
|
price_parts = price.to_s.split('.')
|
@@ -126,7 +126,7 @@ module Faker
|
|
126
126
|
end
|
127
127
|
|
128
128
|
# Get a random Polish register of national economy number. More info https://pl.wikipedia.org/wiki/REGON
|
129
|
-
def polish_register_of_national_economy(length
|
129
|
+
def polish_register_of_national_economy(length: 9)
|
130
130
|
raise ArgumentError, 'Length should be 9 or 14' unless [9, 14].include? length
|
131
131
|
|
132
132
|
random_digits = []
|
@@ -198,7 +198,7 @@ module Faker
|
|
198
198
|
def luhn_algorithm(number)
|
199
199
|
multiplications = []
|
200
200
|
|
201
|
-
number.reverse.split(//).each_with_index do |digit, i|
|
201
|
+
number.to_s.reverse.split(//).each_with_index do |digit, i|
|
202
202
|
multiplications << if i.even?
|
203
203
|
digit.to_i * 2
|
204
204
|
else
|
@@ -7,15 +7,15 @@ module Faker
|
|
7
7
|
ACRONYM = 1
|
8
8
|
URL_LOGO = 2
|
9
9
|
|
10
|
-
def coin_name(coin
|
10
|
+
def coin_name(coin: coin_array)
|
11
11
|
coin[COIN_NAME]
|
12
12
|
end
|
13
13
|
|
14
|
-
def acronym(coin
|
14
|
+
def acronym(coin: coin_array)
|
15
15
|
coin[ACRONYM]
|
16
16
|
end
|
17
17
|
|
18
|
-
def url_logo(coin
|
18
|
+
def url_logo(coin: coin_array)
|
19
19
|
coin[URL_LOGO]
|
20
20
|
end
|
21
21
|
|
@@ -25,7 +25,12 @@ module Faker
|
|
25
25
|
|
26
26
|
def coin_hash
|
27
27
|
coin = coin_array
|
28
|
-
|
28
|
+
|
29
|
+
{
|
30
|
+
name: coin_name(coin: coin),
|
31
|
+
acronym: acronym(coin: coin),
|
32
|
+
url_logo: url_logo(coin: coin)
|
33
|
+
}
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
data/lib/faker/default/date.rb
CHANGED
@@ -3,45 +3,45 @@
|
|
3
3
|
module Faker
|
4
4
|
class Date < Base
|
5
5
|
class << self
|
6
|
-
def between(from
|
6
|
+
def between(from:, to:)
|
7
7
|
from = get_date_object(from)
|
8
8
|
to = get_date_object(to)
|
9
9
|
|
10
10
|
Faker::Base.rand_in_range(from, to)
|
11
11
|
end
|
12
12
|
|
13
|
-
def between_except(from
|
13
|
+
def between_except(from:, to:, excepted:)
|
14
14
|
raise ArgumentError, 'From date, to date and excepted date must not be the same' if from == to && to == excepted
|
15
15
|
|
16
16
|
excepted = get_date_object(excepted)
|
17
17
|
|
18
18
|
loop do
|
19
|
-
date = between(from, to)
|
19
|
+
date = between(from: from, to: to)
|
20
20
|
break date.to_date if date != excepted
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def forward(days
|
24
|
+
def forward(days: 365)
|
25
25
|
from = ::Date.today + 1
|
26
26
|
to = ::Date.today + days
|
27
27
|
|
28
|
-
between(from, to).to_date
|
28
|
+
between(from: from, to: to).to_date
|
29
29
|
end
|
30
30
|
|
31
|
-
def backward(days
|
31
|
+
def backward(days: 365)
|
32
32
|
from = ::Date.today - days
|
33
33
|
to = ::Date.today - 1
|
34
34
|
|
35
|
-
between(from, to).to_date
|
35
|
+
between(from: from, to: to).to_date
|
36
36
|
end
|
37
37
|
|
38
|
-
def birthday(min_age
|
38
|
+
def birthday(min_age: 18, max_age: 65)
|
39
39
|
t = ::Date.today
|
40
40
|
|
41
41
|
from = birthday_date(t, max_age)
|
42
42
|
to = birthday_date(t, min_age)
|
43
43
|
|
44
|
-
between(from, to).to_date
|
44
|
+
between(from: from, to: to).to_date
|
45
45
|
end
|
46
46
|
|
47
47
|
private
|
data/lib/faker/default/device.rb
CHANGED
@@ -4,7 +4,7 @@ module Faker
|
|
4
4
|
class Device < Base
|
5
5
|
class << self
|
6
6
|
def build_number
|
7
|
-
Faker::Number.between(1, 500)
|
7
|
+
Faker::Number.between(from: 1, to: 500)
|
8
8
|
end
|
9
9
|
|
10
10
|
def manufacturer
|
@@ -24,7 +24,7 @@ module Faker
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def version
|
27
|
-
Faker::Number.between(1, 1000)
|
27
|
+
Faker::Number.between(from: 1, to: 1000)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -9,7 +9,7 @@ module Faker
|
|
9
9
|
def british_driving_licence(last_name: Faker::Name.last_name,
|
10
10
|
initials: Faker::Name.initials,
|
11
11
|
gender: random_gender,
|
12
|
-
date_of_birth: Faker::Date.birthday(18, 65))
|
12
|
+
date_of_birth: Faker::Date.birthday(min_age: 18, max_age: 65))
|
13
13
|
[
|
14
14
|
gb_licence_padding(last_name, 5),
|
15
15
|
gb_licence_year(date_of_birth, gender),
|
@@ -19,7 +19,7 @@ module Faker
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def northern_irish_driving_licence
|
22
|
-
Faker::Number.number(8)
|
22
|
+
Faker::Number.number(digits: 8).to_s
|
23
23
|
end
|
24
24
|
|
25
25
|
def uk_driving_licence(*args)
|
@@ -5,8 +5,6 @@ module Faker
|
|
5
5
|
flexible :educator
|
6
6
|
|
7
7
|
class << self
|
8
|
-
extend Gem::Deprecate
|
9
|
-
|
10
8
|
def university
|
11
9
|
"#{parse('educator.name')} #{fetch('educator.tertiary.type')}"
|
12
10
|
end
|
@@ -16,7 +14,6 @@ module Faker
|
|
16
14
|
end
|
17
15
|
|
18
16
|
alias course degree
|
19
|
-
deprecate :course, :course_name, 2018, 10
|
20
17
|
|
21
18
|
def subject
|
22
19
|
fetch('educator.tertiary.degree.subject')
|
data/lib/faker/default/file.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Faker
|
4
4
|
class File < Base
|
5
5
|
class << self
|
6
|
-
def dir(segment_count
|
6
|
+
def dir(segment_count: 3, root: nil, directory_separator: '/')
|
7
7
|
Array
|
8
8
|
.new(segment_count) { Faker::Internet.slug }
|
9
9
|
.unshift(root)
|
@@ -20,8 +20,8 @@ module Faker
|
|
20
20
|
fetch('file.mime_type')
|
21
21
|
end
|
22
22
|
|
23
|
-
def file_name(dir
|
24
|
-
dir ||= dir(1)
|
23
|
+
def file_name(dir: nil, name: nil, ext: nil, directory_separator: '/')
|
24
|
+
dir ||= dir(segment_count: 1)
|
25
25
|
name ||= Faker::Lorem.word.downcase
|
26
26
|
ext ||= extension
|
27
27
|
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Faker
|
4
4
|
class Fillmurray < Base
|
5
5
|
class << self
|
6
|
-
def image(grayscale
|
6
|
+
def image(grayscale: false, width: 200, height: 200)
|
7
7
|
raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
|
8
8
|
raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
|
9
9
|
raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)
|
10
10
|
|
11
|
-
|
11
|
+
"https://www.fillmurray.com#{'/g' if grayscale == true}/#{width}/#{height}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -26,7 +26,7 @@ module Faker
|
|
26
26
|
template.gsub('L', luhn_digit.to_s)
|
27
27
|
end
|
28
28
|
|
29
|
-
def vat_number(country
|
29
|
+
def vat_number(country: 'BR')
|
30
30
|
numerify(fetch("finance.vat_number.#{country}"))
|
31
31
|
rescue I18n::MissingTranslationData
|
32
32
|
raise ArgumentError, "Could not find vat number for #{country}"
|
@@ -8,8 +8,8 @@ module Faker
|
|
8
8
|
random_word =~ /\s/ ? word : random_word
|
9
9
|
end
|
10
10
|
|
11
|
-
def words(
|
12
|
-
resolved_num = resolve(
|
11
|
+
def words(number: 3, supplemental: false, spaces_allowed: false)
|
12
|
+
resolved_num = resolve(number)
|
13
13
|
word_list = (
|
14
14
|
translate('faker.hipster.words') +
|
15
15
|
(supplemental ? translate('faker.lorem.words') : [])
|
@@ -22,36 +22,36 @@ module Faker
|
|
22
22
|
words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
|
23
23
|
end
|
24
24
|
|
25
|
-
def sentence(word_count
|
26
|
-
words(word_count + rand(random_words_to_add.to_i).to_i, supplemental, true).join(' ').capitalize + '.'
|
25
|
+
def sentence(word_count: 4, supplemental: false, random_words_to_add: 6)
|
26
|
+
words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.'
|
27
27
|
end
|
28
28
|
|
29
|
-
def sentences(
|
29
|
+
def sentences(number: 3, supplemental: false)
|
30
30
|
[].tap do |sentences|
|
31
|
-
1.upto(resolve(
|
32
|
-
sentences << sentence(3, supplemental)
|
31
|
+
1.upto(resolve(number)) do
|
32
|
+
sentences << sentence(word_count: 3, supplemental: supplemental)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def paragraph(sentence_count
|
38
|
-
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ')
|
37
|
+
def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
|
38
|
+
sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
|
39
39
|
end
|
40
40
|
|
41
|
-
def paragraphs(
|
41
|
+
def paragraphs(number: 3, supplemental: false)
|
42
42
|
[].tap do |paragraphs|
|
43
|
-
1.upto(resolve(
|
44
|
-
paragraphs << paragraph(3, supplemental)
|
43
|
+
1.upto(resolve(number)) do
|
44
|
+
paragraphs << paragraph(sentence_count: 3, supplemental: supplemental)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def paragraph_by_chars(
|
50
|
-
paragraph = paragraph(3, supplemental)
|
49
|
+
def paragraph_by_chars(characters: 256, supplemental: false)
|
50
|
+
paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
|
51
51
|
|
52
|
-
paragraph += ' ' + paragraph(3, supplemental) while paragraph.length <
|
52
|
+
paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < characters
|
53
53
|
|
54
|
-
paragraph[0...
|
54
|
+
paragraph[0...characters - 1] + '.'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -12,6 +12,9 @@ module Faker
|
|
12
12
|
].freeze
|
13
13
|
ZA_RACE_DIGIT = '8'
|
14
14
|
ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
|
15
|
+
BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/
|
16
|
+
BRAZILIAN_ID_FROM = 10_000_000
|
17
|
+
BRAZILIAN_ID_TO = 99_999_999
|
15
18
|
|
16
19
|
class << self
|
17
20
|
def valid
|
@@ -29,7 +32,7 @@ module Faker
|
|
29
32
|
end
|
30
33
|
|
31
34
|
def spanish_citizen_number
|
32
|
-
num = Faker::Number.number(8)
|
35
|
+
num = Faker::Number.number(digits: 8)
|
33
36
|
mod = num.to_i % 23
|
34
37
|
check = CHECKS[mod]
|
35
38
|
"#{num}-#{check}"
|
@@ -37,7 +40,7 @@ module Faker
|
|
37
40
|
|
38
41
|
def spanish_foreign_citizen_number
|
39
42
|
code = 'XYZ'
|
40
|
-
digits = Faker::Number.number(7)
|
43
|
+
digits = Faker::Number.number(digits: 7)
|
41
44
|
prefix = code[rand(code.length)]
|
42
45
|
prefix_val = 'XYZ'.index(prefix).to_s
|
43
46
|
mod = "#{prefix_val}#{digits}".to_i % 23
|
@@ -48,7 +51,7 @@ module Faker
|
|
48
51
|
def valid_south_african_id_number
|
49
52
|
id_number = [
|
50
53
|
Faker::Date.birthday.strftime('%y%m%d'),
|
51
|
-
Faker::Number.number(4),
|
54
|
+
Faker::Number.number(digits: 4),
|
52
55
|
ZA_CITIZENSHIP_DIGITS.sample(random: Faker::Config.random),
|
53
56
|
ZA_RACE_DIGIT
|
54
57
|
].join
|
@@ -60,14 +63,14 @@ module Faker
|
|
60
63
|
|
61
64
|
def invalid_south_african_id_number
|
62
65
|
invalid_date_of_birth = [
|
63
|
-
Faker::Number.number(2),
|
64
|
-
Faker::Number.between(13, 99),
|
65
|
-
Faker::Number.between(32, 99)
|
66
|
+
Faker::Number.number(digits: 2),
|
67
|
+
Faker::Number.between(from: 13, to: 99),
|
68
|
+
Faker::Number.between(from: 32, to: 99)
|
66
69
|
].map(&:to_s).join
|
67
70
|
|
68
71
|
id_number = [
|
69
72
|
invalid_date_of_birth,
|
70
|
-
Faker::Number.number(4),
|
73
|
+
Faker::Number.number(digits: 4),
|
71
74
|
ZA_CITIZENSHIP_DIGITS.sample(random: Faker::Config.random),
|
72
75
|
ZA_RACE_DIGIT
|
73
76
|
].join
|
@@ -76,13 +79,24 @@ module Faker
|
|
76
79
|
end
|
77
80
|
|
78
81
|
def brazilian_citizen_number(formatted: false)
|
79
|
-
digits = Faker::Number.leading_zero_number(9) until digits&.match(/(\d)((?!\1)\d)+/)
|
82
|
+
digits = Faker::Number.leading_zero_number(digits: 9) until digits&.match(/(\d)((?!\1)\d)+/)
|
80
83
|
first_digit = brazilian_citizen_number_checksum_digit(digits)
|
81
84
|
second_digit = brazilian_citizen_number_checksum_digit(digits + first_digit)
|
82
85
|
number = [digits, first_digit, second_digit].join
|
83
86
|
formatted ? format('%s.%s.%s-%s', *number.scan(/\d{2,3}/).flatten) : number
|
84
87
|
end
|
85
88
|
|
89
|
+
alias brazilian_cpf brazilian_citizen_number
|
90
|
+
|
91
|
+
def brazilian_id(formatted: false)
|
92
|
+
digits = Faker::Number.between(to: BRAZILIAN_ID_FROM, from: BRAZILIAN_ID_TO).to_s
|
93
|
+
check_digit = brazilian_id_checksum_digit(digits)
|
94
|
+
number = [digits, check_digit].join
|
95
|
+
formatted ? format('%s.%s.%s-%s', *number.scan(BRAZILIAN_ID_FORMAT).flatten) : number
|
96
|
+
end
|
97
|
+
|
98
|
+
alias brazilian_rg brazilian_id
|
99
|
+
|
86
100
|
private
|
87
101
|
|
88
102
|
def south_african_id_checksum_digit(id_number)
|
@@ -104,13 +118,36 @@ module Faker
|
|
104
118
|
end
|
105
119
|
|
106
120
|
def brazilian_citizen_number_checksum_digit(digits)
|
107
|
-
|
121
|
+
checksum = brazilian_document_checksum(digits)
|
122
|
+
brazilian_document_digit(checksum)
|
123
|
+
end
|
124
|
+
|
125
|
+
def brazilian_id_checksum_digit(digits)
|
126
|
+
checksum = brazilian_document_checksum(digits)
|
127
|
+
brazilian_document_digit(checksum, id: true)
|
128
|
+
end
|
129
|
+
|
130
|
+
def brazilian_document_checksum(digits)
|
131
|
+
digits.chars.each_with_index.inject(0) do |acc, (digit, i)|
|
108
132
|
acc + digit.to_i * (digits.size + 1 - i)
|
109
133
|
end * 10
|
110
|
-
|
134
|
+
end
|
135
|
+
|
136
|
+
def brazilian_document_digit(checksum, id = false)
|
137
|
+
remainder = checksum % 11
|
138
|
+
id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
|
139
|
+
end
|
140
|
+
|
141
|
+
def brazilian_citizen_number_digit(remainder)
|
111
142
|
remainder == 10 ? '0' : remainder.to_s
|
112
143
|
end
|
113
144
|
|
145
|
+
def brazilian_id_digit(remainder)
|
146
|
+
subtraction = 11 - remainder.to_i
|
147
|
+
digits = { 10 => 'X', 11 => '0' }
|
148
|
+
digits.include?(subtraction) ? digits[subtraction] : subtraction.to_s
|
149
|
+
end
|
150
|
+
|
114
151
|
def _translate(key)
|
115
152
|
parse("id_number.#{key}")
|
116
153
|
end
|