faker 2.14.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +218 -19
  3. data/History.md +4 -4
  4. data/README.md +18 -1
  5. data/lib/faker.rb +12 -13
  6. data/lib/faker/blockchain/aeternity.rb +4 -4
  7. data/lib/faker/blockchain/bitcoin.rb +2 -2
  8. data/lib/faker/blockchain/tezos.rb +30 -2
  9. data/lib/faker/books/dune.rb +15 -2
  10. data/lib/faker/books/lovecraft.rb +8 -4
  11. data/lib/faker/creature/bird.rb +203 -0
  12. data/lib/faker/default/address.rb +4 -4
  13. data/lib/faker/default/app.rb +1 -1
  14. data/lib/faker/default/avatar.rb +1 -1
  15. data/lib/faker/default/bank.rb +20 -6
  16. data/lib/faker/default/barcode.rb +44 -33
  17. data/lib/faker/default/beer.rb +3 -3
  18. data/lib/faker/default/camera.rb +46 -0
  19. data/lib/faker/default/cannabis.rb +10 -0
  20. data/lib/faker/default/chile_rut.rb +3 -2
  21. data/lib/faker/default/chuck_norris.rb +1 -0
  22. data/lib/faker/default/code.rb +5 -5
  23. data/lib/faker/default/commerce.rb +1 -1
  24. data/lib/faker/default/company.rb +58 -10
  25. data/lib/faker/default/crypto.rb +17 -4
  26. data/lib/faker/default/driving_licence.rb +4 -3
  27. data/lib/faker/default/drone.rb +25 -25
  28. data/lib/faker/default/educator.rb +13 -0
  29. data/lib/faker/default/faker_adjective.rb +35 -0
  30. data/lib/faker/default/file.rb +6 -4
  31. data/lib/faker/default/finance.rb +21 -0
  32. data/lib/faker/default/food.rb +1 -1
  33. data/lib/faker/default/hipster.rb +14 -11
  34. data/lib/faker/default/id_number.rb +36 -2
  35. data/lib/faker/default/internet.rb +232 -6
  36. data/lib/faker/default/invoice.rb +1 -1
  37. data/lib/faker/default/json.rb +7 -6
  38. data/lib/faker/default/lorem.rb +160 -5
  39. data/lib/faker/default/lorem_flickr.rb +3 -8
  40. data/lib/faker/default/lorem_pixel.rb +2 -1
  41. data/lib/faker/default/markdown.rb +4 -2
  42. data/lib/faker/default/measurement.rb +3 -2
  43. data/lib/faker/default/military.rb +26 -0
  44. data/lib/faker/default/mountain.rb +33 -0
  45. data/lib/faker/default/number.rb +23 -6
  46. data/lib/faker/default/omniauth.rb +5 -10
  47. data/lib/faker/default/placeholdit.rb +3 -2
  48. data/lib/faker/default/relationship.rb +1 -1
  49. data/lib/faker/default/science.rb +26 -0
  50. data/lib/faker/default/space.rb +1 -1
  51. data/lib/faker/default/string.rb +3 -2
  52. data/lib/faker/default/stripe.rb +3 -3
  53. data/lib/faker/default/tea.rb +41 -0
  54. data/lib/faker/default/types.rb +4 -3
  55. data/lib/faker/default/vehicle.rb +1 -1
  56. data/lib/faker/fantasy/tolkien.rb +67 -0
  57. data/lib/faker/games/clash_of_clans.rb +48 -0
  58. data/lib/faker/games/control.rb +1 -1
  59. data/lib/faker/games/dnd.rb +6 -6
  60. data/lib/faker/games/elder_scrolls.rb +26 -0
  61. data/lib/faker/games/heroes.rb +13 -0
  62. data/lib/faker/games/minecraft.rb +65 -0
  63. data/lib/faker/games/street_fighter.rb +4 -4
  64. data/lib/faker/games/super_mario.rb +48 -0
  65. data/lib/faker/games/touhou.rb +75 -0
  66. data/lib/faker/games/witcher.rb +39 -0
  67. data/lib/faker/games/world_of_warcraft.rb +26 -1
  68. data/lib/faker/japanese_media/conan.rb +48 -0
  69. data/lib/faker/japanese_media/doraemon.rb +48 -0
  70. data/lib/faker/japanese_media/dragon_ball.rb +26 -0
  71. data/lib/faker/japanese_media/naruto.rb +61 -0
  72. data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
  73. data/lib/faker/movies/hobbit.rb +4 -4
  74. data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
  75. data/lib/faker/movies/lord_of_the_rings.rb +3 -3
  76. data/lib/faker/movies/room.rb +63 -0
  77. data/lib/faker/movies/star_wars.rb +74 -2
  78. data/lib/faker/music/hiphop.rb +48 -0
  79. data/lib/faker/music/music.rb +12 -0
  80. data/lib/faker/music/opera.rb +237 -1
  81. data/lib/faker/music/rock_band.rb +12 -0
  82. data/lib/faker/quotes/quote.rb +26 -0
  83. data/lib/faker/quotes/rajnikanth.rb +1 -0
  84. data/lib/faker/quotes/shakespeare.rb +34 -0
  85. data/lib/faker/sports/volleyball.rb +74 -0
  86. data/lib/faker/tv_shows/big_bang_theory.rb +1 -1
  87. data/lib/faker/tv_shows/buffy.rb +17 -4
  88. data/lib/faker/tv_shows/final_space.rb +51 -0
  89. data/lib/faker/tv_shows/suits.rb +1 -1
  90. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
  91. data/lib/faker/version.rb +1 -1
  92. data/lib/locales/en-US.yml +1 -1
  93. data/lib/locales/en/adjective.yml +179 -0
  94. data/lib/locales/en/bird.yml +1281 -0
  95. data/lib/locales/en/book.yml +487 -3
  96. data/lib/locales/en/buffy.yml +1 -1
  97. data/lib/locales/en/camera.yml +611 -0
  98. data/lib/locales/en/clash_of_clan.yml +101 -0
  99. data/lib/locales/en/company.yml +2 -2
  100. data/lib/locales/en/conan.yml +171 -0
  101. data/lib/locales/en/demographic.yml +218 -5
  102. data/lib/locales/en/device.yml +112 -4
  103. data/lib/locales/en/doraemon.yml +286 -0
  104. data/lib/locales/en/dota.yml +531 -63
  105. data/lib/locales/en/dragon_ball.yml +243 -1
  106. data/lib/locales/en/driving_license.yml +3 -0
  107. data/lib/locales/en/dune.yml +270 -131
  108. data/lib/locales/en/educator.yml +6 -0
  109. data/lib/locales/en/elder_scrolls.yml +583 -9
  110. data/lib/locales/en/fallout.yml +311 -133
  111. data/lib/locales/en/final_space.yml +37 -0
  112. data/lib/locales/en/finance.yml +53 -0
  113. data/lib/locales/en/football.yml +3 -3
  114. data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
  115. data/lib/locales/en/half_life.yml +84 -3
  116. data/lib/locales/en/heroes.yml +408 -3
  117. data/lib/locales/en/heroes_of_the_storm.yml +131 -4
  118. data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
  119. data/lib/locales/en/jack_handey.yml +54 -0
  120. data/lib/locales/en/league_of_legends.yml +285 -6
  121. data/lib/locales/en/lebowski.yml +1 -1
  122. data/lib/locales/en/lovecraft.yml +76 -6
  123. data/lib/locales/en/military.yml +179 -5
  124. data/lib/locales/en/minecraft.yml +273 -0
  125. data/lib/locales/en/mountain.yml +158 -0
  126. data/lib/locales/en/music.yml +461 -29
  127. data/lib/locales/en/myst.yml +87 -31
  128. data/lib/locales/en/naruto.yml +231 -0
  129. data/lib/locales/en/opera.yml +168 -0
  130. data/lib/locales/en/overwatch.yml +2650 -2622
  131. data/lib/locales/en/pokemon.yml +417 -4
  132. data/lib/locales/en/quote.yml +692 -163
  133. data/lib/locales/en/rock_band.yml +1 -0
  134. data/lib/locales/en/room.yml +68 -0
  135. data/lib/locales/en/science.yml +355 -3
  136. data/lib/locales/en/shakespeare.yml +21 -24
  137. data/lib/locales/en/source.yml +30 -0
  138. data/lib/locales/en/space.yml +1 -1
  139. data/lib/locales/en/star_trek.yml +1 -1
  140. data/lib/locales/en/street_fighter.yml +4 -4
  141. data/lib/locales/en/studio_ghibli.yml +107 -0
  142. data/lib/locales/en/super_mario.yml +58 -0
  143. data/lib/locales/en/super_smash_bros.yml +18 -4
  144. data/lib/locales/en/tea.yml +172 -0
  145. data/lib/locales/en/tolkien.yml +2453 -0
  146. data/lib/locales/en/touhou.yml +839 -0
  147. data/lib/locales/en/volleyball.yml +501 -0
  148. data/lib/locales/en/witcher.yml +426 -7
  149. data/lib/locales/en/world_of_warcraft.yml +122 -4
  150. data/lib/locales/en/zelda.yml +962 -4
  151. data/lib/locales/es-AR.yml +4603 -0
  152. data/lib/locales/es.yml +56 -0
  153. data/lib/locales/fr.yml +0 -118
  154. data/lib/locales/fr/address.yml +21 -0
  155. data/lib/locales/fr/book.yml +7 -0
  156. data/lib/locales/fr/color.yml +4 -0
  157. data/lib/locales/fr/company.yml +17 -0
  158. data/lib/locales/fr/compass.yml +23 -0
  159. data/lib/locales/fr/demographic.yml +4 -0
  160. data/lib/locales/fr/gender.yml +6 -0
  161. data/lib/locales/fr/internet.yml +5 -0
  162. data/lib/locales/fr/lorem.yml +5 -0
  163. data/lib/locales/fr/measurement.yml +7 -0
  164. data/lib/locales/fr/name.yml +21 -0
  165. data/lib/locales/fr/phone_number.yml +7 -0
  166. data/lib/locales/fr/pokemon.yml +9 -0
  167. data/lib/locales/id.yml +1 -0
  168. data/lib/locales/ja/README.md +13 -0
  169. data/lib/locales/ja/address.yml +17 -0
  170. data/lib/locales/ja/ancient.yml +4 -0
  171. data/lib/locales/ja/bank.yml +4 -0
  172. data/lib/locales/ja/book.yml +7 -0
  173. data/lib/locales/ja/coffee.yml +4 -0
  174. data/lib/locales/ja/color.yml +4 -0
  175. data/lib/locales/ja/commerce.yml +11 -0
  176. data/lib/locales/ja/company.yml +8 -0
  177. data/lib/locales/ja/creature.yml +9 -0
  178. data/lib/locales/ja/food.yml +4 -0
  179. data/lib/locales/ja/games.yml +18 -0
  180. data/lib/locales/ja/gender.yml +4 -0
  181. data/lib/locales/ja/lorem.yml +9 -0
  182. data/lib/locales/ja/name.yml +13 -0
  183. data/lib/locales/ja/phone_number.yml +7 -0
  184. data/lib/locales/ja/restaurant.yml +11 -0
  185. data/lib/locales/ja/space.yml +5 -0
  186. data/lib/locales/ja/subscription.yml +8 -0
  187. data/lib/locales/ja/university.yml +9 -0
  188. data/lib/locales/pt-BR.yml +2 -1
  189. data/lib/locales/ru.yml +39 -0
  190. data/lib/locales/uk.yml +2 -0
  191. metadata +92 -19
  192. data/lib/locales/en/hobbit.yml +0 -19
  193. data/lib/locales/en/lord_of_the_rings.yml +0 -6
  194. data/lib/locales/ja.yml +0 -101
