ffaker 2.21.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +131 -17
  3. data/Gemfile +15 -0
  4. data/README.md +18 -6
  5. data/REFERENCE.md +1012 -969
  6. data/Rakefile +16 -47
  7. data/bin/console +9 -0
  8. data/ffaker.gemspec +9 -23
  9. data/lib/ffaker/address.rb +4 -4
  10. data/lib/ffaker/address_fr.rb +3 -5
  11. data/lib/ffaker/address_it.rb +1 -4
  12. data/lib/ffaker/address_ua.rb +1 -1
  13. data/lib/ffaker/avatar.rb +11 -3
  14. data/lib/ffaker/bank.rb +1 -1
  15. data/lib/ffaker/bank_us.rb +33 -0
  16. data/lib/ffaker/book.rb +15 -7
  17. data/lib/ffaker/cheesy_lingo.rb +2 -2
  18. data/lib/ffaker/code.rb +1 -1
  19. data/lib/ffaker/company.rb +2 -2
  20. data/lib/ffaker/company_fr.rb +2 -2
  21. data/lib/ffaker/crypto.rb +14 -0
  22. data/lib/ffaker/data/address_de/state +1 -0
  23. data/lib/ffaker/data/jo_jo/first_names +356 -0
  24. data/lib/ffaker/data/jo_jo/full_names +225 -0
  25. data/lib/ffaker/data/jo_jo/last_names +153 -0
  26. data/lib/ffaker/data/jo_jo/stands +149 -0
  27. data/lib/ffaker/date.rb +40 -0
  28. data/lib/ffaker/filesystem.rb +12 -2
  29. data/lib/ffaker/geolocation.rb +2 -2
  30. data/lib/ffaker/identification_br.rb +3 -12
  31. data/lib/ffaker/identification_ec.rb +39 -0
  32. data/lib/ffaker/identification_es_cl.rb +2 -2
  33. data/lib/ffaker/identification_es_co.rb +1 -1
  34. data/lib/ffaker/identification_kr.rb +11 -4
  35. data/lib/ffaker/identification_pl.rb +6 -6
  36. data/lib/ffaker/identification_tw.rb +1 -1
  37. data/lib/ffaker/image.rb +28 -4
  38. data/lib/ffaker/jo_jo.rb +24 -0
  39. data/lib/ffaker/lorem_ja.rb +1 -1
  40. data/lib/ffaker/lorem_ru.rb +1 -1
  41. data/lib/ffaker/movie.rb +1 -1
  42. data/lib/ffaker/name_fr.rb +4 -3
  43. data/lib/ffaker/name_pl.rb +1 -1
  44. data/lib/ffaker/number.rb +6 -2
  45. data/lib/ffaker/phone_number_de.rb +3 -3
  46. data/lib/ffaker/skill.rb +1 -1
  47. data/lib/ffaker/ssn.rb +4 -2
  48. data/lib/ffaker/ssn_se.rb +2 -2
  49. data/lib/ffaker/string.rb +1 -1
  50. data/lib/ffaker/time.rb +3 -3
  51. data/lib/ffaker/utils/module_utils.rb +5 -6
  52. data/lib/ffaker/utils/unique_utils.rb +33 -21
  53. data/lib/ffaker/vehicle.rb +2 -2
  54. data/lib/{version.rb → ffaker/version.rb} +1 -1
  55. data/lib/ffaker.rb +63 -191
  56. data/scripts/reference.rb +8 -10
  57. data/test/helper.rb +3 -5
  58. data/test/test_address_da.rb +3 -3
  59. data/test/test_address_fi.rb +2 -2
  60. data/test/test_address_se.rb +2 -2
  61. data/test/test_avatar.rb +30 -7
  62. data/test/test_bank_us.rb +35 -0
  63. data/test/test_book.rb +29 -0
  64. data/test/test_cheesy_lingo.rb +1 -1
  65. data/test/test_color.rb +3 -3
  66. data/test/test_crypto.rb +15 -0
  67. data/test/test_date.rb +47 -0
  68. data/test/test_filesystem.rb +30 -4
  69. data/test/test_freedom_ipsum.rb +1 -1
  70. data/test/test_gender_it.rb +1 -1
  71. data/test/test_gender_ja.rb +1 -1
  72. data/test/test_gender_jp.rb +1 -1
  73. data/test/test_gender_pl.rb +1 -1
  74. data/test/test_healthcare_ru.rb +1 -1
  75. data/test/test_hipster_ipsum.rb +1 -1
  76. data/test/test_html_ipsum.rb +2 -2
  77. data/test/test_identification.rb +12 -2
  78. data/test/test_identification_ec.rb +33 -0
  79. data/test/test_identification_es_mx.rb +3 -1
  80. data/test/test_identification_it.rb +12 -1
  81. data/test/test_identification_kr.rb +3 -3
  82. data/test/test_image.rb +51 -5
  83. data/test/test_internet.rb +3 -1
  84. data/test/test_internet_se.rb +5 -2
  85. data/test/test_jo_jo.rb +29 -0
  86. data/test/test_lorem_br.rb +2 -2
  87. data/test/test_lorem_cn.rb +3 -3
  88. data/test/test_lorem_fr.rb +3 -3
  89. data/test/test_lorem_ie.rb +2 -2
  90. data/test/test_lorem_kr.rb +3 -3
  91. data/test/test_lorem_pl.rb +2 -2
  92. data/test/test_lorem_ru.rb +3 -3
  93. data/test/test_lorem_ua.rb +3 -3
  94. data/test/test_module_utils.rb +33 -0
  95. data/test/test_name_da.rb +1 -1
  96. data/test/test_name_ph.rb +1 -1
  97. data/test/test_name_ru.rb +2 -2
  98. data/test/test_name_ua.rb +2 -2
  99. data/test/test_number.rb +13 -1
  100. data/test/test_phone_number_nl.rb +1 -1
  101. data/test/test_phone_number_se.rb +1 -1
  102. data/test/test_phone_number_sg.rb +8 -8
  103. data/test/test_unique_utils.rb +29 -5
  104. data/test/test_units.rb +6 -6
  105. data/test/test_units_english.rb +15 -15
  106. data/test/test_units_metric.rb +15 -15
  107. data/test/test_vehicle.rb +22 -0
  108. 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` =~ /^\* main$/
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[gemspec reference] do
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
- exit!
142
- end
143
- unless Dir['VERSION*'].empty?
144
- puts 'A `VERSION` file at root level violates Gem best practices.'
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
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'irb'
6
+
7
+ require_relative '../lib/ffaker'
8
+
9
+ IRB.start
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 = '>= 2.5'
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
- # = MANIFEST =
32
- s.files = %w[
33
- Changelog.md
34
- Gemfile
35
- LICENSE
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
@@ -36,10 +36,10 @@ module FFaker
36
36
 
37
37
  def city
38
38
  case rand(0..3)
39
- when 0 then format('%s %s%s', city_prefix, Name.first_name, city_suffix)
40
- when 1 then format('%s %s', city_prefix, Name.first_name)
41
- when 2 then format('%s%s', Name.first_name, city_suffix)
42
- when 3 then format('%s%s', Name.last_name, city_suffix)
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
 
@@ -14,11 +14,9 @@ module FFaker
14
14
  POSTAL_CODE_FORMATS = ['#####', '97###', '2A###', '2B###'].freeze
15
15
 
16
16
  def street_address
17
- FFaker.numerify(fetch_sample(NUM)) +
18
- fetch_sample(MOD) +
19
- fetch_sample(SEP) +
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
@@ -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
@@ -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(/#/) { rand(1..9).to_s }.gsub(/#/) { rand(0..9).to_s }
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 = nil, size = '300x300', format = 'png', bgset = nil)
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}#{'&bgset=bg' + bgset.to_s if bgset}"
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 =~ /^[0-9]+x[0-9]+$/
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.keys.include?(country_code.upcase)
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 = nil, size = '300x300', format = 'png', bgset = nil)
34
- FFaker::Avatar.image(slug, size, format, bgset)
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
 
@@ -23,11 +23,11 @@ module FFaker
23
23
  end
24
24
 
25
25
  def sentence
26
- [
26
+ "#{[
27
27
  fetch_sample(CHEESY_PHRASES).capitalize,
28
28
  fetch_sample(CHEESY_PHRASES),
29
29
  fetch_sample(CHEESY_PHRASES)
30
- ].join + '.'
30
+ ].join}."
31
31
  end
32
32
 
33
33
  def paragraph(number_of_phrases = 10)
data/lib/ffaker/code.rb CHANGED
@@ -17,7 +17,7 @@ module FFaker
17
17
  .chars
18
18
  .inject(0) { |sum, digit| sum + digit.to_i }
19
19
 
20
- npi_checksum = (10 - (24 + summed_digits) % 10).to_s.chars.last
20
+ npi_checksum = (10 - ((24 + summed_digits) % 10)).to_s[-1]
21
21
 
22
22
  base_npi + npi_checksum
23
23
  end
@@ -5,7 +5,7 @@ module FFaker
5
5
  extend ModuleUtils
6
6
  extend self
7
7
 
8
- SUFFIXES = %w[Inc and\ Sons LLC Group].freeze
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 format('%s, %s and %s', Name.last_name, Name.last_name, Name.last_name)
16
+ when 2 then "#{Name.last_name}, #{Name.last_name} and #{Name.last_name}"
17
17
  end
18
18
  end
19
19
 
@@ -5,13 +5,13 @@ module FFaker
5
5
  extend ModuleUtils
6
6
  extend self
7
7
 
8
- SUFFIXES = %w[SA et\ fils SARL Groupe].freeze
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 format('%s, %s and %s', NameFR.last_name, NameFR.last_name, NameFR.last_name)
14
+ when 2 then "#{NameFR.last_name}, #{NameFR.last_name} and #{NameFR.last_name}"
15
15
  end
16
16
  end
17
17
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+
5
+ module FFaker
6
+ module Crypto
7
+ extend ModuleUtils
8
+ extend self
9
+
10
+ def sha256
11
+ OpenSSL::Digest::SHA256.hexdigest(Lorem.characters)
12
+ end
13
+ end
14
+ end
@@ -11,5 +11,6 @@ Nordrhein-Westfalen
11
11
  Rheinland-Pfalz
12
12
  Saarland
13
13
  Sachsen
14
+ Sachsen-Anhalt
14
15
  Schleswig-Holstein
15
16
  Thueringen