faker 2.12.0 → 2.16.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 (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +240 -0
  3. data/History.md +4 -4
  4. data/README.md +18 -1
  5. data/lib/faker.rb +14 -14
  6. data/lib/faker/blockchain/aeternity.rb +4 -4
  7. data/lib/faker/blockchain/tezos.rb +28 -0
  8. data/lib/faker/books/dune.rb +15 -2
  9. data/lib/faker/books/lovecraft.rb +8 -4
  10. data/lib/faker/default/address.rb +34 -4
  11. data/lib/faker/default/app.rb +1 -1
  12. data/lib/faker/default/avatar.rb +1 -1
  13. data/lib/faker/default/bank.rb +4 -6
  14. data/lib/faker/default/barcode.rb +165 -0
  15. data/lib/faker/default/beer.rb +3 -3
  16. data/lib/faker/default/blood.rb +3 -3
  17. data/lib/faker/default/camera.rb +46 -0
  18. data/lib/faker/default/cannabis.rb +10 -0
  19. data/lib/faker/default/chile_rut.rb +47 -3
  20. data/lib/faker/default/chuck_norris.rb +1 -0
  21. data/lib/faker/default/code.rb +98 -17
  22. data/lib/faker/default/commerce.rb +1 -1
  23. data/lib/faker/default/company.rb +57 -11
  24. data/lib/faker/default/computer.rb +4 -4
  25. data/lib/faker/default/date.rb +16 -12
  26. data/lib/faker/default/driving_licence.rb +26 -2
  27. data/lib/faker/default/drone.rb +332 -0
  28. data/lib/faker/default/faker_adjective.rb +35 -0
  29. data/lib/faker/default/file.rb +6 -4
  30. data/lib/faker/default/finance.rb +21 -0
  31. data/lib/faker/default/food.rb +1 -1
  32. data/lib/faker/default/gender.rb +1 -1
  33. data/lib/faker/default/hipster.rb +14 -11
  34. data/lib/faker/default/id_number.rb +88 -2
  35. data/lib/faker/default/internet.rb +266 -12
  36. data/lib/faker/default/internet_http.rb +48 -0
  37. data/lib/faker/default/invoice.rb +1 -1
  38. data/lib/faker/default/json.rb +7 -6
  39. data/lib/faker/default/lorem.rb +160 -5
  40. data/lib/faker/default/lorem_flickr.rb +67 -7
  41. data/lib/faker/default/lorem_pixel.rb +23 -0
  42. data/lib/faker/default/markdown.rb +91 -0
  43. data/lib/faker/default/measurement.rb +3 -2
  44. data/lib/faker/default/military.rb +26 -0
  45. data/lib/faker/default/mountain.rb +33 -0
  46. data/lib/faker/default/name.rb +15 -0
  47. data/lib/faker/default/nhs.rb +19 -0
  48. data/lib/faker/default/number.rb +6 -8
  49. data/lib/faker/default/omniauth.rb +62 -14
  50. data/lib/faker/default/placeholdit.rb +3 -2
  51. data/lib/faker/default/relationship.rb +1 -1
  52. data/lib/faker/default/space.rb +1 -1
  53. data/lib/faker/default/string.rb +3 -2
  54. data/lib/faker/default/stripe.rb +3 -3
  55. data/lib/faker/default/vehicle.rb +1 -1
  56. data/lib/faker/default/world_cup.rb +4 -4
  57. data/lib/faker/fantasy/tolkien.rb +67 -0
  58. data/lib/faker/games/clash_of_clans.rb +48 -0
  59. data/lib/faker/games/control.rb +9 -9
  60. data/lib/faker/games/dnd.rb +91 -16
  61. data/lib/faker/games/elder_scrolls.rb +26 -0
  62. data/lib/faker/games/heroes.rb +13 -0
  63. data/lib/faker/games/heroes_of_the_storm.rb +16 -5
  64. data/lib/faker/games/minecraft.rb +113 -0
  65. data/lib/faker/games/street_fighter.rb +61 -0
  66. data/lib/faker/games/super_mario.rb +48 -0
  67. data/lib/faker/games/touhou.rb +75 -0
  68. data/lib/faker/games/warhammer_fantasy.rb +5 -5
  69. data/lib/faker/games/world_of_warcraft.rb +26 -1
  70. data/lib/faker/japanese_media/conan.rb +48 -0
  71. data/lib/faker/japanese_media/doraemon.rb +48 -0
  72. data/lib/faker/japanese_media/dragon_ball.rb +26 -0
  73. data/lib/faker/japanese_media/naruto.rb +61 -0
  74. data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
  75. data/lib/faker/movies/departed.rb +3 -3
  76. data/lib/faker/movies/hobbit.rb +4 -4
  77. data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
  78. data/lib/faker/movies/lord_of_the_rings.rb +3 -3
  79. data/lib/faker/movies/movie.rb +13 -0
  80. data/lib/faker/movies/room.rb +63 -0
  81. data/lib/faker/movies/star_wars.rb +74 -2
  82. data/lib/faker/music/hiphop.rb +48 -0
  83. data/lib/faker/music/opera.rb +237 -1
  84. data/lib/faker/music/pearl_jam.rb +3 -3
  85. data/lib/faker/music/phish.rb +2 -2
  86. data/lib/faker/music/prince.rb +64 -0
  87. data/lib/faker/music/rock_band.rb +12 -0
  88. data/lib/faker/music/rush.rb +37 -0
  89. data/lib/faker/music/show.rb +3 -3
  90. data/lib/faker/quotes/quote.rb +26 -0
  91. data/lib/faker/quotes/rajnikanth.rb +1 -0
  92. data/lib/faker/quotes/shakespeare.rb +34 -0
  93. data/lib/faker/sports/volleyball.rb +74 -0
  94. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
  95. data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
  96. data/lib/faker/tv_shows/buffy.rb +17 -4
  97. data/lib/faker/tv_shows/dr_who.rb +1 -1
  98. data/lib/faker/tv_shows/final_space.rb +51 -0
  99. data/lib/faker/tv_shows/futurama.rb +65 -0
  100. data/lib/faker/tv_shows/simpsons.rb +14 -0
  101. data/lib/faker/tv_shows/suits.rb +3 -3
  102. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
  103. data/lib/faker/version.rb +1 -1
  104. data/lib/helpers/base58.rb +1 -1
  105. data/lib/helpers/char.rb +20 -26
  106. data/lib/helpers/unique_generator.rb +3 -2
  107. data/lib/locales/de-AT.yml +4 -2
  108. data/lib/locales/de-CH.yml +3 -1
  109. data/lib/locales/de.yml +4 -2
  110. data/lib/locales/en-AU.yml +8 -2
  111. data/lib/locales/en-GB.yml +1 -1
  112. data/lib/locales/en-IND.yml +2 -1
  113. data/lib/locales/en-MS.yml +2 -1
  114. data/lib/locales/en-NEP.yml +4 -1
  115. data/lib/locales/en-NZ.yml +3 -1
  116. data/lib/locales/en-PAK.yml +2 -1
  117. data/lib/locales/en-SG.yml +2 -1
  118. data/lib/locales/en-US.yml +10 -10
  119. data/lib/locales/en-au-ocker.yml +2 -1
  120. data/lib/locales/en.yml +0 -3
  121. data/lib/locales/en/adjective.yml +179 -0
  122. data/lib/locales/en/animal.yml +1 -1
  123. data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
  124. data/lib/locales/en/bank.yml +1 -1
  125. data/lib/locales/en/barcode.yml +24 -0
  126. data/lib/locales/en/big_bang_theory.yml +38 -0
  127. data/lib/locales/en/buffy.yml +1 -1
  128. data/lib/locales/en/camera.yml +611 -0
  129. data/lib/locales/en/clash_of_clan.yml +101 -0
  130. data/lib/locales/en/company.yml +2 -2
  131. data/lib/locales/en/conan.yml +171 -0
  132. data/lib/locales/en/demographic.yml +218 -5
  133. data/lib/locales/en/dnd.yml +430 -33
  134. data/lib/locales/en/doraemon.yml +286 -0
  135. data/lib/locales/en/dota.yml +531 -63
  136. data/lib/locales/en/dragon_ball.yml +243 -1
  137. data/lib/locales/en/driving_license.yml +181 -0
  138. data/lib/locales/en/drone.yml +95 -0
  139. data/lib/locales/en/dune.yml +401 -131
  140. data/lib/locales/en/elder_scrolls.yml +583 -9
  141. data/lib/locales/en/fallout.yml +311 -133
  142. data/lib/locales/en/final_space.yml +37 -0
  143. data/lib/locales/en/finance.yml +53 -0
  144. data/lib/locales/en/football.yml +3 -3
  145. data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
  146. data/lib/locales/en/futurama.yml +344 -0
  147. data/lib/locales/en/half_life.yml +84 -3
  148. data/lib/locales/en/heroes.yml +408 -3
  149. data/lib/locales/en/heroes_of_the_storm.yml +131 -4
  150. data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
  151. data/lib/locales/en/jack_handey.yml +54 -0
  152. data/lib/locales/en/league_of_legends.yml +285 -6
  153. data/lib/locales/en/lebowski.yml +1 -1
  154. data/lib/locales/en/military.yml +179 -5
  155. data/lib/locales/en/minecraft.yml +663 -0
  156. data/lib/locales/en/mountain.yml +158 -0
  157. data/lib/locales/en/movie.yml +192 -1
  158. data/lib/locales/en/music.yml +451 -29
  159. data/lib/locales/en/myst.yml +87 -31
  160. data/lib/locales/en/name.yml +5 -4
  161. data/lib/locales/en/naruto.yml +231 -0
  162. data/lib/locales/en/opera.yml +168 -0
  163. data/lib/locales/en/overwatch.yml +2650 -2622
  164. data/lib/locales/en/pokemon.yml +417 -4
  165. data/lib/locales/en/prince.yml +227 -0
  166. data/lib/locales/en/quote.yml +692 -163
  167. data/lib/locales/en/rock_band.yml +1 -0
  168. data/lib/locales/en/room.yml +68 -0
  169. data/lib/locales/en/rush.yml +32 -0
  170. data/lib/locales/en/simpsons.yml +668 -0
  171. data/lib/locales/en/source.yml +30 -0
  172. data/lib/locales/en/star_trek.yml +1 -1
  173. data/lib/locales/en/star_wars.yml +1 -0
  174. data/lib/locales/en/street_fighter.yml +1524 -0
  175. data/lib/locales/en/studio_ghibli.yml +107 -0
  176. data/lib/locales/en/super_mario.yml +58 -0
  177. data/lib/locales/en/super_smash_bros.yml +18 -4
  178. data/lib/locales/en/tolkien.yml +2453 -0
  179. data/lib/locales/en/touhou.yml +839 -0
  180. data/lib/locales/en/volleyball.yml +501 -0
  181. data/lib/locales/en/witcher.yml +389 -7
  182. data/lib/locales/en/world_of_warcraft.yml +122 -4
  183. data/lib/locales/en/zelda.yml +962 -4
  184. data/lib/locales/es.yml +56 -0
  185. data/lib/locales/fi-FI.yml +1 -1
  186. data/lib/locales/fr-CA.yml +19 -5
  187. data/lib/locales/fr-CH.yml +2 -2
  188. data/lib/locales/fr.yml +12 -6
  189. data/lib/locales/id.yml +3 -1
  190. data/lib/locales/it.yml +2 -1
  191. data/lib/locales/ja.yml +10 -1
  192. data/lib/locales/ko.yml +34 -24
  193. data/lib/locales/nb-NO.yml +4 -2
  194. data/lib/locales/pt-BR.yml +1 -1
  195. data/lib/locales/pt.yml +3 -1
  196. data/lib/locales/ru.yml +3 -1
  197. data/lib/locales/sk.yml +4 -2
  198. data/lib/locales/uk.yml +2 -0
  199. metadata +66 -18
  200. data/lib/locales/en/hobbit.yml +0 -19
  201. data/lib/locales/en/lord_of_the_rings.yml +0 -6
@@ -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
  ##
@@ -37,7 +37,7 @@ module Faker
37
37
  # @example
38
38
  # Faker::Gender.short_binary_type #=> "f"
39
39
  #
40
- # @faker.version next
40
+ # @faker.version 2.13.0
41
41
  def short_binary_type
42
42
  fetch('gender.short_binary_types')
43
43
  end
@@ -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
@@ -19,10 +19,28 @@ module Faker
19
19
  CHILEAN_MODULO = 11
20
20
 
21
21
  class << self
22
+ ##
23
+ # Produces a random valid US Social Security number.
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faker::IDNumber.valid #=> "552-56-3593"
29
+ #
30
+ # @faker.version 1.6.0
22
31
  def valid
23
32
  _translate('valid')
24
33
  end
25
34
 
35
+ ##
36
+ # Produces a random invalid US Social Security number.
37
+ #
38
+ # @return [String]
39
+ #
40
+ # @example
41
+ # Faker::IDNumber.invalid #=> "311-72-0000"
42
+ #
43
+ # @faker.version 1.6.0
26
44
  def invalid
27
45
  _translate('invalid')
28
46
  end
@@ -33,6 +51,15 @@ module Faker
33
51
  INVALID_SSN.any? { |regex| regex =~ ssn } ? ssn_valid : ssn
34
52
  end
35
53
 
54
+ ##
55
+ # Produces a random Spanish citizen identifier (DNI).
56
+ #
57
+ # @return [String]
58
+ #
59
+ # @example
60
+ # Faker::IDNumber.spanish_citizen_number #=> "53290236-H"
61
+ #
62
+ # @faker.version 1.9.0
36
63
  def spanish_citizen_number
37
64
  num = Faker::Number.number(digits: 8)
38
65
  mod = num.to_i % 23
@@ -40,6 +67,15 @@ module Faker
40
67
  "#{num}-#{check}"
41
68
  end
42
69
 
70
+ ##
71
+ # Produces a random Spanish foreign born citizen identifier (NIE).
72
+ #
73
+ # @return [String]
74
+ #
75
+ # @example
76
+ # Faker::IDNumber.spanish_foreign_citizen_number #=> "Z-1600870-Y"
77
+ #
78
+ # @faker.version 1.9.0
43
79
  def spanish_foreign_citizen_number
44
80
  code = 'XYZ'
45
81
  digits = Faker::Number.number(digits: 7)
@@ -50,6 +86,16 @@ module Faker
50
86
  "#{prefix}-#{digits}-#{check}"
51
87
  end
52
88
 
89
+ ##
90
+ # Produces a random valid South African ID Number.
91
+ #
92
+ # @return [String]
93
+ #
94
+ # @example
95
+ # Faker::IDNumber.south_african_id_number #=> "8105128870184"
96
+ # Faker::IDNumber.valid_south_african_id_number #=> "8105128870184"
97
+ #
98
+ # @faker.version 1.9.2
53
99
  def valid_south_african_id_number
54
100
  id_number = [
55
101
  Faker::Date.birthday.strftime('%y%m%d'),
@@ -63,6 +109,15 @@ module Faker
63
109
 
64
110
  alias south_african_id_number valid_south_african_id_number
65
111
 
112
+ ##
113
+ # Produces a random invalid South African ID Number.
114
+ #
115
+ # @return [String]
116
+ #
117
+ # @example
118
+ # Faker::IDNumber.invalid_south_african_id_number #=> "1642972065088"
119
+ #
120
+ # @faker.version 1.9.2
66
121
  def invalid_south_african_id_number
67
122
  invalid_date_of_birth = [
68
123
  Faker::Number.number(digits: 2),
@@ -80,6 +135,17 @@ module Faker
80
135
  [id_number, south_african_id_checksum_digit(id_number)].join
81
136
  end
82
137
 
138
+ ##
139
+ # Produces a random Brazilian Citizen Number (CPF).
140
+ #
141
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
142
+ # @return [String]
143
+ #
144
+ # @example
145
+ # Faker::IDNumber.brazilian_citizen_number #=> "53540542221"
146
+ # Faker::IDNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21"
147
+ #
148
+ # @faker.version 1.9.2
83
149
  def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
84
150
  warn_for_deprecated_arguments do |keywords|
85
151
  keywords << :formatted if legacy_formatted != NOT_GIVEN
@@ -94,6 +160,17 @@ module Faker
94
160
 
95
161
  alias brazilian_cpf brazilian_citizen_number
96
162
 
163
+ ##
164
+ # Produces a random Brazilian ID Number (RG).
165
+ #
166
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
167
+ # @return [String]
168
+ #
169
+ # @example
170
+ # Faker::IDNumber.brazilian_id #=> "493054029"
171
+ # Faker::IDNumber.brazilian_id(formatted: true) #=> "49.305.402-9"
172
+ #
173
+ # @faker.version 2.1.2
97
174
  def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
98
175
  warn_for_deprecated_arguments do |keywords|
99
176
  keywords << :formatted if legacy_formatted != NOT_GIVEN
@@ -107,11 +184,20 @@ module Faker
107
184
 
108
185
  alias brazilian_rg brazilian_id
109
186
 
187
+ ##
188
+ # Produces a random Chilean ID (Rut with 8 digits).
189
+ #
190
+ # @return [String]
191
+ #
192
+ # @example
193
+ # Faker::IDNumber.chilean_id #=> "15620613-K"
194
+ #
195
+ # @faker.version 2.1.2
110
196
  def chilean_id
111
197
  digits = Faker::Number.number(digits: 8)
112
198
  verification_code = chilean_verification_code(digits)
113
199
 
114
- digits.to_s + '-' + verification_code.to_s
200
+ "#{digits}-#{verification_code}"
115
201
  end
116
202
 
117
203
  private
@@ -170,7 +256,7 @@ module Faker
170
256
  end * 10
171
257
  end
172
258
 
173
- def brazilian_document_digit(checksum, id = false)
259
+ def brazilian_document_digit(checksum, id: false)
174
260
  remainder = checksum % 11
175
261
  id ? brazilian_id_digit(remainder) : brazilian_citizen_number_digit(remainder)
176
262
  end
@@ -3,35 +3,91 @@
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
9
23
  keywords << :separators if legacy_separators != NOT_GIVEN
10
24
  end
11
25
 
12
- if separators
13
- [username(specifier: name, separators: separators), domain_name(domain: domain)].join('@')
14
- else
15
- [username(specifier: name), domain_name(domain: domain)].join('@')
16
- end
26
+ local_part = if separators
27
+ username(specifier: name, separators: separators)
28
+ else
29
+ username(specifier: name)
30
+ end
31
+
32
+ sanitized_local_part = sanitize_email_local_part(local_part)
33
+ construct_email(sanitized_local_part, domain_name(domain: domain))
17
34
  end
18
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"
19
46
  def free_email(legacy_name = NOT_GIVEN, name: nil)
20
47
  warn_for_deprecated_arguments do |keywords|
21
48
  keywords << :name if legacy_name != NOT_GIVEN
22
49
  end
23
50
 
24
- [username(specifier: name), fetch('internet.free_email')].join('@')
51
+ construct_email(
52
+ sanitize_email_local_part(username(specifier: name)),
53
+ fetch('internet.free_email')
54
+ )
25
55
  end
26
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"
27
67
  def safe_email(legacy_name = NOT_GIVEN, name: nil)
28
68
  warn_for_deprecated_arguments do |keywords|
29
69
  keywords << :name if legacy_name != NOT_GIVEN
30
70
  end
31
71
 
32
- [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
72
+ construct_email(
73
+ sanitize_email_local_part(username(specifier: name)),
74
+ "example.#{sample(%w[org com net])}"
75
+ )
33
76
  end
34
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"
35
91
  def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
36
92
  warn_for_deprecated_arguments do |keywords|
37
93
  keywords << :specifier if legacy_specifier != NOT_GIVEN
@@ -41,7 +97,8 @@ module Faker
41
97
  with_locale(:en) do
42
98
  return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
43
99
 
44
- if specifier.is_a?(Integer)
100
+ case specifier
101
+ when Integer
45
102
  # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
46
103
  raise ArgumentError, 'Given argument is too large' if specifier > 10**6
47
104
 
@@ -53,7 +110,7 @@ module Faker
53
110
  break unless result.length < specifier && tries < 7
54
111
  end
55
112
  return result * (specifier / result.length + 1) if specifier.positive?
56
- elsif specifier.is_a?(Range)
113
+ when Range
57
114
  tries = 0
58
115
  result = nil
59
116
  loop do
@@ -98,7 +155,6 @@ module Faker
98
155
  #
99
156
  # @faker.version 2.1.3
100
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)
101
- # rubocop:enable Metrics/ParameterLists
102
158
  warn_for_deprecated_arguments do |keywords|
103
159
  keywords << :min_length if legacy_min_length != NOT_GIVEN
104
160
  keywords << :max_length if legacy_max_length != NOT_GIVEN
@@ -106,7 +162,7 @@ module Faker
106
162
  keywords << :special_characters if legacy_special_characters != NOT_GIVEN
107
163
  end
108
164
 
109
- min_alpha = mix_case ? 2 : 0
165
+ min_alpha = mix_case && min_length > 1 ? 2 : 0
110
166
  temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
111
167
  diff_length = max_length - min_length
112
168
 
@@ -134,7 +190,21 @@ module Faker
134
190
 
135
191
  temp
136
192
  end
193
+ # rubocop:enable Metrics/ParameterLists
137
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"
138
208
  def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false, domain: nil)
139
209
  warn_for_deprecated_arguments do |keywords|
140
210
  keywords << :subdomain if legacy_subdomain != NOT_GIVEN
@@ -157,6 +227,19 @@ module Faker
157
227
  end
158
228
  end
159
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"
160
243
  def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
161
244
  warn_for_deprecated_arguments do |keywords|
162
245
  keywords << :string if legacy_string != NOT_GIVEN
@@ -164,15 +247,40 @@ module Faker
164
247
 
165
248
  Char.fix_umlauts(string)
166
249
  end
250
+ # rubocop:enable Style/AsciiComments
167
251
 
252
+ ##
253
+ # Returns the domain word for internet
254
+ #
255
+ # @return [String]
256
+ #
257
+ # @example
258
+ # Faker::Internet.domain_word #=> "senger"
168
259
  def domain_word
169
260
  with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
170
261
  end
171
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"
172
270
  def domain_suffix
173
271
  fetch('internet.domain_suffix')
174
272
  end
175
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"
176
284
  def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
177
285
  warn_for_deprecated_arguments do |keywords|
178
286
  keywords << :prefix if legacy_prefix != NOT_GIVEN
@@ -183,11 +291,25 @@ module Faker
183
291
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
184
292
  end
185
293
 
294
+ ##
295
+ # Returns the IPv4 address
296
+ #
297
+ # @return [String]
298
+ #
299
+ # @example
300
+ # Faker::Internet.ip_v4_address #=> "97.117.128.93"
186
301
  def ip_v4_address
187
302
  [rand_in_range(0, 255), rand_in_range(0, 255),
188
303
  rand_in_range(0, 255), rand_in_range(0, 255)].join('.')
189
304
  end
190
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"
191
313
  def private_ip_v4_address
192
314
  addr = nil
193
315
  loop do
@@ -197,6 +319,13 @@ module Faker
197
319
  addr
198
320
  end
199
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"
200
329
  def public_ip_v4_address
201
330
  addr = nil
202
331
  loop do
@@ -206,6 +335,13 @@ module Faker
206
335
  addr
207
336
  end
208
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])\./]
209
345
  def private_nets_regex