@@ -72,6 +72,19 @@ module Faker
72
72
  parse('educator.secondary_school')
73
73
  end
74
74
 
75
+ ##
76
+ # Produces a primary school.
77
+ #
78
+ # @return [String]
79
+ #
80
+ # @example
81
+ # Faker::Educator.primary_school #=> "Brighthurst Elementary School"
82
+ #
83
+ # @faker.version next
84
+ def primary_school
85
+ parse('educator.primary_school')
86
+ end
87
+
75
88
  ##
76
89
  # Produces a campus name.
77
90
  #
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Adjective < Base
5
+ flexible :adjective
6
+
7
+ class << self
8
+ ##
9
+ # Produces a positive adjective.
10
+ #
11
+ # @return [String]
12
+ #
13
+ # @example
14
+ # Faker::Adjective.positive #=> "Kind"
15
+ #
16
+ # @faker.version next
17
+ def positive
18
+ fetch('adjective.positive')
19
+ end
20
+
21
+ ##
22
+ # Produces a negative adjective.
23
+ #
24
+ # @return [String]
25
+ #
26
+ # @example
27
+ # Faker::Adjective.negative #=> "Creepy"
28
+ #
29
+ # @faker.version next
30
+ def negative
31
+ fetch('adjective.negative')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,6 +3,8 @@
3
3
  module Faker
