ffaker 2.21.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 +131 -17
- data/Gemfile +15 -0
- data/README.md +18 -6
- data/REFERENCE.md +1012 -969
- data/Rakefile +16 -47
- data/bin/console +9 -0
- data/ffaker.gemspec +9 -23
- 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/address_ua.rb +1 -1
- 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 +15 -7
- data/lib/ffaker/cheesy_lingo.rb +2 -2
- data/lib/ffaker/code.rb +1 -1
- data/lib/ffaker/company.rb +2 -2
- data/lib/ffaker/company_fr.rb +2 -2
- data/lib/ffaker/crypto.rb +14 -0
- data/lib/ffaker/data/address_de/state +1 -0
- data/lib/ffaker/data/jo_jo/first_names +356 -0
- data/lib/ffaker/data/jo_jo/full_names +225 -0
- data/lib/ffaker/data/jo_jo/last_names +153 -0
- data/lib/ffaker/data/jo_jo/stands +149 -0
- data/lib/ffaker/date.rb +40 -0
- data/lib/ffaker/filesystem.rb +12 -2
- data/lib/ffaker/geolocation.rb +2 -2
- data/lib/ffaker/identification_br.rb +3 -12
- data/lib/ffaker/identification_ec.rb +39 -0
- data/lib/ffaker/identification_es_cl.rb +2 -2
- data/lib/ffaker/identification_es_co.rb +1 -1
- data/lib/ffaker/identification_kr.rb +11 -4
- data/lib/ffaker/identification_pl.rb +6 -6
- data/lib/ffaker/identification_tw.rb +1 -1
- data/lib/ffaker/image.rb +28 -4
- data/lib/ffaker/jo_jo.rb +24 -0
- 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/name_pl.rb +1 -1
- data/lib/ffaker/number.rb +6 -2
- 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/ssn_se.rb +2 -2
- data/lib/ffaker/string.rb +1 -1
- data/lib/ffaker/time.rb +3 -3
- data/lib/ffaker/utils/module_utils.rb +5 -6
- data/lib/ffaker/utils/unique_utils.rb +33 -21
- data/lib/ffaker/vehicle.rb +2 -2
- data/lib/{version.rb → ffaker/version.rb} +1 -1
- data/lib/ffaker.rb +63 -191
- data/scripts/reference.rb +8 -10
- data/test/helper.rb +3 -5
- data/test/test_address_da.rb +3 -3
- data/test/test_address_fi.rb +2 -2
- data/test/test_address_se.rb +2 -2
- 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_cheesy_lingo.rb +1 -1
- data/test/test_color.rb +3 -3
- data/test/test_crypto.rb +15 -0
- data/test/test_date.rb +47 -0
- data/test/test_filesystem.rb +30 -4
- data/test/test_freedom_ipsum.rb +1 -1
- data/test/test_gender_it.rb +1 -1
- data/test/test_gender_ja.rb +1 -1
- data/test/test_gender_jp.rb +1 -1
- data/test/test_gender_pl.rb +1 -1
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_hipster_ipsum.rb +1 -1
- data/test/test_html_ipsum.rb +2 -2
- data/test/test_identification.rb +12 -2
- data/test/test_identification_ec.rb +33 -0
- 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 +5 -2
- data/test/test_jo_jo.rb +29 -0
- data/test/test_lorem_br.rb +2 -2
- data/test/test_lorem_cn.rb +3 -3
- data/test/test_lorem_fr.rb +3 -3
- data/test/test_lorem_ie.rb +2 -2
- data/test/test_lorem_kr.rb +3 -3
- data/test/test_lorem_pl.rb +2 -2
- data/test/test_lorem_ru.rb +3 -3
- data/test/test_lorem_ua.rb +3 -3
- data/test/test_module_utils.rb +33 -0
- data/test/test_name_da.rb +1 -1
- data/test/test_name_ph.rb +1 -1
- data/test/test_name_ru.rb +2 -2
- data/test/test_name_ua.rb +2 -2
- data/test/test_number.rb +13 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_phone_number_se.rb +1 -1
- data/test/test_phone_number_sg.rb +8 -8
- data/test/test_unique_utils.rb +29 -5
- data/test/test_units.rb +6 -6
- data/test/test_units_english.rb +15 -15
- data/test/test_units_metric.rb +15 -15
- data/test/test_vehicle.rb +22 -0
- metadata +24 -241
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
|
@@ -34,7 +38,7 @@ def name
|
|
34
38
|
end
|
35
39
|
|
36
40
|
def version
|
37
|
-
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
41
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
38
42
|
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
39
43
|
end
|
40
44
|
|
@@ -50,10 +54,6 @@ def gem_file
|
|
50
54
|
"#{name}-#{version}.gem"
|
51
55
|
end
|
52
56
|
|
53
|
-
def replace_header(head, header_name)
|
54
|
-
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{Regexp.last_match(1)}#{send(header_name)}'" }
|
55
|
-
end
|
56
|
-
|
57
57
|
#############################################################################
|
58
58
|
#
|
59
59
|
# Standard tasks
|
@@ -84,14 +84,9 @@ rescue LoadError
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
|
-
#
|
89
|
-
# Packaging tasks
|
90
|
-
#
|
91
|
-
#############################################################################
|
92
|
-
|
87
|
+
desc 'Packaging tasks'
|
93
88
|
task release: :build do
|
94
|
-
unless `git branch
|
89
|
+
unless `git branch`.match?(/^\* main$/)
|
95
90
|
puts 'You must be on the main branch to release!'
|
96
91
|
exit!
|
97
92
|
end
|
@@ -102,51 +97,25 @@ task release: :build do
|
|
102
97
|
sh "gem push pkg/#{name}-#{version}.gem"
|
103
98
|
end
|
104
99
|
|
105
|
-
task build: %i[
|
100
|
+
task build: %i[validate reference] do
|
106
101
|
sh 'mkdir -p pkg'
|
107
|
-
sh "gem build #{gemspec_file}"
|
108
|
-
sh "mv #{gem_file} pkg"
|
109
|
-
end
|
110
|
-
|
111
|
-
task gemspec: :validate do
|
112
|
-
# read spec file and split out manifest section
|
113
|
-
spec = File.read(gemspec_file)
|
114
|
-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
115
|
-
|
116
|
-
# replace name version and date
|
117
|
-
replace_header(head, :name)
|
118
|
-
replace_header(head, :version)
|
119
|
-
replace_header(head, :date)
|
120
|
-
|
121
|
-
# determine file list from git ls-files
|
122
|
-
files = `git ls-files`
|
123
|
-
.split("\n")
|
124
|
-
.sort
|
125
|
-
.reject { |file| file =~ /^\./ }
|
126
|
-
.reject { |file| file =~ /^(rdoc|pkg)/ }
|
127
|
-
.map { |file| " #{file}" }
|
128
|
-
.join("\n")
|
129
|
-
|
130
|
-
# piece file back together and write
|
131
|
-
manifest = " s.files = %w[\n#{files}\n ]\n"
|
132
|
-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
133
|
-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
134
|
-
puts "Updated #{gemspec_file}"
|
102
|
+
sh "gem build #{gemspec_file} --output=pkg/#{gem_file}"
|
135
103
|
end
|
136
104
|
|
105
|
+
desc 'Validate library files'
|
137
106
|
task :validate do
|
138
107
|
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
139
108
|
unless libfiles.empty?
|
140
|
-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
109
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir. Found:"
|
110
|
+
libfiles.each do |libfile|
|
111
|
+
puts "- #{libfile}"
|
112
|
+
end
|
113
|
+
|
145
114
|
exit!
|
146
115
|
end
|
147
116
|
end
|
148
117
|
|
149
118
|
desc 'Creates REFERENCE.md'
|
150
119
|
task :reference do
|
151
|
-
system 'ruby ./scripts/reference.rb > REFERENCE.md'
|
120
|
+
system 'ruby -Ilib ./scripts/reference.rb > REFERENCE.md'
|
152
121
|
end
|
data/bin/console
ADDED
data/ffaker.gemspec
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'lib/version'
|
3
|
+
require_relative 'lib/ffaker/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.specification_version = 2 if s.respond_to? :specification_version=
|
7
6
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
8
|
-
s.rubygems_version = '1.3.5'
|
9
7
|
|
10
8
|
s.name = 'ffaker'
|
11
9
|
s.version = FFaker::VERSION
|
12
|
-
s.required_ruby_version = '>=
|
10
|
+
s.required_ruby_version = '>= 3.0'
|
13
11
|
|
14
12
|
s.license = 'MIT'
|
15
13
|
|
@@ -28,27 +26,15 @@ Gem::Specification.new do |s|
|
|
28
26
|
s.rdoc_options = ['--charset=UTF-8']
|
29
27
|
s.extra_rdoc_files = %w[README.md LICENSE Changelog.md]
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
RANDOM.md
|
37
|
-
README.md
|
38
|
-
REFERENCE.md
|
39
|
-
Rakefile
|
40
|
-
ffaker.gemspec
|
41
|
-
] + Dir['lib/**/*', 'scripts/*']
|
42
|
-
# = MANIFEST =
|
43
|
-
|
44
|
-
s.test_files = Dir['test/**/*']
|
29
|
+
s.files = `git ls-files`
|
30
|
+
.split("\n")
|
31
|
+
.sort
|
32
|
+
.grep_v(/^\./)
|
33
|
+
.grep_v(/^(rdoc|pkg)/)
|
45
34
|
|
46
35
|
s.metadata = {
|
47
36
|
'changelog_uri' => 'https://github.com/ffaker/ffaker/blob/main/Changelog.md',
|
48
|
-
'documentation_uri' => 'https://github.com/ffaker/ffaker/blob/main/REFERENCE.md'
|
37
|
+
'documentation_uri' => 'https://github.com/ffaker/ffaker/blob/main/REFERENCE.md',
|
38
|
+
'rubygems_mfa_required' => 'true'
|
49
39
|
}
|
50
|
-
|
51
|
-
s.add_development_dependency 'rake', '~> 13.0'
|
52
|
-
s.add_development_dependency 'rubocop'
|
53
|
-
s.add_development_dependency 'test-unit'
|
54
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/address_ua.rb
CHANGED
@@ -49,7 +49,7 @@ module FFaker
|
|
49
49
|
if allow_first_zero
|
50
50
|
FFaker.numerify(masks_arr)
|
51
51
|
else
|
52
|
-
fetch_sample(masks_arr).sub(
|
52
|
+
fetch_sample(masks_arr).sub('#') { rand(1..9).to_s }.gsub('#') { rand(0..9).to_s }
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
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,16 +30,24 @@ 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)
|
38
|
-
'https://orly-appstore.herokuapp.com/generate?'\
|
39
|
-
"title=#{CGI.escape(name)}&"\
|
40
|
-
"top_text=#{CGI.escape(top_text)}&"\
|
41
|
-
"author=#{CGI.escape(book_author)}&"\
|
42
|
-
"image_code=#{Random.rand(1..40)}&"\
|
46
|
+
'https://orly-appstore.herokuapp.com/generate?' \
|
47
|
+
"title=#{CGI.escape(name)}&" \
|
48
|
+
"top_text=#{CGI.escape(top_text)}&" \
|
49
|
+
"author=#{CGI.escape(book_author)}&" \
|
50
|
+
"image_code=#{Random.rand(1..40)}&" \
|
43
51
|
"theme=#{Random.rand(1..16)}"
|
44
52
|
end
|
45
53
|
|
data/lib/ffaker/cheesy_lingo.rb
CHANGED
data/lib/ffaker/code.rb
CHANGED
data/lib/ffaker/company.rb
CHANGED
@@ -5,7 +5,7 @@ module FFaker
|
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
8
|
-
SUFFIXES =
|
8
|
+
SUFFIXES = ['Inc', 'and Sons', 'LLC', 'Group'].freeze
|
9
9
|
POSITION_PREFIXES = %w[Executive Assistant General Associate].freeze
|
10
10
|
POSITIONS = %w[President Manager Director Secretary Consultant].freeze
|
11
11
|
|
@@ -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
@@ -5,13 +5,13 @@ module FFaker
|
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
8
|
-
SUFFIXES =
|
8
|
+
SUFFIXES = ['SA', 'et fils', 'SARL', 'Groupe'].freeze
|
9
9
|
|
10
10
|
def name
|
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
|
|