faker 1.9.6 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +189 -6
  3. data/README.md +5 -1
  4. data/lib/faker/books/dune.rb +2 -2
  5. data/lib/faker/books/lovecraft.rb +18 -18
  6. data/lib/faker/creature/animal.rb +1 -1
  7. data/lib/faker/creature/cat.rb +1 -1
  8. data/lib/faker/creature/dog.rb +1 -1
  9. data/lib/faker/creature/horse.rb +1 -1
  10. data/lib/faker/default/address.rb +3 -3
  11. data/lib/faker/default/alphanumeric.rb +4 -4
  12. data/lib/faker/default/avatar.rb +1 -1
  13. data/lib/faker/default/bank.rb +2 -2
  14. data/lib/faker/default/boolean.rb +1 -1
  15. data/lib/faker/default/cannabis.rb +4 -0
  16. data/lib/faker/default/chile_rut.rb +3 -3
  17. data/lib/faker/default/code.rb +5 -5
  18. data/lib/faker/default/commerce.rb +4 -4
  19. data/lib/faker/default/company.rb +2 -2
  20. data/lib/faker/default/crypto_coin.rb +9 -4
  21. data/lib/faker/default/date.rb +9 -9
  22. data/lib/faker/default/demographic.rb +1 -1
  23. data/lib/faker/default/device.rb +2 -2
  24. data/lib/faker/default/driving_licence.rb +2 -2
  25. data/lib/faker/default/educator.rb +0 -3
  26. data/lib/faker/default/file.rb +3 -3
  27. data/lib/faker/default/fillmurray.rb +2 -2
  28. data/lib/faker/default/finance.rb +1 -1
  29. data/lib/faker/default/hipster.rb +16 -16
  30. data/lib/faker/default/id_number.rb +47 -10
  31. data/lib/faker/default/internet.rb +22 -21
  32. data/lib/faker/default/invoice.rb +3 -3
  33. data/lib/faker/default/json.rb +2 -2
  34. data/lib/faker/default/lorem.rb +20 -20
  35. data/lib/faker/default/lorem_flickr.rb +4 -4
  36. data/lib/faker/default/lorem_pixel.rb +1 -1
  37. data/lib/faker/default/markdown.rb +7 -7
  38. data/lib/faker/default/measurement.rb +8 -8
  39. data/lib/faker/default/name.rb +2 -4
  40. data/lib/faker/default/nhs.rb +7 -7
  41. data/lib/faker/default/number.rb +35 -32
  42. data/lib/faker/default/omniauth.rb +11 -11
  43. data/lib/faker/default/phone_number.rb +1 -1
  44. data/lib/faker/default/placeholdit.rb +1 -1
  45. data/lib/faker/default/relationship.rb +1 -1
  46. data/lib/faker/default/source.rb +2 -2
  47. data/lib/faker/default/south_africa.rb +1 -1
  48. data/lib/faker/default/space.rb +2 -2
  49. data/lib/faker/default/string.rb +1 -1
  50. data/lib/faker/default/stripe.rb +4 -4
  51. data/lib/faker/default/time.rb +23 -8
  52. data/lib/faker/default/twitter.rb +30 -30
  53. data/lib/faker/default/types.rb +7 -7
  54. data/lib/faker/default/vehicle.rb +5 -5
  55. data/lib/faker/default/world_cup.rb +2 -2
  56. data/lib/faker/games/dota.rb +1 -1
  57. data/lib/faker/games/elder_scrolls.rb +1 -1
  58. data/lib/faker/games/fallout.rb +1 -1
  59. data/lib/faker/games/half_life.rb +1 -1
  60. data/lib/faker/games/heroes.rb +1 -1
  61. data/lib/faker/games/heroes_of_the_storm.rb +1 -1
  62. data/lib/faker/games/league_of_legends.rb +1 -1
  63. data/lib/faker/games/myst.rb +1 -1
  64. data/lib/faker/games/overwatch.rb +1 -1
  65. data/lib/faker/games/pokemon.rb +1 -1
  66. data/lib/faker/games/sonic_the_hedgehog.rb +1 -1
  67. data/lib/faker/games/super_smash_bros.rb +1 -1
  68. data/lib/faker/games/witcher.rb +1 -1
  69. data/lib/faker/games/world_of_warcraft.rb +1 -1
  70. data/lib/faker/games/zelda.rb +1 -1
  71. data/lib/faker/japanese_media/dragon_ball.rb +1 -1
  72. data/lib/faker/japanese_media/one_piece.rb +1 -1
  73. data/lib/faker/japanese_media/sword_art_online.rb +1 -1
  74. data/lib/faker/movies/back_to_the_future.rb +1 -1
  75. data/lib/faker/movies/ghostbusters.rb +1 -1
  76. data/lib/faker/movies/harry_potter.rb +1 -1
  77. data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +1 -1
  78. data/lib/faker/movies/hobbit.rb +1 -1
  79. data/lib/faker/movies/lebowski.rb +1 -1
  80. data/lib/faker/movies/lord_of_the_rings.rb +1 -1
  81. data/lib/faker/movies/princess_bride.rb +1 -1
  82. data/lib/faker/movies/star_wars.rb +2 -2
  83. data/lib/faker/movies/v_for_vendetta.rb +1 -1
  84. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +1 -1
  85. data/lib/faker/tv_shows/bojack_horseman.rb +1 -1
  86. data/lib/faker/tv_shows/breaking_bad.rb +1 -1
  87. data/lib/faker/tv_shows/buffy.rb +1 -1
  88. data/lib/faker/tv_shows/community.rb +1 -1
  89. data/lib/faker/tv_shows/dr_who.rb +1 -1
  90. data/lib/faker/tv_shows/dumb_and_dumber.rb +1 -1
  91. data/lib/faker/tv_shows/family_guy.rb +1 -1
  92. data/lib/faker/tv_shows/friends.rb +1 -1
  93. data/lib/faker/tv_shows/game_of_thrones.rb +1 -1
  94. data/lib/faker/tv_shows/hey_arnold.rb +1 -1
  95. data/lib/faker/tv_shows/how_i_met_your_mother.rb +1 -1
  96. data/lib/faker/tv_shows/michael_scott.rb +1 -1
  97. data/lib/faker/tv_shows/new_girl.rb +1 -1
  98. data/lib/faker/tv_shows/parks_and_rec.rb +1 -1
  99. data/lib/faker/tv_shows/rick_and_morty.rb +1 -1
  100. data/lib/faker/tv_shows/ru_paul.rb +1 -1
  101. data/lib/faker/tv_shows/seinfeld.rb +1 -1
  102. data/lib/faker/tv_shows/silicon_valley.rb +1 -1
  103. data/lib/faker/tv_shows/simpsons.rb +1 -1
  104. data/lib/faker/tv_shows/south_park.rb +1 -1
  105. data/lib/faker/tv_shows/star_trek.rb +1 -1
  106. data/lib/faker/tv_shows/stargate.rb +1 -1
  107. data/lib/faker/tv_shows/stranger_things.rb +1 -1
  108. data/lib/faker/tv_shows/the_expanse.rb +1 -1
  109. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +1 -1
  110. data/lib/faker/tv_shows/the_it_crowd.rb +1 -1
  111. data/lib/faker/tv_shows/the_thick_of_it.rb +1 -1
  112. data/lib/faker/tv_shows/twin_peaks.rb +1 -1
  113. data/lib/faker/tv_shows/venture_bros.rb +1 -1
  114. data/lib/faker/version.rb +1 -1
  115. data/lib/locales/en-IND.yml +1 -1
  116. data/lib/locales/en.yml +4 -1
  117. data/lib/locales/en/address.yml +1 -4
  118. data/lib/locales/en/animal.yml +2 -2
  119. data/lib/locales/en/cannabis.yml +1 -0
  120. data/lib/locales/en/space.yml +1 -1
  121. data/lib/locales/en/super_smash_bros.yml +4 -0
  122. data/lib/locales/vi.yml +1 -1
  123. metadata +9 -17
  124. data/lib/faker/default/creature.rb +0 -6
  125. data/lib/faker/default/games.rb +0 -6
  126. data/lib/faker/default/japanese_media.rb +0 -6
  127. data/lib/faker/default/movies.rb +0 -6
  128. data/lib/faker/default/tv_shows.rb +0 -6
  129. data/lib/faker/deprecate/unreleased/football.rb +0 -35
  130. data/lib/faker/deprecate/unreleased/movies/grateful_dead.rb +0 -22