4
4
  class File < Base
5
5
  class << self
6
+ # rubocop:disable Metrics/ParameterLists
7
+
6
8
  ##
7
9
  # Produces a random directory name.
8
10
  #
@@ -18,9 +20,7 @@ module Faker
18
20
  # Faker::File.dir(segment_count: 3, root: nil, directory_separator: '\\') #=> "aut-ullam\\quia_quisquam\\ut-eos"
19
21
  #
20
22
  # @faker.version 1.6.4
21
- # rubocop:disable Metrics/ParameterLists
22
23
  def dir(legacy_segment_count = NOT_GIVEN, legacy_root = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, segment_count: 3, root: nil, directory_separator: ::File::Separator)
23
- # rubocop:enable Metrics/ParameterLists
24
24
  warn_for_deprecated_arguments do |keywords|
25
25
  keywords << :segment_count if legacy_segment_count != NOT_GIVEN
26
26
  keywords << :root if legacy_root != NOT_GIVEN
@@ -34,6 +34,7 @@ module Faker
34
34
  .join(directory_separator)
35
35
  .squeeze(directory_separator)
36
36
  end
37
+ # rubocop:enable Metrics/ParameterLists
37
38
 
38
39
  ##
39
40
  # Produces a random file extension.
@@ -61,6 +62,8 @@ module Faker
61
62
  fetch('file.mime_type')
62
63
  end
63
64
 
65
+ # rubocop:disable Metrics/ParameterLists
66
+
64
67
  ##
65
68
  # Produces a random file name.
66
69
  #
@@ -77,9 +80,7 @@ module Faker
77
80
  # Faker::File.file_name(dir: 'foo/bar', name: 'baz', ext: 'mp3', directory_separator: '\\') #=> "foo/bar\\baz.mp3"
78
81
  #
79
82
  # @faker.version 1.6.4
80
- # rubocop:disable Metrics/ParameterLists
81
83
  def file_name(legacy_dir = NOT_GIVEN, legacy_name = NOT_GIVEN, legacy_ext = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
82
- # rubocop:enable Metrics/ParameterLists
83
84
  warn_for_deprecated_arguments do |keywords|
84
85
  keywords << :dir if legacy_dir != NOT_GIVEN
85
86
  keywords << :name if legacy_name != NOT_GIVEN
@@ -93,6 +94,7 @@ module Faker
93
94
 
94
95
  [dir, name].join(directory_separator) + ".#{ext}"
95
96
  end
97
+ # rubocop:enable Metrics/ParameterLists
96
98
  end
97
99
  end
98
100
  end
@@ -6,6 +6,8 @@ module Faker
6
6
  diners_club jcb switch solo dankort
7
7
  maestro forbrugsforeningen laser].freeze
