ffaker 2.22.0 → 2.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +120 -17
- data/Gemfile +15 -0
- data/README.md +3 -2
- data/REFERENCE.md +885 -868
- data/Rakefile +7 -7
- data/ffaker.gemspec +2 -6
- data/lib/ffaker/address.rb +4 -4
- data/lib/ffaker/address_fr.rb +3 -5
- data/lib/ffaker/address_it.rb +1 -4
- data/lib/ffaker/avatar.rb +11 -3
- data/lib/ffaker/bank.rb +1 -1
- data/lib/ffaker/bank_us.rb +33 -0
- data/lib/ffaker/book.rb +10 -2
- data/lib/ffaker/cheesy_lingo.rb +2 -2
- data/lib/ffaker/code.rb +1 -1
- data/lib/ffaker/company.rb +1 -1
- data/lib/ffaker/company_fr.rb +1 -1
- data/lib/ffaker/crypto.rb +14 -0
- data/lib/ffaker/date.rb +9 -0
- data/lib/ffaker/filesystem.rb +12 -2
- data/lib/ffaker/identification_br.rb +2 -11
- data/lib/ffaker/identification_ec.rb +1 -1
- data/lib/ffaker/identification_es_cl.rb +1 -1
- data/lib/ffaker/identification_kr.rb +10 -3
- data/lib/ffaker/identification_pl.rb +2 -2
- data/lib/ffaker/image.rb +28 -4
- data/lib/ffaker/lorem_ja.rb +1 -1
- data/lib/ffaker/lorem_ru.rb +1 -1
- data/lib/ffaker/movie.rb +1 -1
- data/lib/ffaker/name_fr.rb +4 -3
- data/lib/ffaker/number.rb +4 -0
- data/lib/ffaker/phone_number_de.rb +3 -3
- data/lib/ffaker/skill.rb +1 -1
- data/lib/ffaker/ssn.rb +4 -2
- data/lib/ffaker/string.rb +1 -1
- data/lib/ffaker/utils/module_utils.rb +2 -2
- data/lib/ffaker/utils/unique_utils.rb +9 -5
- data/lib/ffaker/version.rb +1 -1
- data/lib/ffaker.rb +60 -191
- data/scripts/reference.rb +8 -10
- data/test/helper.rb +1 -1
- data/test/test_avatar.rb +30 -7
- data/test/test_bank_us.rb +35 -0
- data/test/test_book.rb +29 -0
- data/test/test_crypto.rb +15 -0
- data/test/test_date.rb +11 -1
- data/test/test_filesystem.rb +28 -2
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_identification.rb +12 -2
- data/test/test_identification_ec.rb +1 -1
- data/test/test_identification_es_mx.rb +3 -1
- data/test/test_identification_it.rb +12 -1
- data/test/test_identification_kr.rb +3 -3
- data/test/test_image.rb +51 -5
- data/test/test_internet.rb +3 -1
- data/test/test_internet_se.rb +3 -1
- data/test/test_lorem_br.rb +1 -1
- data/test/test_lorem_ru.rb +1 -1
- data/test/test_lorem_ua.rb +1 -1
- data/test/test_name_ua.rb +1 -1
- data/test/test_number.rb +13 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_unique_utils.rb +4 -0
- data/test/test_units.rb +6 -6
- data/test/test_units_english.rb +15 -15
- data/test/test_units_metric.rb +15 -15
- metadata +7 -45
data/Rakefile
CHANGED
@@ -23,6 +23,10 @@ module Test
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
require 'rubocop/rake_task'
|
27
|
+
|
28
|
+
RuboCop::RakeTask.new
|
29
|
+
|
26
30
|
#############################################################################
|
27
31
|
#
|
28
32
|
# Helper functions
|
@@ -80,14 +84,9 @@ rescue LoadError
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
83
|
-
|
84
|
-
#
|
85
|
-
# Packaging tasks
|
86
|
-
#
|
87
|
-
#############################################################################
|
88
|
-
|
87
|
+
desc 'Packaging tasks'
|
89
88
|
task release: :build do
|
90
|
-
unless `git branch
|
89
|
+
unless `git branch`.match?(/^\* main$/)
|
91
90
|
puts 'You must be on the main branch to release!'
|
92
91
|
exit!
|
93
92
|
end
|
@@ -103,6 +102,7 @@ task build: %i[validate reference] do
|
|
103
102
|
sh "gem build #{gemspec_file} --output=pkg/#{gem_file}"
|
104
103
|
end
|
105
104
|
|
105
|
+
desc 'Validate library files'
|
106
106
|
task :validate do
|
107
107
|
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
108
108
|
unless libfiles.empty?
|
data/ffaker.gemspec
CHANGED
@@ -29,16 +29,12 @@ Gem::Specification.new do |s|
|
|
29
29
|
s.files = `git ls-files`
|
30
30
|
.split("\n")
|
31
31
|
.sort
|
32
|
-
.
|
33
|
-
.
|
32
|
+
.grep_v(/^\./)
|
33
|
+
.grep_v(/^(rdoc|pkg)/)
|
34
34
|
|
35
35
|
s.metadata = {
|
36
36
|
'changelog_uri' => 'https://github.com/ffaker/ffaker/blob/main/Changelog.md',
|
37
37
|
'documentation_uri' => 'https://github.com/ffaker/ffaker/blob/main/REFERENCE.md',
|
38
38
|
'rubygems_mfa_required' => 'true'
|
39
39
|
}
|
40
|
-
|
41
|
-
s.add_development_dependency 'rake', '~> 13.0'
|
42
|
-
s.add_development_dependency 'rubocop'
|
43
|
-
s.add_development_dependency 'test-unit'
|
44
40
|
end
|
data/lib/ffaker/address.rb
CHANGED
@@ -36,10 +36,10 @@ module FFaker
|
|
36
36
|
|
37
37
|
def city
|
38
38
|
case rand(0..3)
|
39
|
-
when 0 then
|
40
|
-
when 1 then
|
41
|
-
when 2 then
|
42
|
-
when 3 then
|
39
|
+
when 0 then "#{city_prefix} #{Name.first_name}#{city_suffix}"
|
40
|
+
when 1 then "#{city_prefix} #{Name.first_name}"
|
41
|
+
when 2 then "#{Name.first_name}#{city_suffix}"
|
42
|
+
when 3 then "#{Name.last_name}#{city_suffix}"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/ffaker/address_fr.rb
CHANGED
@@ -14,11 +14,9 @@ module FFaker
|
|
14
14
|
POSTAL_CODE_FORMATS = ['#####', '97###', '2A###', '2B###'].freeze
|
15
15
|
|
16
16
|
def street_address
|
17
|
-
|
18
|
-
fetch_sample(MOD)
|
19
|
-
|
20
|
-
fetch_sample(TYPE) + ' ' +
|
21
|
-
FFaker::NameFR.name
|
17
|
+
<<~TEXT.chomp
|
18
|
+
#{FFaker.numerify(fetch_sample(NUM))}#{fetch_sample(MOD)}#{fetch_sample(SEP)}#{fetch_sample(TYPE)} #{FFaker::NameFR.name}
|
19
|
+
TEXT
|
22
20
|
end
|
23
21
|
|
24
22
|
def postal_code
|
data/lib/ffaker/address_it.rb
CHANGED
@@ -11,10 +11,7 @@ module FFaker
|
|
11
11
|
POSTAL_CODE_FORMATS = ['#####'].freeze
|
12
12
|
|
13
13
|
def street_address
|
14
|
-
FFaker.numerify(fetch_sample(NUM))
|
15
|
-
fetch_sample(SEP) +
|
16
|
-
fetch_sample(TYPE) + ' ' +
|
17
|
-
FFaker::NameIT.name
|
14
|
+
"#{FFaker.numerify(fetch_sample(NUM))}#{fetch_sample(SEP)}#{fetch_sample(TYPE)} #{FFaker::NameIT.name}"
|
18
15
|
end
|
19
16
|
|
20
17
|
def postal_code
|
data/lib/ffaker/avatar.rb
CHANGED
@@ -7,16 +7,24 @@ module FFaker
|
|
7
7
|
|
8
8
|
SUPPORTED_FORMATS = %w[png jpg bmp].freeze
|
9
9
|
|
10
|
-
def image(slug
|
10
|
+
def image(*args, slug: nil, size: '300x300', format: 'png', bgset: nil)
|
11
|
+
if args.any?
|
12
|
+
warn "Positional arguments for Avatar##{__method__} are deprecated. Please use keyword arguments."
|
13
|
+
slug = args[0]
|
14
|
+
size = args[1] if args.size > 1
|
15
|
+
format = args[2] if args.size > 2
|
16
|
+
bgset = args[3] if args.size > 3
|
17
|
+
end
|
18
|
+
|
11
19
|
check_passed_params(size, format, bgset)
|
12
20
|
slug ||= FFaker::Lorem.words.join
|
13
|
-
"https://robohash.org/#{slug}.#{format}?size=#{size}#{
|
21
|
+
"https://robohash.org/#{slug}.#{format}?size=#{size}#{"&bgset=bg#{bgset}" if bgset}"
|
14
22
|
end
|
15
23
|
|
16
24
|
private
|
17
25
|
|
18
26
|
def check_passed_params(size, format, bgset)
|
19
|
-
invalid_size_error unless size
|
27
|
+
invalid_size_error unless size.match?(/^[0-9]+x[0-9]+$/)
|
20
28
|
invalid_format_error unless SUPPORTED_FORMATS.include?(format)
|
21
29
|
invalid_background_number unless bgset.nil? || (1..2).cover?(bgset.to_i)
|
22
30
|
end
|
data/lib/ffaker/bank.rb
CHANGED
@@ -110,7 +110,7 @@ module FFaker
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def check_country_existence(country_code)
|
113
|
-
return if COUNTRIES.
|
113
|
+
return if COUNTRIES.key?(country_code.upcase)
|
114
114
|
|
115
115
|
raise ArgumentError, "Unexpected country code: '#{country_code}'"
|
116
116
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module BankUS
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def account_number(min_digits: 9, max_digits: 17)
|
9
|
+
FFaker.numerify('#' * rand(min_digits..max_digits))
|
10
|
+
end
|
11
|
+
|
12
|
+
def routing_number
|
13
|
+
partial_routing_number = FFaker.numerify('########')
|
14
|
+
ninth_digit = generate_ninth_digit(partial_routing_number)
|
15
|
+
|
16
|
+
"#{partial_routing_number}#{ninth_digit}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def generate_ninth_digit(num_string)
|
22
|
+
# This leverages the `Modules 10, Straight Summation` used for routing_numbers
|
23
|
+
# See http://www.sxlist.com/techref/ecommerce/bank/routingnumber/index.htm
|
24
|
+
# for more details
|
25
|
+
num_array = num_string.chars.map(&:to_i)
|
26
|
+
(
|
27
|
+
(7 * (num_array[0] + num_array[3] + num_array[6])) +
|
28
|
+
(3 * (num_array[1] + num_array[4] + num_array[7])) +
|
29
|
+
(9 * (num_array[2] + num_array[5]))
|
30
|
+
) % 10
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/ffaker/book.rb
CHANGED
@@ -30,8 +30,16 @@ module FFaker
|
|
30
30
|
FFaker::Lorem.paragraph(sentence_count)
|
31
31
|
end
|
32
32
|
|
33
|
-
def cover(slug
|
34
|
-
|
33
|
+
def cover(*args, slug: nil, size: '300x300', format: 'png', bgset: nil)
|
34
|
+
if args.any?
|
35
|
+
warn "Positional arguments for Book##{__method__} are deprecated. Please use keyword arguments."
|
36
|
+
slug = args[0]
|
37
|
+
size = args[1] if args.size > 1
|
38
|
+
format = args[2] if args.size > 2
|
39
|
+
bgset = args[3] if args.size > 3
|
40
|
+
end
|
41
|
+
|
42
|
+
FFaker::Avatar.image(slug: slug, size: size, format: format, bgset: bgset)
|
35
43
|
end
|
36
44
|
|
37
45
|
def orly_cover(name = title, book_author = author, top_text = genre)
|
data/lib/ffaker/cheesy_lingo.rb
CHANGED
data/lib/ffaker/code.rb
CHANGED
data/lib/ffaker/company.rb
CHANGED
@@ -13,7 +13,7 @@ module FFaker
|
|
13
13
|
case rand(0..2)
|
14
14
|
when 0 then "#{Name.last_name} #{suffix}"
|
15
15
|
when 1 then "#{Name.last_name}-#{Name.last_name}"
|
16
|
-
when 2 then
|
16
|
+
when 2 then "#{Name.last_name}, #{Name.last_name} and #{Name.last_name}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/ffaker/company_fr.rb
CHANGED
@@ -11,7 +11,7 @@ module FFaker
|
|
11
11
|
case rand(0..2)
|
12
12
|
when 0 then "#{NameFR.last_name} #{suffix}"
|
13
13
|
when 1 then "#{NameFR.last_name}-#{NameFR.last_name}"
|
14
|
-
when 2 then
|
14
|
+
when 2 then "#{NameFR.last_name}, #{NameFR.last_name} and #{NameFR.last_name}"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/lib/ffaker/date.rb
CHANGED
@@ -27,5 +27,14 @@ module FFaker
|
|
27
27
|
|
28
28
|
between(from, to)
|
29
29
|
end
|
30
|
+
|
31
|
+
# Random birthday date (maximum age between 18 and 65)
|
32
|
+
# Keyword arguments: min_age, max_age
|
33
|
+
def birthday(min_age: 18, max_age: 65)
|
34
|
+
from = ::Date.today.prev_year(max_age + 1).next_day
|
35
|
+
to = ::Date.today.prev_year(min_age)
|
36
|
+
|
37
|
+
between(from, to)
|
38
|
+
end
|
30
39
|
end
|
31
40
|
end
|
data/lib/ffaker/filesystem.rb
CHANGED
@@ -17,8 +17,18 @@ module FFaker
|
|
17
17
|
Lorem.words.join(directory_separator)
|
18
18
|
end
|
19
19
|
|
20
|
-
def file_name(
|
21
|
-
|
20
|
+
def file_name(
|
21
|
+
*args,
|
22
|
+
dir: directory, name: Lorem.word.downcase, ext: extension, directory_separator: File::SEPARATOR
|
23
|
+
)
|
24
|
+
if args.any?
|
25
|
+
warn "Positional arguments for Filesystem##{__method__} are deprecated. Please use keyword arguments."
|
26
|
+
dir = args[0]
|
27
|
+
name = args[1] if args.size > 1
|
28
|
+
ext = args[2] if args.size > 2
|
29
|
+
directory_separator = args[3] if args.size > 3
|
30
|
+
end
|
31
|
+
|
22
32
|
"#{dir}#{directory_separator}#{name}.#{ext}"
|
23
33
|
end
|
24
34
|
end
|
@@ -17,11 +17,7 @@ module FFaker
|
|
17
17
|
|
18
18
|
def pretty_cpf
|
19
19
|
cpf_numbers = cpf
|
20
|
-
|
21
|
-
cpf_numbers[0..2],
|
22
|
-
cpf_numbers[3..5],
|
23
|
-
cpf_numbers[6..8],
|
24
|
-
cpf_numbers[9..10])
|
20
|
+
"#{cpf_numbers[0..2]}.#{cpf_numbers[3..5]}.#{cpf_numbers[6..8]}-#{cpf_numbers[9..10]}"
|
25
21
|
end
|
26
22
|
|
27
23
|
def cnpj
|
@@ -32,12 +28,7 @@ module FFaker
|
|
32
28
|
|
33
29
|
def pretty_cnpj
|
34
30
|
cnpj_numbers = cnpj.to_s.rjust(14, '0')
|
35
|
-
|
36
|
-
cnpj_numbers[0..1],
|
37
|
-
cnpj_numbers[2..4],
|
38
|
-
cnpj_numbers[5..7],
|
39
|
-
cnpj_numbers[8..11],
|
40
|
-
cnpj_numbers[12..14])
|
31
|
+
"#{cnpj_numbers[0..1]}.#{cnpj_numbers[2..4]}.#{cnpj_numbers[5..7]}/#{cnpj_numbers[8..11]}-#{cnpj_numbers[12..14]}"
|
41
32
|
end
|
42
33
|
|
43
34
|
def rg
|
@@ -20,7 +20,7 @@ module FFaker
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def dv(rut)
|
23
|
-
total = rut.to_s.rjust(8, '0').
|
23
|
+
total = rut.to_s.rjust(8, '0').chars.zip(%w[3 2 7 6 5 4 3 2]).sum do |a, b|
|
24
24
|
a.to_i * b.to_i
|
25
25
|
end
|
26
26
|
(11 - (total % 11)).to_s.gsub('10', 'k').gsub('11', '0')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module FFaker
|
4
|
-
module
|
4
|
+
module IdentificationKR
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
@@ -11,8 +11,15 @@ module FFaker
|
|
11
11
|
birth = fetch_sample(::Date.new(1970, 1, 1)..::Date.new(1999, 12, 31)).strftime('%y%d%m')
|
12
12
|
sex = fetch_sample([1, 2])
|
13
13
|
loc = FFaker.numerify("#{fetch_sample(Array('00'..'95'))}###")
|
14
|
-
a, b, c, d, e, f, g, h, i, j, k, l = "#{birth}#{sex}#{loc}".
|
15
|
-
checksum = (
|
14
|
+
a, b, c, d, e, f, g, h, i, j, k, l = "#{birth}#{sex}#{loc}".chars.map(&:to_i)
|
15
|
+
checksum = (
|
16
|
+
11 - (
|
17
|
+
(
|
18
|
+
(2 * a) + (3 * b) + (4 * c) + (5 * d) + (6 * e) + (7 * f) + (8 * g) + (9 * h) +
|
19
|
+
(2 * i) + (3 * j) + (4 * k) + (5 * l)
|
20
|
+
) % 11
|
21
|
+
)
|
22
|
+
) % 10
|
16
23
|
"#{birth}-#{sex}#{loc}#{checksum}"
|
17
24
|
end
|
18
25
|
end
|
@@ -63,14 +63,14 @@ module FFaker
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def pesel_checksum(date, serial_number)
|
66
|
-
pesel_digits = "#{date}#{serial_number}".
|
66
|
+
pesel_digits = "#{date}#{serial_number}".chars.map(&:to_i)
|
67
67
|
a, b, c, d, e, f, g, h, i, j = pesel_digits
|
68
68
|
((a * 9) + (b * 7) + (c * 3) + d + (e * 9) + (f * 7) + (g * 3) + h + (i * 9) + (j * 7)) % 10
|
69
69
|
end
|
70
70
|
|
71
71
|
def identity_card_checksum(letter_part, number_part)
|
72
72
|
a, b, c = letter_part.codepoints.map { |codepoints| codepoints - 55 }
|
73
|
-
d, e, f, g, h = number_part.
|
73
|
+
d, e, f, g, h = number_part.chars.map(&:to_i)
|
74
74
|
((a * 7) + (b * 3) + c + (7 * d) + (3 * e) + f + (7 * g) + (3 * h)) % 10
|
75
75
|
end
|
76
76
|
end
|
data/lib/ffaker/image.rb
CHANGED
@@ -11,7 +11,18 @@ module FFaker
|
|
11
11
|
|
12
12
|
SUPPORTED_FORMATS = %w[png jpg jpeg gif].freeze
|
13
13
|
|
14
|
-
|
14
|
+
## `*args` for old format support, it will be removed with deprecation
|
15
|
+
# rubocop:disable Metrics/ParameterLists
|
16
|
+
def url(*args, size: '300x300', format: 'png', bg_color: :random, text_color: :random, text: nil)
|
17
|
+
if args.any?
|
18
|
+
warn "Positional arguments for Image##{__method__} are deprecated. Please use keyword arguments."
|
19
|
+
size = args[0]
|
20
|
+
format = args[1] if args.size > 1
|
21
|
+
bg_color = args[2] if args.size > 2
|
22
|
+
text_color = args[3] if args.size > 3
|
23
|
+
text = args[4] if args.size > 4
|
24
|
+
end
|
25
|
+
|
15
26
|
check_size!(size)
|
16
27
|
check_format!(format)
|
17
28
|
|
@@ -21,20 +32,33 @@ module FFaker
|
|
21
32
|
|
22
33
|
"https://dummyimage.com/#{size}/#{bg_color}/#{text_color}.#{format}?text=#{text}"
|
23
34
|
end
|
35
|
+
# rubocop:enable Metrics/ParameterLists
|
36
|
+
|
37
|
+
## `*args` for old format support, it will be removed with deprecation
|
38
|
+
# rubocop:disable Metrics/ParameterLists
|
39
|
+
def file(*args, size: '300x300', format: 'png', bg_color: :random, text_color: :random, text: nil)
|
40
|
+
if args.any?
|
41
|
+
warn "Positional arguments for Image##{__method__} are deprecated. Please use keyword arguments."
|
42
|
+
size = args[0]
|
43
|
+
format = args[1] if args.size > 1
|
44
|
+
bg_color = args[2] if args.size > 2
|
45
|
+
text_color = args[3] if args.size > 3
|
46
|
+
text = args[4] if args.size > 4
|
47
|
+
end
|
24
48
|
|
25
|
-
|
26
|
-
uri = URI.parse(url(size, format, bg_color, text_color, text))
|
49
|
+
uri = URI.parse(url(size: size, format: format, bg_color: bg_color, text_color: text_color, text: text))
|
27
50
|
file = Tempfile.new('ffaker_image')
|
28
51
|
file.binmode
|
29
52
|
file << uri.open.read
|
30
53
|
file.close
|
31
54
|
File.new(file.path)
|
32
55
|
end
|
56
|
+
# rubocop:enable Metrics/ParameterLists
|
33
57
|
|
34
58
|
private
|
35
59
|
|
36
60
|
def check_size!(size)
|
37
|
-
return true if size
|
61
|
+
return true if size.match?(/\A\d+x\d+\z/)
|
38
62
|
|
39
63
|
raise ArgumentError, 'Size should be specified in format 300x300'
|
40
64
|
end
|
data/lib/ffaker/lorem_ja.rb
CHANGED
data/lib/ffaker/lorem_ru.rb
CHANGED
data/lib/ffaker/movie.rb
CHANGED
data/lib/ffaker/name_fr.rb
CHANGED
@@ -25,9 +25,10 @@ module FFaker
|
|
25
25
|
|
26
26
|
def name
|
27
27
|
case rand(0..9)
|
28
|
-
when 7
|
29
|
-
|
30
|
-
else
|
28
|
+
when 5, 7
|
29
|
+
"#{first_name} #{prefix} #{last_name}"
|
30
|
+
else
|
31
|
+
"#{first_name} #{last_name}"
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/ffaker/number.rb
CHANGED
@@ -7,15 +7,15 @@ module FFaker
|
|
7
7
|
|
8
8
|
# Mobile prefixes are in the 015x, 016x, 017x ranges
|
9
9
|
def mobile_prefix(leading_zero = true)
|
10
|
-
mobile_prefix =
|
11
|
-
mobile_prefix =
|
10
|
+
mobile_prefix = "1#{rand(5..7)}#{rand(0..9)}"
|
11
|
+
mobile_prefix = "0#{mobile_prefix}" if leading_zero
|
12
12
|
mobile_prefix
|
13
13
|
end
|
14
14
|
|
15
15
|
# Region prefixes are in range 02..09 with length of 3 to 5 digits
|
16
16
|
def region_prefix(leading_zero = true)
|
17
17
|
region_prefix = rand(2..9).to_s + FFaker.numerify('#' * rand(1..3)).to_s
|
18
|
-
region_prefix =
|
18
|
+
region_prefix = "0#{region_prefix}" if leading_zero
|
19
19
|
region_prefix
|
20
20
|
end
|
21
21
|
|
data/lib/ffaker/skill.rb
CHANGED
data/lib/ffaker/ssn.rb
CHANGED
@@ -15,8 +15,10 @@ module FFaker
|
|
15
15
|
second_group = rand(1..99)
|
16
16
|
third_group = rand(1..9999)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
format(
|
19
|
+
'%<first_group>.3d-%<second_group>.2d-%<third_group>.4d',
|
20
|
+
first_group: first_group, second_group: second_group, third_group: third_group
|
21
|
+
)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/ffaker/string.rb
CHANGED
@@ -13,7 +13,7 @@ module FFaker
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def const_missing(const_name)
|
16
|
-
if const_name
|
16
|
+
if const_name.match?(/[a-z]/) # Not a constant, probably a class/module name.
|
17
17
|
super const_name
|
18
18
|
else
|
19
19
|
mod_name = ancestors.first.to_s.split('::').last
|
@@ -40,7 +40,7 @@ module FFaker
|
|
40
40
|
def luhn_check(number)
|
41
41
|
multiplications = []
|
42
42
|
|
43
|
-
number.
|
43
|
+
number.chars.each_with_index do |digit, i|
|
44
44
|
multiplications << i.even? ? digit.to_i * 2 : digit.to_i
|
45
45
|
end
|
46
46
|
|
@@ -16,7 +16,7 @@ module FFaker
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def clear
|
19
|
-
instances.
|
19
|
+
instances.each_value(&:clear)
|
20
20
|
instances.clear
|
21
21
|
end
|
22
22
|
end
|
@@ -32,19 +32,23 @@ module FFaker
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def method_missing(name, *
|
35
|
+
def method_missing(name, *args, **kwargs)
|
36
36
|
@max_retries.times do
|
37
|
-
result = @generator.public_send(name, *
|
37
|
+
result = @generator.public_send(name, *args, **kwargs)
|
38
38
|
|
39
|
-
next if previous_results[[name,
|
39
|
+
next if previous_results[[name, args, kwargs]].include?(result)
|
40
40
|
|
41
|
-
previous_results[[name,
|
41
|
+
previous_results[[name, args, kwargs]] << result
|
42
42
|
return result
|
43
43
|
end
|
44
44
|
|
45
45
|
raise RetryLimitExceeded, "Retry limit exceeded for #{name}"
|
46
46
|
end
|
47
47
|
|
48
|
+
def respond_to_missing?(name, *args)
|
49
|
+
@generator.respond_to?(name, *args) || super
|
50
|
+
end
|
51
|
+
|
48
52
|
def previous_results
|
49
53
|
@previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
|
50
54
|
end
|
data/lib/ffaker/version.rb
CHANGED