@@ -3,23 +3,23 @@
3
3
  module Faker
4
4
  class Internet < Base
5
5
  class << self
6
- def email(name = nil, *separators)
6
+ def email(name: nil, separators: nil)
7
7
  if separators
8
- [username(name, separators), domain_name].join('@')
8
+ [username(specifier: name, separators: separators), domain_name].join('@')
9
9
  else
10
- [username(name), domain_name].join('@')
10
+ [username(specifier: name), domain_name].join('@')
11
11
  end
12
12
  end
13
13
 
14
- def free_email(name = nil)
15
- [username(name), fetch('internet.free_email')].join('@')
14
+ def free_email(name: nil)
15
+ [username(specifier: name), fetch('internet.free_email')].join('@')
16
16
  end
17
17
 
18
- def safe_email(name = nil)
19
- [username(name), 'example.' + sample(%w[org com net])].join('@')
18
+ def safe_email(name: nil)
19
+ [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
20
20
  end
21
21
 
22
- def username(specifier = nil, separators = %w[. _])
22
+ def username(specifier: nil, separators: %w[. _])
23
23
  with_locale(:en) do
24
24
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
25
25
 
@@ -30,7 +30,7 @@ module Faker
30
30
  tries = 0 # Don't try forever in case we get something like 1_000_000.
31
31
  result = nil
32
32
  loop do
33
- result = username(nil, separators)
33
+ result = username(specifier: nil, separators: separators)
34
34
  tries += 1
35
35
  break unless result.length < specifier && tries < 7
36
36
  end
@@ -39,7 +39,7 @@ module Faker
39
39
  tries = 0
40
40
  result = nil
41
41
  loop do
42
- result = username(specifier.min, separators)
42
+ result = username(specifier: specifier.min, separators: separators)
43
43
  tries += 1
44
44
  break unless !specifier.include?(result.length) && tries < 7
45
45
  end
@@ -55,12 +55,13 @@ module Faker
55
55
  end
56
56
  end
57
57
 
58
- def password(min_length = 8, max_length = 16, mix_case = true, special_chars = false)
59
- temp = Lorem.characters(min_length)
58
+ def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
59
+ temp = Lorem.characters(number: min_length)
60
60
  diff_length = max_length - min_length
61
+
61
62
  if diff_length.positive?
62
63
  diff_rand = rand(diff_length + 1)
63
- temp += Lorem.characters(diff_rand)
64
+ temp += Lorem.characters(number: diff_rand)
64
65
  end
65
66
 
66
67
  if mix_case
@@ -69,7 +70,7 @@ module Faker
69
70
  end
70
71
  end
71
72
 
72
- if special_chars
73
+ if special_characters
73
74
  chars = %w[! @ # $ % ^ & *]
74
75
  rand(1..min_length).times do |i|
75
76
  temp[i] = chars[rand(chars.length)]
@@ -79,7 +80,7 @@ module Faker
79
80
  temp
80
81
  end
81
82
 
82
- def domain_name(subdomain = false)
83
+ def domain_name(subdomain: false)
83
84
  with_locale(:en) do
84
85
  domain_elements = [Char.prepare(domain_word), domain_suffix]
85
86
  domain_elements.unshift(Char.prepare(domain_word)) if subdomain
@@ -87,7 +88,7 @@ module Faker
87
88
  end
88
89
  end
89
90
 
90
- def fix_umlauts(string = '')
91
+ def fix_umlauts(string: '')
91
92
  Char.fix_umlauts(string)
92
93
  end
93
94
 
@@ -99,7 +100,7 @@ module Faker
99
100
  fetch('internet.domain_suffix')
100
101
  end
101
102
 
102
- def mac_address(prefix = '')
103
+ def mac_address(prefix: '')
103
104
  prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
104
105
  address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
105
106
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
@@ -173,20 +174,20 @@ module Faker
173
174
  "#{ip_v6_address}/#{rand(1..127)}"
174
175
  end
175
176
 
176
- def url(host = domain_name, path = "/#{username}", scheme = 'http')
177
+ def url(host: domain_name, path: "/#{username}", scheme: 'http')
177
178
  "#{scheme}://#{host}#{path}"
178
179
  end
179
180
 
180
- def slug(words = nil, glue = nil)
181
+ def slug(words: nil, glue: nil)
181
182
  glue ||= sample(%w[- _])
182
- (words || Faker::Lorem.words(2).join(' ')).delete(',.').gsub(' ', glue).downcase
183
+ (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
183
184
  end
184
185
 
185
186
  def device_token
186
187
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
187
188
  end
188
189
 
189
- def user_agent(vendor = nil)
190
+ def user_agent(vendor: nil)
190
191
  agent_hash = translate('faker.internet.user_agent')
191
192
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
192
193
  sample(agents)
@@ -6,13 +6,13 @@ module Faker
6
6
 
7
7
  class << self
8
8
  # Generate random amount between values with 2 decimals
9
- def amount_between(from = 0, to = 0)
9
+ def amount_between(from: 0, to: 0)
10
10
  Faker::Base.rand_in_range(from, to).round(2)
11
11
  end
12
12
 
13
13
  # International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
14
14
  # ref is optional so that we can create unit tests
15
- def creditor_reference(ref = '')
15
+ def creditor_reference(ref: '')
16
16
  ref = reference if ref.empty?
17
17
 
18
18
  'RF' + iban_checksum('RF', ref) + ref
@@ -20,7 +20,7 @@ module Faker
20
20
 
21
21
  # Payment references have some rules in certain countries
22
22
  # ref is optional so that we can create unit tests
23
- def reference(ref = '')
23
+ def reference(ref: '')
24
24
  pattern = fetch('invoice.reference.pattern')
25
25
 
26
26
  ref = Base.regexify(/#{pattern}/) if ref.empty?
@@ -3,7 +3,7 @@ module Faker
3
3
  require 'json'
4
4
 
5
5
  class << self
6
- def shallow_json(width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' })
6
+ def shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
7
7
  options[:key] = 'Faker::' + options[:key]
8
8
  options[:value] = 'Faker::' + options[:value]
9
9
 
@@ -11,7 +11,7 @@ module Faker
11
11
  JSON.generate(hash)
12
12
  end
13
13
 
14
- def add_depth_to_json(json = shallow_json, width = 3, options = { key: 'Name.first_name', value: 'Name.first_name' })
14
+ def add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
15
15
  options[:key] = 'Faker::' + options[:key]
16
16
  options[:value] = 'Faker::' + options[:value]
17
17
 
@@ -8,8 +8,8 @@ module Faker
8
8
  sample(translate('faker.lorem.words'))
9
9
  end
10
10
 
11
- def words(num = 3, supplemental = false)
12
- resolved_num = resolve(num)
11
+ def words(number: 3, supplemental: false)
12
+ resolved_num = resolve(number)
13
13
  word_list = (
14
14
  translate('faker.lorem.words') +
15
15
  (supplemental ? translate('faker.lorem.supplemental') : [])
@@ -22,44 +22,44 @@ module Faker
22
22
  sample(Types::CHARACTERS)
23
23
  end
24
24
 
25
- def characters(char_count = 255)
26
- Alphanumeric.alphanumeric(char_count)
25
+ def characters(number: 255)
26
+ Alphanumeric.alphanumeric(number: number)
27
27
  end
28
28
 
29
29
  def multibyte
30
30
  sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8')
31
31
  end
32
32
 
33
- def sentence(word_count = 4, supplemental = false, random_words_to_add = 0)
34
- words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
33
+ def sentence(word_count: 4, supplemental: false, random_words_to_add: 0)
34
+ words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(' ').capitalize + locale_period
35
35
  end
36
36
 
37
- def sentences(sentence_count = 3, supplemental = false)
38
- 1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) }
37
+ def sentences(number: 3, supplemental: false)
38
+ 1.upto(resolve(number)).collect { sentence(word_count: 3, supplemental: supplemental) }
39
39
  end
40
40
 
41
- def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0)
42
- sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space)
41
+ def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0)
42
+ sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental: supplemental).join(locale_space)
43
43
  end