8
8
 
9
+ MARKET_LIST = %i[nyse nasdaq].freeze
10
+
9
11
  class << self
10
12
  ##
11
13
  # Produces a random credit card number.
@@ -63,6 +65,25 @@ module Faker
63
65
  def vat_number_keys
64
66
  translate('faker.finance.vat_number').keys
65
67
  end
68
+
69
+ ##
70
+ # Returns a randomly-selected stock ticker from a specified market.
71
+ #
72
+ # @param markets [String] The name of the market to choose the ticker from (e.g. NYSE, NASDAQ)
73
+ # @return [String]
74
+ #
75
+ # @example
76
+ # Faker::Finance.ticker #=> 'AMZN'
77
+ # Faker::Finance.vat_number('NASDAQ') #=> 'GOOG'
78
+ #
79
+ # @faker.version next
80
+ def ticker(*markets)
81
+ markets = MARKET_LIST if markets.empty?
82
+ market = sample(markets)
83
+ fetch("finance.ticker.#{market}")
84
+ rescue I18n::MissingTranslationData
85
+ raise ArgumentError, "Could not find market named #{market}"
86
+ end
66
87
  end
67
88
  end
68
89
  end
@@ -93,7 +93,7 @@ module Faker
93
93
  #
94
94
  # @faker.version 1.7.0
95
95
  def measurement
96
- fetch('food.measurement_sizes') + ' ' + fetch('food.measurements')
96
+ "#{fetch('food.measurement_sizes')} #{fetch('food.measurements')}"
97
97
  end
98
98
 
99
99
  ##
@@ -17,6 +17,8 @@ module Faker
17
17
  random_word =~ /\s/ ? word : random_word
18
18
  end
19
19
 
20
+ # rubocop:disable Metrics/ParameterLists
21
+
20
22
  ##
21
23
  # Produces a random hipster word.
22
24
  #
@@ -32,9 +34,7 @@ module Faker
32
34
  # Faker::Hipster.words(number: 4, supplemental: true, spaces_allowed: true) #=> ["qui", "magni", "craft beer", "est"]
33
35
  #
34
36
  # @faker.version 1.6.0
35
- # rubocop:disable Metrics/ParameterLists
36
37
  def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false)
37
- # rubocop:enable Metrics/ParameterLists
38
38
  warn_for_deprecated_arguments do |keywords|
39
39
  keywords << :number if legacy_number != NOT_GIVEN
40
40
  keywords << :supplemental if legacy_supplemental != NOT_GIVEN
@@ -59,7 +59,8 @@ module Faker
59
59
  #
60
60
  # @param word_count [Integer] Specifies the number of words in the sentence
61
61
  # @param supplemental [Boolean] Specifies if the words are supplemental
62
- # @param random_words_to_add [Boolean] Specifies the number of random words to add
62
+ # @param random_words_to_add [Integer] Specifies the number of random words to add
63
+ # @param open_compounds_allowed [Boolean] Specifies if the generated sentence can contain words having additional spaces
63
64
  # @return [String]
64
65
  #
65
66
  # @example
@@ -68,19 +69,20 @@ module Faker
68
69
  # Faker::Hipster.sentence(word_count: 3, supplemental: true) #=> "Beard laboriosam sequi celiac."
69
70
  # Faker::Hipster.sentence(word_count: 3, supplemental: false, random_words_to_add: 4) #=> "Bitters retro mustache aesthetic biodiesel 8-bit."
70
71
  # Faker::Hipster.sentence(word_count: 3, supplemental: true, random_words_to_add: 4) #=> "Occaecati deleniti messenger bag meh crucifix autem."
72
+ # Faker::Hipster.sentence(word_count: 3, supplemental: true, random_words_to_add: 0, open_compounds_allowed: true) #=> "Kale chips nihil eos."
73
+ # Faker::Hipster.sentence(word_count: 3, supplemental: true, random_words_to_add: 0, open_compounds_allowed: false) #=> "Dreamcatcher umami fixie."
71
74
  #
72
75
  # @faker.version 1.6.0
73
- # rubocop:disable Metrics/ParameterLists
74
- def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 6)
75
- # rubocop:enable Metrics/ParameterLists
76
+ def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true)
76
77
  warn_for_deprecated_arguments do |keywords|
77
78
  keywords << :word_count if legacy_word_count != NOT_GIVEN
78
79
  keywords << :supplemental if legacy_supplemental != NOT_GIVEN
79
80
  keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN
80
81
  end
81
82
 
82
- words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.'
83
+ "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: open_compounds_allowed).join(' ').capitalize}."
83
84
  end
85
+ # rubocop:enable Metrics/ParameterLists
84
86
 
85
87
  ##
86
88
  # Produces random hipster sentences.
@@ -108,6 +110,8 @@ module Faker
108
110
  end
109
111
  end
110
112
 
113
+ # rubocop:disable Metrics/ParameterLists
114
+
111
115
  ##
112
116
  # Produces a random hipster paragraph.
113
117
  #
@@ -124,9 +128,7 @@ module Faker
124
128
  # Faker::Hipster.paragraph(sentence_count: 2, supplemental: true, random_sentences_to_add: 4) #=> "Deep v gluten-free unde waistcoat aperiam migas voluptas dolorum. Aut drinking illo sustainable sapiente. Direct trade fanny pack kale chips ennui semiotics."
