ffaker 2.22.0 → 2.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +120 -17
  3. data/Gemfile +15 -0
  4. data/README.md +3 -2
  5. data/REFERENCE.md +885 -868
  6. data/Rakefile +7 -7
  7. data/ffaker.gemspec +2 -6
  8. data/lib/ffaker/address.rb +4 -4
  9. data/lib/ffaker/address_fr.rb +3 -5
  10. data/lib/ffaker/address_it.rb +1 -4
  11. data/lib/ffaker/avatar.rb +11 -3
  12. data/lib/ffaker/bank.rb +1 -1
  13. data/lib/ffaker/bank_us.rb +33 -0
  14. data/lib/ffaker/book.rb +10 -2
  15. data/lib/ffaker/cheesy_lingo.rb +2 -2
  16. data/lib/ffaker/code.rb +1 -1
  17. data/lib/ffaker/company.rb +1 -1
  18. data/lib/ffaker/company_fr.rb +1 -1
  19. data/lib/ffaker/crypto.rb +14 -0
  20. data/lib/ffaker/date.rb +9 -0
  21. data/lib/ffaker/filesystem.rb +12 -2
  22. data/lib/ffaker/identification_br.rb +2 -11
  23. data/lib/ffaker/identification_ec.rb +1 -1
  24. data/lib/ffaker/identification_es_cl.rb +1 -1
  25. data/lib/ffaker/identification_kr.rb +10 -3
  26. data/lib/ffaker/identification_pl.rb +2 -2
  27. data/lib/ffaker/image.rb +28 -4
  28. data/lib/ffaker/lorem_ja.rb +1 -1
  29. data/lib/ffaker/lorem_ru.rb +1 -1
  30. data/lib/ffaker/movie.rb +1 -1
  31. data/lib/ffaker/name_fr.rb +4 -3
  32. data/lib/ffaker/number.rb +4 -0
  33. data/lib/ffaker/phone_number_de.rb +3 -3
  34. data/lib/ffaker/skill.rb +1 -1
  35. data/lib/ffaker/ssn.rb +4 -2
  36. data/lib/ffaker/string.rb +1 -1
  37. data/lib/ffaker/utils/module_utils.rb +2 -2
  38. data/lib/ffaker/utils/unique_utils.rb +9 -5
  39. data/lib/ffaker/version.rb +1 -1
  40. data/lib/ffaker.rb +60 -191
  41. data/scripts/reference.rb +8 -10
  42. data/test/helper.rb +1 -1
  43. data/test/test_avatar.rb +30 -7
  44. data/test/test_bank_us.rb +35 -0
  45. data/test/test_book.rb +29 -0
  46. data/test/test_crypto.rb +15 -0
  47. data/test/test_date.rb +11 -1
  48. data/test/test_filesystem.rb +28 -2
  49. data/test/test_healthcare_ru.rb +1 -1
  50. data/test/test_identification.rb +12 -2
  51. data/test/test_identification_ec.rb +1 -1
  52. data/test/test_identification_es_mx.rb +3 -1
  53. data/test/test_identification_it.rb +12 -1
  54. data/test/test_identification_kr.rb +3 -3
  55. data/test/test_image.rb +51 -5
  56. data/test/test_internet.rb +3 -1
  57. data/test/test_internet_se.rb +3 -1
  58. data/test/test_lorem_br.rb +1 -1
  59. data/test/test_lorem_ru.rb +1 -1
  60. data/test/test_lorem_ua.rb +1 -1
  61. data/test/test_name_ua.rb +1 -1
  62. data/test/test_number.rb +13 -1
  63. data/test/test_phone_number_nl.rb +1 -1
  64. data/test/test_unique_utils.rb +4 -0
  65. data/test/test_units.rb +6 -6
  66. data/test/test_units_english.rb +15 -15
  67. data/test/test_units_metric.rb +15 -15
  68. 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` =~ /^\* main$/
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
- .reject { |file| file =~ /^\./ }
33
- .reject { |file| file =~ /^(rdoc|pkg)/ }
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
@@ -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
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,8 +30,16 @@ 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)
@@ -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
@@ -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
 
@@ -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 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
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
@@ -17,8 +17,18 @@ module FFaker
17
17
  Lorem.words.join(directory_separator)
18
18
  end
19
19
 
20
- def file_name(dir = directory, name = Lorem.word.downcase,
21
- ext = extension, directory_separator = File::SEPARATOR)
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
- format('%s.%s.%s-%s',
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
- format('%s.%s.%s/%s-%s',
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
 
21
21
  def last_digit(digits)
22
22
  mod = digits_sum(digits) % 10
23
- 10 - mod if mod > 0
23
+ 10 - mod if mod.positive?
24
24
  end
25
25
 
26
26
  def digits_sum(digits)
@@ -20,7 +20,7 @@ module FFaker
20
20
  private
21
21
 
22
22
  def dv(rut)
23
- total = rut.to_s.rjust(8, '0').split('').zip(%w[3 2 7 6 5 4 3 2]).sum do |a, b|
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 IdentificationKr
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}".split('').map(&:to_i)
15
- checksum = (11 - (((2 * a) + (3 * b) + (4 * c) + (5 * d) + (6 * e) + (7 * f) + (8 * g) + (9 * h) + (2 * i) + (3 * j) + (4 * k) + (5 * l)) % 11)) % 10
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}".split('').map(&:to_i)
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.split('').map(&:to_i)
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
- def url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil)
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
- def file(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil)
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 =~ /\A\d+x\d+\z/
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
@@ -30,7 +30,7 @@ module FFaker
30
30
  end
31
31
 
32
32
  def paragraph(sentence_count = 3)
33
- sentences(sentence_count).join('、') + '、' + fetch_sample(SENTENCES_END) + ''
33
+ "#{sentences(sentence_count).join('、')}、#{fetch_sample(SENTENCES_END)}"
34
34
  end
35
35
 
36
36
  def paragraphs(count = 3)
@@ -50,7 +50,7 @@ module FFaker
50
50
  if CAPITAL_CHARS.include?(string[0])
51
51
  string
52
52
  else
53
- CAPITAL_CHARS[CHARS.index(string[0])] + string[1..-1]
53
+ CAPITAL_CHARS[CHARS.index(string[0])] + string[1..]
54
54
  end
55
55
  end
56
56
  end
data/lib/ffaker/movie.rb CHANGED
@@ -37,7 +37,7 @@ module FFaker
37
37
  end
38
38
 
39
39
  def maybe_adj_or_adv
40
- fetch_sample(ADJ_AND_ADV) + ' ' if rand(0..1) == 1
40
+ "#{fetch_sample(ADJ_AND_ADV)} " if rand(0..1) == 1
41
41
  end
42
42
 
43
43
  def simple_title
@@ -25,9 +25,10 @@ module FFaker
25
25
 
26
26
  def name
27
27
  case rand(0..9)
28
- when 7 then "#{first_name} #{prefix} #{last_name}"
29
- when 5 then "#{first_name} #{prefix} #{last_name}"
30
- else "#{first_name} #{last_name}"
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
@@ -15,6 +15,10 @@ module FFaker
15
15
  FFaker.numerify("#{whole_part_pattern}.#{fractional_part_pattern}").to_f
16
16
  end
17
17
 
18
+ def between(from: 1.00, to: 5000.00)
19
+ fetch_sample(from..to)
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def generate_pattern(digits)
@@ -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 = '1' + rand(5..7).to_s + rand(0..9).to_s
11
- mobile_prefix = '0' + mobile_prefix if leading_zero
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 = '0' + region_prefix if leading_zero
18
+ region_prefix = "0#{region_prefix}" if leading_zero
19
19
  region_prefix
20
20
  end
21
21
 
data/lib/ffaker/skill.rb CHANGED
@@ -14,7 +14,7 @@ module FFaker
14
14
  end
15
15
 
16
16
  def specialty
17
- format('%s %s', fetch_sample(SPECIALTY_START), fetch_sample(SPECIALTY_END))
17
+ "#{fetch_sample(SPECIALTY_START)} #{fetch_sample(SPECIALTY_END)}"
18
18
  end
19
19
 
20
20
  def specialties(num = 3)
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
- group_numbers = [first_group, second_group, third_group]
19
- format('%.3d-%.2d-%.4d', *group_numbers)
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
@@ -21,7 +21,7 @@ module FFaker
21
21
  @last_token = nil
22
22
 
23
23
  # Drop surrounding /'s and split into characters
24
- tokens = exp.inspect[1...-1].split('')
24
+ tokens = exp.inspect[1...-1].chars
25
25
  result << process_token(tokens) until tokens.empty?
26
26
 
27
27
  result
@@ -13,7 +13,7 @@ module FFaker
13
13
  end
14
14
 
15
15
  def const_missing(const_name)
16
- if const_name =~ /[a-z]/ # Not a constant, probably a class/module 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.split('').each_with_index do |digit, i|
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.values.each(&:clear)
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, *arguments)
35
+ def method_missing(name, *args, **kwargs)
36
36
  @max_retries.times do
37
- result = @generator.public_send(name, *arguments)
37
+ result = @generator.public_send(name, *args, **kwargs)
38
38
 
39
- next if previous_results[[name, arguments]].include?(result)
39
+ next if previous_results[[name, args, kwargs]].include?(result)
40
40
 
41
- previous_results[[name, arguments]] << result
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FFaker
4
- VERSION = '2.22.0'
4
+ VERSION = '2.23.0'
5
5
  end