44
44
 
45
- def paragraphs(paragraph_count = 3, supplemental = false)
46
- 1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) }
45
+ def paragraphs(number: 3, supplemental: false)
46
+ 1.upto(resolve(number)).collect { paragraph(sentence_count: 3, supplemental: supplemental) }
47
47
  end
48
48
 
49
- def paragraph_by_chars(chars = 256, supplemental = false)
50
- paragraph = paragraph(3, supplemental)
49
+ def paragraph_by_chars(number: 256, supplemental: false)
50
+ paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
51
51
 
52
- paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars
52
+ paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < number
53
53
 
54
- paragraph[0...chars - 1] + '.'
54
+ paragraph[0...number - 1] + '.'
55
55
  end
56
56
 
57
- def question(word_count = 4, supplemental = false, random_words_to_add = 0)
58
- words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark
57
+ def question(word_count: 4, supplemental: false, random_words_to_add: 0)
58
+ words(number: word_count + rand(random_words_to_add), supplemental: supplemental).join(' ').capitalize + locale_question_mark
59
59
  end
60
60
 
61
- def questions(question_count = 3, supplemental = false)
62
- 1.upto(resolve(question_count)).collect { question(3, supplemental) }
61
+ def questions(number: 3, supplemental: false)
62
+ 1.upto(resolve(number)).collect { question(word_count: 3, supplemental: supplemental) }
63
63
  end