125
129
  #
126
130
  # @faker.version 1.6.0
127
- # rubocop:disable Metrics/ParameterLists
128
131
  def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
129
- # rubocop:enable Metrics/ParameterLists
130
132
  warn_for_deprecated_arguments do |keywords|
131
133
  keywords << :sentence_count if legacy_sentence_count != NOT_GIVEN
132
134
  keywords << :supplemental if legacy_supplemental != NOT_GIVEN
@@ -135,6 +137,7 @@ module Faker
135
137
 
136
138
  sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
137
139
  end
140
+ # rubocop:enable Metrics/ParameterLists
138
141
 
139
142
  ##
140
143
  # Produces random hipster paragraphs.
@@ -182,9 +185,9 @@ module Faker
182
185
 
183
186
  paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
184
187
 
185
- paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < characters
188
+ paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters
186
189
 
187
- paragraph[0...characters - 1] + '.'
190
+ "#{paragraph[0...characters - 1]}."
188
191
  end
189
192
  end
190
193
  end
@@ -197,11 +197,45 @@ module Faker
197
197
  digits = Faker::Number.number(digits: 8)
198
198
  verification_code = chilean_verification_code(digits)
199
199
 
200
- digits.to_s + '-' + verification_code.to_s
200
+ "#{digits}-#{verification_code}"
201
+ end
202
+
203
+ ##
204
+ # Produces a random Croatian ID number (OIB).
205
+ #
206
+ # @param international [Boolean] Specifies whether to add international prefix.
207
+ # @return [String]
208
+ #
209
+ # @example
210
+ # Faker::IDNumber.croatian_id #=> "88467617508"
211
+ # Faker::IDNumber.croatian_id(international: true) #=> "HR88467617508"
212
+ #
213
+ # @faker.version next
214
+ def croatian_id(international: false)
215
+ prefix = international ? 'HR' : ''
216
+ digits = Faker::Number.number(digits: 10).to_s
217
+ checksum_digit = croatian_id_checksum_digit(digits)
218
+
219
+ "#{prefix}#{digits}#{checksum_digit}"
201
220
  end
202
221
 
203
222
  private
204
223
 
224
+ def croatian_id_checksum_digit(digits)
225
+ control_sum = 10
226
+
227
+ digits.chars.map(&:to_i).each do |digit|
228
+ control_sum += digit
229
+ control_sum %= 10
230
+ control_sum = 10 if control_sum.zero?
231
+ control_sum *= 2
232
+ control_sum %= 11
233
+ end
234
+
235
+ control_sum = 11 - control_sum
236
+ control_sum % 10
237
+ end
238
+
205
239
  def chilean_verification_code(digits)
206
240
  # First digit is multiplied by 3, second by 2, and so on
207
241
  multiplication_rule = [3, 2, 7, 6, 5, 4, 3, 2]
@@ -256,7 +290,7 @@ module Faker
256
290
  end * 10
257
291
  end
258
292
 
259
- def brazilian_document_digit(checksum, id = false)
293
+ def brazilian_document_digit(checksum, id: false)
260
294
  remainder = checksum % 11
261
295
  id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
262
296
  end
@@ -3,6 +3,20 @@
3
3
  module Faker
4
4
  class Internet < Base
5
5
  class << self
6
+ ##
7
+ # Returns the email address
8
+ #
9
+ # @return [String]
10
+ #
11
+ # @param name [String]
12
+ # @param separators [Array]
13
+ # @param domain [String]
14
+ #
15
+ # @example
16
+ # Faker::Internet.email #=> "samsmith@faker.com"
17
+ # Faker::Internet.email(name: 'smith') #=> "smith@faker.com"
18
+ # Faker::Internet.email(name: 'sam smith', separators: ['-']) #=> "sam-smith@faker.com"
19
+ # Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: 'gmail') #=> "sam-smith@gmail.com"
6
20
  def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil, domain: nil)
7
21
  warn_for_deprecated_arguments do |keywords|
8
22
  keywords << :name if legacy_name != NOT_GIVEN
@@ -19,6 +33,16 @@ module Faker
19
33
  construct_email(sanitized_local_part, domain_name(domain: domain))
20
34
  end
21
35
 
36
+ ##
37
+ # Returns the email address with doamin either gmail.com, yahoo.com or hotmail.com
38
+ #
39
+ # @return [String]
40
+ #
41
+ # @param name [String]
42
+ #
43
+ # @example
44
+ # Faker::Internet.free_email #=> "samsmith@gmail.com"
45
+ # Faker::Internet.free_email(name: 'smith') #=> "smith@yahoo.com"
22
46
  def free_email(legacy_name = NOT_GIVEN, name: nil)
23
47
  warn_for_deprecated_arguments do |keywords|
24
48
  keywords << :name if legacy_name != NOT_GIVEN
@@ -30,6 +54,16 @@ module Faker
30
54
  )
31
55
  end
32
56
 