210
346
  [
211
347
  /^10\./, # 10.0.0.0 - 10.255.255.255
@@ -219,10 +355,25 @@ module Faker
219
355
  ]
220
356
  end
221
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
222
366
  def private_net_checker
223
367
  ->(addr) { private_nets_regex.any? { |net| net =~ addr } }
224
368
  end
225
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])\./]
226
377
  def reserved_nets_regex
227
378
  [
228
379
  /^0\./, # 0.0.0.0 - 0.255.255.255
@@ -235,25 +386,69 @@ module Faker
235
386
  ]
236
387
  end
237
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
238
397
  def reserved_net_checker
239
398
  ->(addr) { (private_nets_regex + reserved_nets_regex).any? { |net| net =~ addr } }
240
399
  end
241
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"
242
409
  def ip_v4_cidr
243
410
  "#{ip_v4_address}/#{rand(1..31)}"
244
411
  end
245
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"
246
420
  def ip_v6_address
247
421
  (1..8).map { rand(65_536).to_s(16) }.join(':')
248
422
  end
249
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"
250
431
  def ip_v6_cidr
251
432
  "#{ip_v6_address}/#{rand(1..127)}"
252
433
  end
253
434
 
254
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"
255
451
  def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
256
- # rubocop:enable Metrics/ParameterLists
257
452
  warn_for_deprecated_arguments do |keywords|