64
64
 
65
65
  private
@@ -5,23 +5,23 @@ module Faker
5
5
  class << self
6
6
  SUPPORTED_COLORIZATIONS = %w[red green blue].freeze
7
7
 
8
- def image(size = '300x300', search_terms = [], match_all = false)
8
+ def image(size: '300x300', search_terms: [], match_all: false)
9
9
  build_url(size, nil, search_terms, match_all)
10
10
  end
11
11
 
12
- def grayscale_image(size = '300x300', search_terms = ['all'], match_all = false)
12
+ def grayscale_image(size: '300x300', search_terms: ['all'], match_all: false)
13
13
  raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any?
14
14
 
15
15
  build_url(size, 'g', search_terms, match_all)
16
16
  end
17
17
 
18
- def pixelated_image(size = '300x300', search_terms = ['all'], match_all = false)
18
+ def pixelated_image(size: '300x300', search_terms: ['all'], match_all: false)
19
19
  raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any?
20
20
 
21
21
  build_url(size, 'p', search_terms, match_all)
22
22
  end
23
23
 
24
- def colorized_image(size = '300x300', color = 'red', search_terms = ['all'], match_all = false)
24
+ def colorized_image(size: '300x300', color: 'red', search_terms: ['all'], match_all: false)
25
25
  raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any?