57
+ ##
58
+ # Returns the email address with fixed domain name as 'example'
59
+ #
60
+ # @return [String]
61
+ #
62
+ # @param name [String]
63
+ #
64
+ # @example
65
+ # Faker::Internet.safe_email #=> "samsmith@example.com"
66
+ # Faker::Internet.safe_email(name: 'smith') #=> "smith@example.net"
33
67
  def safe_email(legacy_name = NOT_GIVEN, name: nil)
34
68
  warn_for_deprecated_arguments do |keywords|
35
69
  keywords << :name if legacy_name != NOT_GIVEN
@@ -37,10 +71,23 @@ module Faker
37
71
 
38
72
  construct_email(
39
73
  sanitize_email_local_part(username(specifier: name)),
40
- 'example.' + sample(%w[org com net])
74
+ "example.#{sample(%w[org com net])}"
41
75
  )
42
76
  end
43
77
 
78
+ ##
79
+ # Returns the username
80
+ #
81
+ # @return [String]
82
+ #
83
+ # @param specifier [Integer, Range] When int value passed it returns the username longer than specifier. Max value can be 10^6
84
+ # @param separator [Array]
85
+ #
86
+ # @wxample
87
+ # Faker::Internet.username(specifier: 10) #=> "lulu.goodwin"
88
+ # Faker::Internet.username(specifier: 5..10) #=> "morris"
89
+ # Faker::Internet.username(specifier: 5..10) #=> "berryberry"
90
+ # Faker::Internet.username(specifier: 20, separators: ['-']) #=> "nikki_sawaynnikki_saway"
44
91
  def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
45
92
  warn_for_deprecated_arguments do |keywords|
46
93
  keywords << :specifier if legacy_specifier != NOT_GIVEN
@@ -50,7 +97,8 @@ module Faker
50
97
  with_locale(:en) do
51
98
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
52
99
 
53
- if specifier.is_a?(Integer)
100
+ case specifier
101
+ when Integer
54
102
  # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
55
103
  raise ArgumentError, 'Given argument is too large' if specifier > 10**6
56
104
 
@@ -62,7 +110,7 @@ module Faker
62
110
  break unless result.length < specifier && tries < 7
63
111
  end
64
112
  return result * (specifier / result.length + 1) if specifier.positive?
65
- elsif specifier.is_a?(Range)
113
+ when Range
66
114
  tries = 0
67
115
  result = nil
68
116
  loop do
@@ -107,7 +155,6 @@ module Faker
107
155
  #
108
156
  # @faker.version 2.1.3
109
157
  def password(legacy_min_length = NOT_GIVEN, legacy_max_length = NOT_GIVEN, legacy_mix_case = NOT_GIVEN, legacy_special_characters = NOT_GIVEN, min_length: 8, max_length: 16, mix_case: true, special_characters: false)
110
- # rubocop:enable Metrics/ParameterLists
111
158
  warn_for_deprecated_arguments do |keywords|
112
159
  keywords << :min_length if legacy_min_length != NOT_GIVEN
113
160
  keywords << :max_length if legacy_max_length != NOT_GIVEN
@@ -115,7 +162,7 @@ module Faker
115
162
  keywords << :special_characters if legacy_special_characters != NOT_GIVEN
116
163
  end
117
164
 
118
- min_alpha = mix_case ? 2 : 0
165
+ min_alpha = mix_case && min_length > 1 ? 2 : 0
119
166
  temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
120
167
  diff_length = max_length - min_length
121
168
 
@@ -143,7 +190,21 @@ module Faker
143
190
 
144
191
  temp
145
192
  end
193
+ # rubocop:enable Metrics/ParameterLists
146
194
 
195
+ ##
196
+ # Returns the domain name
197
+ #
198
+ # @return [String]
199
+ #
200
+ # @param subdomain [Bool] If true passed adds a subdomain in response
201
+ # @param domain [String]
202
+ #
203
+ # @example
204
+ # Faker::Internet.domain_name #=> "test.net"
205
+ # Faker::Internet.domain_name(subdomain: true) #=> "test.faker.io"
206
+ # Faker::Internet.domain_name(subdomain: true, domain: 'example') #=> "faker.example.com"
207
+ # Faker::Internet.domain_name(domain: 'faker') #=> "faker.org"
147
208
  def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false, domain: nil)
148
209
  warn_for_deprecated_arguments do |keywords|
149
210
  keywords << :subdomain if legacy_subdomain != NOT_GIVEN
@@ -166,6 +227,19 @@ module Faker
166
227
  end
167
228
  end
168
229
 
230
+ # rubocop:disable Style/AsciiComments
231
+
232
+ ##
233
+ # Fixes ä, ö, ü, ß characters in string passed with ae, oe, ue, ss resp.
234
+ #
235
+ # @return [String]
236
+ #
237
+ # @param string [String]
238
+ #
239
+ # @example
240
+ # Faker::Internet.fix_umlauts #=> ""
241
+ # Faker::Internet.fix_umlauts(string: 'faker') #=> "faker"
242
+ # Faker::Internet.fix_umlauts(string: 'faküer') #=> "fakueer"
169
243
  def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
170
244
  warn_for_deprecated_arguments do |keywords|
171
245
  keywords << :string if legacy_string != NOT_GIVEN
@@ -173,15 +247,40 @@ module Faker
173
247
 
174
248
  Char.fix_umlauts(string)
175
249
  end
250
+ # rubocop:enable Style/AsciiComments
176
251
 