258
453
  keywords << :host if legacy_host != NOT_GIVEN
259
454
  keywords << :path if legacy_path != NOT_GIVEN
@@ -262,7 +457,21 @@ module Faker
262
457
 
263
458
  "#{scheme}://#{host}#{path}"
264
459
  end
460
+ # rubocop:enable Metrics/ParameterLists
265
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"
266
475
  def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
267
476
  warn_for_deprecated_arguments do |keywords|
268
477
  keywords << :words if legacy_words != NOT_GIVEN
@@ -273,10 +482,29 @@ module Faker
273
482
  (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
274
483
  end
275
484
 
485
+ ##
486
+ # Generates random token
487
+ #
488
+ # @return[String]
489
+ #
490
+ # @example
491
+ # Faker::Internet.device_token #=> "749f535671cf6b34d8e794d212d00c703b96274e07161b18b082d0d70ef1052f"
276
492
  def device_token
277
493
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
278
494
  end
279
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"
280
508
  def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
281
509
  warn_for_deprecated_arguments do |keywords|
282
510
  keywords << :vendor if legacy_vendor != NOT_GIVEN
@@ -287,6 +515,13 @@ module Faker
287
515
  sample(agents)
288
516
  end
289
517
 
518
+ ##
519
+ # Generated universally unique identifier
520
+ #
521
+ # @return [String]
522
+ #
523
+ # @example
524
+ # Faker::Internet.uuid #=> "8a6cdd40-6d78-4fdb-912b-190e3057197f"
290
525
  def uuid
291
526
  # borrowed from: https://github.com/ruby/ruby/blob/d48783bb0236db505fe1205d1d9822309de53a36/lib/securerandom.rb#L250
292
527
  ary = Faker::Config.random.bytes(16).unpack('NnnnnN')
@@ -325,6 +560,25 @@ module Faker
325
560
  end
326
561
 
327
562
  alias user_name username
563
+
564
+ private
565
+
566
+ def sanitize_email_local_part(local_part)
567
+ char_range = [
568
+ Array('0'..'9'),
569
+ Array('A'..'Z'),
570
+ Array('a'..'z'),
571
+ "!#$%&'*+-/=?^_`{|}~.".split(//)
572
+ ].flatten
573
+
574
+ local_part.split(//).map do |char|
575
+ char_range.include?(char) ? char : '#'
576
+ end.join
577
+ end
578
+
579
+ def construct_email(local_part, domain_name)
580
+ [local_part, domain_name].join('@')
581
+ end
328
582
  end
329
583
  end
330
584
  end