26
26
  raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color)
27
27
 
@@ -18,7 +18,7 @@ module Faker
18
18
  transport].freeze
19
19
 
20
20
  # rubocop:disable Metrics/ParameterLists
21
- def image(size = '300x300', is_gray = false, category = nil, number = nil, text = nil, secure: true)
21
+ def image(size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true)
22
22
  raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
23
23
  raise ArgumentError, "Supported categories are #{SUPPORTED_CATEGORIES.join(', ')}" unless category.nil? || SUPPORTED_CATEGORIES.include?(category)
24
24
  raise ArgumentError, 'Category required when number is passed' if !number.nil? && category.nil?
@@ -8,7 +8,7 @@ module Faker
8
8
  end
9
9
 
10
10
  def emphasis
11
- paragraph = Faker::Lorem.paragraph(3)
11
+ paragraph = Faker::Lorem.paragraph(sentence_count: 3)
12
12
  words = paragraph.split(' ')
13
13
  position = rand(0..words.length - 1)
14
14
  formatting = fetch('markdown.emphasis')
@@ -21,7 +21,7 @@ module Faker
21
21
 
22
22
  result = []
23
23
  number.times do |i|
24
- result << "#{i}. #{Faker::Lorem.sentence(1)} \n"
24
+ result << "#{i}. #{Faker::Lorem.sentence(word_count: 1)} \n"
25
25
  end
26
26
  result.join('')
27
27
  end
@@ -31,17 +31,17 @@ module Faker
31
31
 
32
32
  result = []
33
33
  number.times do |_i|
34
- result << "* #{Faker::Lorem.sentence(1)} \n"
34
+ result << "* #{Faker::Lorem.sentence(word_count: 1)} \n"
35
35
  end
36
36
  result.join('')
37
37
  end
38
38
 
39
39
  def inline_code