252
+ ##
253
+ # Returns the domain word for internet
254
+ #
255
+ # @return [String]
256
+ #
257
+ # @example
258
+ # Faker::Internet.domain_word #=> "senger"
177
259
  def domain_word
178
260
  with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
179
261
  end
180
262
 
263
+ ## Returns the domain suffix e.g. com, org, co, biz, info etc.
264
+ #
265
+ # @return [String]
266
+ #
267
+ # @wxample
268
+ # Faker::Internet.domain_suffix #=> "com"
269
+ # Faker::Internet.domain_suffix #=> "biz"
181
270
  def domain_suffix
182
271
  fetch('internet.domain_suffix')
183
272
  end
184
273
 
274
+ ##
275
+ # Returns the MAC address
276
+ #
277
+ # @return [String]
278
+ #
279
+ # @example
280
+ # Faker::Internet.mac_address #=> "74:d0:c9:22:95:12"
281
+ # Faker::Internet.mac_address(prefix: 'a') #=> "0a:91:ce:24:89:3b"
282
+ # Faker::Internet.mac_address(prefix: 'aa') #=> "aa:38:a0:3e:e8:41"
283
+ # Faker::Internet.mac_address(prefix: 'aa:44') #=> "aa:44:30:88:6e:95"
185
284
  def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
186
285
  warn_for_deprecated_arguments do |keywords|
187
286
  keywords << :prefix if legacy_prefix != NOT_GIVEN
@@ -192,11 +291,25 @@ module Faker
192
291
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
193
292
  end
194
293
 
294
+ ##
295
+ # Returns the IPv4 address
296
+ #
297
+ # @return [String]
298
+ #
299
+ # @example
300
+ # Faker::Internet.ip_v4_address #=> "97.117.128.93"
195
301
  def ip_v4_address
196
302
  [rand_in_range(0, 255), rand_in_range(0, 255),
197
303
  rand_in_range(0, 255), rand_in_range(0, 255)].join('.')
198
304
  end
199
305
 
306
+ ##
307
+ # Returns the private IPv4 address
308
+ #
309
+ # @return [String]
310
+ #
311
+ # @example
312
+ # Faker::Internet.private_ip_v4_address #=> "127.120.80.42"
200
313
  def private_ip_v4_address
201
314
  addr = nil
202
315
  loop do
@@ -206,6 +319,13 @@ module Faker
206
319
  addr
207
320
  end
208
321
 
322
+ ##
323
+ # Returns the public IPv4 address
324
+ #
325
+ # @return [String]
326
+ #
327
+ # @example
328
+ # Faker::Internet.public_ip_v4_address #=> "127.120.80.42"
209
329
  def public_ip_v4_address
210
330
  addr = nil
211
331
  loop do
@@ -215,6 +335,13 @@ module Faker
215
335
  addr
216
336
  end
217
337
 
338
+ ##
339
+ # Returns the private network regular expressions
340
+ #
341
+ # @return [Array]
342
+ #
343
+ # @example
344
+ # Faker::Internet.private_nets_regex #=> [/^10\./, /^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./, /^127\./, /^169\.254\./, /^172\.(1[6-9]|2\d|3[0-1])\./, /^192\.0\.0\./, /^192\.168\./, /^198\.(1[8-9])\./]
218
345
  def private_nets_regex
219
346
  [
220
347
  /^10\./, # 10.0.0.0 - 10.255.255.255
@@ -228,10 +355,25 @@ module Faker
228
355
  ]
229
356
  end
230
357
 
358
+ ##
359
+ # Returns lambda to check if address passed is private or not
360
+ #
361
+ # @return [Lambda]
362
+ #
363
+ # @example
364
+ # Faker::Internet.private_net_checker.call("127.120.80.42") #=> true
365
+ # Faker::Internet.private_net_checker.call("148.120.80.42") #=> false
231
366
  def private_net_checker
232
367
  ->(addr) { private_nets_regex.any? { |net| net =~ addr } }
233
368
  end
234
369
 
370
+ ##
371
+ # Returns the reserved network regular expressions
372
+ #
373
+ # @return [Array]
374
+ #
375
+ # @example
376
+ # Faker::Internet.reserved_nets_regex #=> [/^0\./, /^192\.0\.2\./, /^192\.88\.99\./, /^198\.51\.100\./, /^203\.0\.113\./, /^(22[4-9]|23\d)\./, /^(24\d|25[0-5])\./]
235
377
  def reserved_nets_regex
236
378
  [
237
379
  /^0\./, # 0.0.0.0 - 0.255.255.255
@@ -244,25 +386,69 @@ module Faker
244
386
  ]
245
387
  end
246
388
 
389
+ ##
390
+ # Returns lambda function to check address passed is reserverd or not
391
+ #
392
+ # @return [Lambda]
393
+ #
394
+ # @example
395
+ # Faker::Internet.reserved_net_checker.call('192.88.99.255') #=> true
396
+ # Faker::Internet.reserved_net_checker.call('192.88.199.255') #=> false
247
397
  def reserved_net_checker
248
398
  ->(addr) { (private_nets_regex + reserved_nets_regex).any? { |net| net =~ addr } }
249
399
  end
250
400
 
401
+ ##
402
+ # Returns Ipv4 address with CIDR, range from 1 to 31
403
+ #
404
+ # @return [String]
405
+ #
406
+ # @example
407
+ # Faker::Internet.ip_v4_cidr #=> "129.162.99.74/16"
408
+ # Faker::Internet.ip_v4_cidr #=> "129.162.99.74/24"
251
409
  def ip_v4_cidr
252
410
  "#{ip_v4_address}/#{rand(1..31)}"
253
411
  end
254
412
 
413
+ ##
414
+ # Returns Ipv6 address
415
+ #
416
+ # @return [String]
417
+ #
418
+ # @example
419
+ # Faker::Internet.ip_v6_address #=> "7754:76d4:c7aa:7646:ea68:1abb:4055:4343"
255
420
  def ip_v6_address
256
421
  (1..8).map { rand(65_536).to_s(16) }.join(':')
257
422
  end
258
423
 
424
+ ##
425
+ # Returns Ipv6 address with CIDR, range between 1 to 127
426
+ #
427
+ # @return [String]
428
+ #
429
+ # @example
430
+ # Faker::Internet.ip_v6_cidr #=> "beca:9b99:4bb6:9712:af2f:516f:8507:96e1/99"
259
431
  def ip_v6_cidr
260
432
  "#{ip_v6_address}/#{rand(1..127)}"
261
433
  end
262
434
 
263
435
  # rubocop:disable Metrics/ParameterLists
436
+
437
+ ##
438
+ # Returns URL
439
+ #
440
+ # @return [String]
441
+ #
442
+ # @param host [String]
443
+ # @param path [String]
444
+ # @param scheme [String]
445
+ #
446
+ # @example
447
+ # Faker::Internet.url #=> "http://sipes-okon.com/hung.macejkovic"
448
+ # Faker::Internet.url(host: 'faker') #=> "http://faker/shad"
449
+ # Faker::Internet.url(host: 'faker', path: '/fake_test_path') #=> "http://faker/fake_test_path"
450
+ # Faker::Internet.url(host: 'faker', path: '/fake_test_path', scheme: 'https') #=> "https://faker/fake_test_path"
264
451
  def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
265
- # rubocop:enable Metrics/ParameterLists
266
452
  warn_for_deprecated_arguments do |keywords|
267
453
  keywords << :host if legacy_host != NOT_GIVEN
268
454
  keywords << :path if legacy_path != NOT_GIVEN
@@ -271,7 +457,21 @@ module Faker
271
457
 
272
458
  "#{scheme}://#{host}#{path}"
273
459
  end
460
+ # rubocop:enable Metrics/ParameterLists
274
461
 
462
+ ##
463
+ # Returns unique string in URL
464
+ #
465
+ # @return [String]
466
+ #
467
+ # @param words [String] Comma or period separated words list
468
+ # @param glue [String] Separator to add between words passed, default used are '-' or '_'
469
+ #
470
+ # @example
471
+ # Faker::Internet.slug #=> "repudiandae-sed"
472
+ # Faker::Internet.slug(words: 'test, faker') #=> "test-faker"
473
+ # Faker::Internet.slug(words: 'test. faker') #=> "test-faker"
474
+ # Faker::Internet.slug(words: 'test. faker', glue: '$') #=> "test$faker"
275
475
  def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
276
476
  warn_for_deprecated_arguments do |keywords|
277
477
  keywords << :words if legacy_words != NOT_GIVEN
@@ -282,10 +482,29 @@ module Faker
282
482
  (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
283
483
  end
284
484
 
485
+ ##
486
+ # Generates random token
487
+ #
488
+ # @return[String]
489
+ #
490
+ # @example
491
+ # Faker::Internet.device_token #=> "749f535671cf6b34d8e794d212d00c703b96274e07161b18b082d0d70ef1052f"
285
492
  def device_token
286
493
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
287
494
  end
288
495
 
496
+ ##
497
+ # Generates the random browser identifier
498
+ #
499
+ # @return [String]
500
+ #
501
+ # @param vendor [String] Name of vendor, supported vendors are aol, chrome, firefox, internet_explorer, netscape, opera, safari
502
+ #
503
+ # @example
504
+ # Faker::Internet.user_agent #=> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
505
+ # Faker::Internet.user_agent(vendor: 'chrome') #=> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
506
+ # Faker::Internet.user_agent(vendor: 'safari') #=> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"
507
+ # Faker::Internet.user_agent(vendor: 'faker') #=> "Mozilla/5.0 (Windows; U; Win 9x 4.90; SG; rv:1.9.2.4) Gecko/20101104 Netscape/9.1.0285"
289
508
  def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
290
509
  warn_for_deprecated_arguments do |keywords|
291
510
  keywords << :vendor if legacy_vendor != NOT_GIVEN
@@ -296,6 +515,13 @@ module Faker
296
515
  sample(agents)
297
516
  end
298
517
 
518
+ ##
519
+ # Generated universally unique identifier
520
+ #
521
+ # @return [String]
522
+ #
523
+ # @example
524
+ # Faker::Internet.uuid #=> "8a6cdd40-6d78-4fdb-912b-190e3057197f"
299
525
  def uuid
300
526
  # borrowed from: https://github.com/ruby/ruby/blob/d48783bb0236db505fe1205d1d9822309de53a36/lib/securerandom.rb#L250
301
527
  ary = Faker::Config.random.bytes(16).unpack('NnnnnN')