40
- "`#{Faker::Lorem.sentence(1)}`"
40
+ "`#{Faker::Lorem.sentence(word_count: 1)}`"
41
41
  end
42
42
 
43
43
  def block_code
44
- "```ruby\n#{Lorem.sentence(1)}\n```"
44
+ "```ruby\n#{Lorem.sentence(word_count: 1)}\n```"
45
45
  end
46
46
 
47
47
  def table
@@ -59,11 +59,11 @@ module Faker
59
59
  send(method_list[rand(0..method_list.length - 1)])
60
60
  end
61
61
 
62
- def sandwich(sentences = 3, repeat = 1)
62
+ def sandwich(sentences: 3, repeat: 1)
63
63
  text_block = []
64
64
  text_block << headers
65
65
  repeat.times do
66
- text_block << Faker::Lorem.paragraph(sentences)
66
+ text_block << Faker::Lorem.paragraph(sentence_count: sentences)
67
67
  text_block << random
68
68
  end
69
69
  text_block.join("\n")
@@ -6,35 +6,35 @@ module Faker
6
6
  ALL = 'all'
7
7
  NONE = 'none'
8
8
 
9
- def height(amount = rand(10))
9
+ def height(amount: rand(10))
10
10
  define_measurement_locale(amount, 'height')
11
11
  end
12
12
 
13
- def length(amount = rand(10))
13
+ def length(amount: rand(10))
14
14
  define_measurement_locale(amount, 'length')
15
15
  end
16
16
 
17
- def volume(amount = rand(10))
17
+ def volume(amount: rand(10))
18
18
  define_measurement_locale(amount, 'volume')
19
19
  end
20
20
 
21
- def weight(amount = rand(10))
21
+ def weight(amount: rand(10))
22
22
  define_measurement_locale(amount, 'weight')
23
23
  end
24
24
 
25
- def metric_height(amount = rand(10))
25
+ def metric_height(amount: rand(10))
26
26
  define_measurement_locale(amount, 'metric_height')
27
27
  end
28
28
 
29
- def metric_length(amount = rand(10))
29
+ def metric_length(amount: rand(10))
30
30
  define_measurement_locale(amount, 'metric_length')
31
31
  end
32
32
 
33
- def metric_volume(amount = rand(10))
33
+ def metric_volume(amount: rand(10))
34
34
  define_measurement_locale(amount, 'metric_volume')
35
35
  end
36
36
 
37
- def metric_weight(amount = rand(10))
37
+ def metric_weight(amount: rand(10))
38
38
  define_measurement_locale(amount, 'metric_weight')
39
39
  end
40
40
 
@@ -5,8 +5,6 @@ module Faker
5
5
  flexible :name
6
6
 
7
7
  class << self
8
- extend Gem::Deprecate
9
-
10
8
  def name
11
9
  parse('name.name')
12
10
  end
@@ -48,8 +46,8 @@ module Faker
48
46
  fetch('name.suffix')
49
47
  end
50
48
 
51
- def initials(character_count = 3)
52
- (0...character_count).map { rand(65..90).chr }.join
49
+ def initials(number: 3)
50
+ (0...number).map { rand(65..90).chr }.join
53
51
  end
54
52
  end
55
53
  end
@@ -7,15 +7,15 @@ module Faker
7
7
  base_number = rand(400_000_001...499_999_999)
8
8
  # If the check digit is equivalent to 10, the number is invalid.
9
9
  # See https://en.wikipedia.org/wiki/NHS_number
10
- base_number -= 1 if check_digit(base_number) == 10
11
- "#{base_number}#{check_digit(base_number)}".to_s
12
- .chars
13
- .insert(3, ' ')
14
- .insert(7, ' ')
15
- .join('')
10
+ base_number -= 1 if check_digit(number: base_number) == 10
11
+ "#{base_number}#{check_digit(number: base_number)}".to_s
12
+ .chars
13
+ .insert(3, ' ')
14
+ .insert(7, ' ')
15
+ .join('')
16
16
  end
17
17
 
18
- def check_digit(number = 0)
18
+ def check_digit(number: 0)
19
19
  sum = 0
20
20
  number.to_s.chars.each_with_index do |digit, idx|
21
21
  position = idx + 1
@@ -3,82 +3,88 @@
3
3
  module Faker
4
4
  class Number < Base
5
5
  class << self
6
- extend Gem::Deprecate
6
+ def number(digits: 10)
7
+ return if digits < 1
8
+ return 0 if digits == 1
7
9
 
8
- def number(digits = 10)
9
- num = ''
10
-
11
- if digits > 1
12
- num = non_zero_digit
13
- digits -= 1
14
- end
15
-
16
- num + (1..digits).collect { digit }.join
10
+ # Ensure the first digit is not zero
11
+ ([non_zero_digit] + generate(digits - 1)).join.to_i
17
12
  end
18
13
 
19
- def leading_zero_number(digits = 10)
14
+ def leading_zero_number(digits: 10)
20
15
  '0' + (2..digits).collect { digit }.join
21
16
  end
22
17
 
23
- def decimal_part(digits = 10)
18
+ def decimal_part(digits: 10)
24
19
  num = ''
25
20
  if digits > 1
26
21
  num = non_zero_digit
27
22
  digits -= 1
28
23
  end
29
- leading_zero_number(digits) + num
24
+ leading_zero_number(digits: digits) + num.to_s
30
25
  end
31
26
 
32
- def decimal(l_digits = 5, r_digits = 2)
33
- l_d = number(l_digits)
34
- r_d = decimal_part(r_digits)
35
-
36
- "#{l_d}.#{r_d}"
27
+ def decimal(l_digits: 5, r_digits: 2)
28
+ l_d = number(digits: l_digits)
29
+ r_d = if r_digits == 1
30
+ generate(r_digits)
31
+ else
32
+ # Ensure the last digit is not zero
33
+ # so it does not get truncated on converting to float
34
+ generate(r_digits - 1).join + non_zero_digit.to_s
35
+ end
36
+ "#{l_d}.#{r_d}".to_f
37
37
  end
38
38
 
39
39
  def non_zero_digit
40
- rand(1..9).to_s
40
+ rand(1..9)
41
41
  end
42
42
 
43
43
  def digit
44
- rand(10).to_s
44
+ rand(10)
45
45
  end
46
46
 
47
- def hexadecimal(digits = 6)
47
+ def hexadecimal(digits: 6)
48
48
  hex = ''
49
49
  digits.times { hex += rand(15).to_s(16) }
50
50
  hex
51
51
  end
52
52
 
53
- def normal(mean = 1, standard_deviation = 1)
53
+ def normal(mean: 1, standard_deviation: 1)
54
54
  theta = 2 * Math::PI * rand
55
55
  rho = Math.sqrt(-2 * Math.log(1 - rand))
56
56
  scale = standard_deviation * rho
57
57
  mean + scale * Math.cos(theta)
58
58
  end
59
59
 
60
- def between(from = 1.00, to = 5000.00)
60
+ def between(from: 1.00, to: 5000.00)
61
61
  Faker::Base.rand_in_range(from, to)
62
62
  end
63
63
 
64
- def within(range = 1.00..5000.00)
65
- between(range.min, range.max)
64
+ def within(range: 1.00..5000.00)
65
+ between(from: range.min, to: range.max)
66
66
  end
67
67
 
68
- def positive(from = 1.00, to = 5000.00)
69
- random_number = between(from, to)
68
+ def positive(from: 1.00, to: 5000.00)
69
+ random_number = between(from: from, to: to)
70
70
 
71
71
  greater_than_zero(random_number)
72
72
  end
73
73
 
74
- def negative(from = -5000.00, to = -1.00)
75
- random_number = between(from, to)
74
+ def negative(from: -5000.00, to: -1.00)
75
+ random_number = between(from: from, to: to)
76
76
 
77
77
  less_than_zero(random_number)
78
78
  end
79
79
 
80
80
  private
81
81
 
82
+ def generate(count)
83
+ return [] if count.zero?
84
+
85
+ Array.new(count) { digit }
86
+ end
87
+
82
88
  def greater_than_zero(number)
83
89
  should_be(number, :>)
84
90
  end
@@ -94,9 +100,6 @@ module Faker
94
100
  number * -1
95
101
  end
96
102
  end
97
-
98
- deprecate :decimal_part, nil, 2019, 06
99
- deprecate :leading_zero_number, nil, 2019, 06
100
103
  end
101
104
  end
102
105
  end