faker 2.15.1 → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +848 -34
  3. data/README.md +225 -103
  4. data/lib/faker/blockchain/aeternity.rb +1 -1
  5. data/lib/faker/blockchain/bitcoin.rb +2 -2
  6. data/lib/faker/blockchain/ethereum.rb +1 -1
  7. data/lib/faker/blockchain/tezos.rb +31 -3
  8. data/lib/faker/books/dune.rb +2 -10
  9. data/lib/faker/books/lovecraft.rb +9 -41
  10. data/lib/faker/books/the_kingkiller_chronicle.rb +61 -0
  11. data/lib/faker/creature/bird.rb +203 -0
  12. data/lib/faker/default/address.rb +7 -27
  13. data/lib/faker/default/alphanumeric.rb +2 -8
  14. data/lib/faker/default/app.rb +1 -10
  15. data/lib/faker/default/avatar.rb +1 -12
  16. data/lib/faker/default/bank.rb +25 -17
  17. data/lib/faker/default/barcode.rb +33 -22
  18. data/lib/faker/default/boolean.rb +1 -4
  19. data/lib/faker/default/cannabis.rb +10 -0
  20. data/lib/faker/default/chile_rut.rb +25 -25
  21. data/lib/faker/default/chuck_norris.rb +1 -0
  22. data/lib/faker/default/code.rb +71 -42
  23. data/lib/faker/default/color.rb +77 -6
  24. data/lib/faker/default/commerce.rb +31 -17
  25. data/lib/faker/default/company.rb +137 -22
  26. data/lib/faker/default/crypto.rb +26 -4
  27. data/lib/faker/default/crypto_coin.rb +3 -15
  28. data/lib/faker/default/date.rb +65 -42
  29. data/lib/faker/default/demographic.rb +1 -5
  30. data/lib/faker/default/driving_licence.rb +20 -18
  31. data/lib/faker/default/drone.rb +1 -1
  32. data/lib/faker/default/educator.rb +13 -0
  33. data/lib/faker/default/emotion.rb +33 -0
  34. data/lib/faker/default/file.rb +5 -22
  35. data/lib/faker/default/finance.rb +30 -7
  36. data/lib/faker/default/food.rb +27 -1
  37. data/lib/faker/default/hipster.rb +8 -48
  38. data/lib/faker/default/hobby.rb +22 -0
  39. data/lib/faker/default/html.rb +230 -0
  40. data/lib/faker/default/id_number.rb +175 -27
  41. data/lib/faker/default/internet.rb +333 -114
  42. data/lib/faker/default/invoice.rb +4 -17
  43. data/lib/faker/default/json.rb +4 -21
  44. data/lib/faker/default/lorem.rb +175 -73
  45. data/lib/faker/default/lorem_flickr.rb +4 -37
  46. data/lib/faker/default/markdown.rb +10 -13
  47. data/lib/faker/default/marketing.rb +1 -1
  48. data/lib/faker/default/measurement.rb +16 -48
  49. data/lib/faker/default/name.rb +1 -5
  50. data/lib/faker/default/nation.rb +0 -3
  51. data/lib/faker/default/{nhs.rb → national_health_service.rb} +9 -8
  52. data/lib/faker/default/number.rb +33 -61
  53. data/lib/faker/default/omniauth.rb +55 -52
  54. data/lib/faker/default/phone_number.rb +36 -21
  55. data/lib/faker/default/placeholdit.rb +10 -20
  56. data/lib/faker/default/relationship.rb +1 -5
  57. data/lib/faker/default/religion.rb +6 -0
  58. data/lib/faker/default/science.rb +108 -0
  59. data/lib/faker/default/source.rb +3 -16
  60. data/lib/faker/default/south_africa.rb +3 -3
  61. data/lib/faker/default/string.rb +1 -7
  62. data/lib/faker/default/stripe.rb +4 -20
  63. data/lib/faker/default/tea.rb +41 -0
  64. data/lib/faker/{music/show.rb → default/theater.rb} +11 -8
  65. data/lib/faker/default/time.rb +4 -34
  66. data/lib/faker/default/twitter.rb +7 -23
  67. data/lib/faker/default/types.rb +12 -34
  68. data/lib/faker/default/vehicle.rb +44 -54
  69. data/lib/faker/default/vulnerability_identifier.rb +23 -0
  70. data/lib/faker/default/world_cup.rb +2 -11
  71. data/lib/faker/games/clash_of_clans.rb +1 -1
  72. data/lib/faker/games/dnd.rb +49 -7
  73. data/lib/faker/games/dota.rb +14 -5
  74. data/lib/faker/games/final_fantasy_xiv.rb +73 -0
  75. data/lib/faker/games/minecraft.rb +1 -1
  76. data/lib/faker/games/myst.rb +1 -1
  77. data/lib/faker/games/tarkov.rb +205 -0
  78. data/lib/faker/games/touhou.rb +75 -0
  79. data/lib/faker/games/witcher.rb +39 -0
  80. data/lib/faker/japanese_media/cowboy_bebop.rb +61 -0
  81. data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +51 -0
  82. data/lib/faker/japanese_media/kamen_rider.rb +102 -0
  83. data/lib/faker/japanese_media/one_piece.rb +1 -1
  84. data/lib/faker/locations/australia.rb +52 -0
  85. data/lib/faker/movies/avatar.rb +49 -0
  86. data/lib/faker/movies/hackers.rb +48 -0
  87. data/lib/faker/movies/star_wars.rb +73 -5
  88. data/lib/faker/movies/{room.rb → the_room.rb} +4 -4
  89. data/lib/faker/movies/tron.rb +161 -0
  90. data/lib/faker/music/hiphop.rb +3 -3
  91. data/lib/faker/music/music.rb +12 -0
  92. data/lib/faker/music/rock_band.rb +12 -0
  93. data/lib/faker/music/smashing_pumpkins.rb +64 -0
  94. data/lib/faker/quotes/quote.rb +13 -0
  95. data/lib/faker/quotes/rajnikanth.rb +1 -0
  96. data/lib/faker/quotes/shakespeare.rb +34 -0
  97. data/lib/faker/religion/bible.rb +50 -0
  98. data/lib/faker/sports/chess.rb +90 -0
  99. data/lib/faker/sports/mountaineering.rb +22 -0
  100. data/lib/faker/sports/sport.rb +116 -0
  101. data/lib/faker/travel/airport.rb +43 -0
  102. data/lib/faker/travel/train_station.rb +54 -0
  103. data/lib/faker/tv_shows/archer.rb +51 -0
  104. data/lib/faker/tv_shows/big_bang_theory.rb +1 -1
  105. data/lib/faker/tv_shows/brooklyn_nine_nine.rb +38 -0
  106. data/lib/faker/tv_shows/michael_scott.rb +0 -3
  107. data/lib/faker/tv_shows/south_park.rb +15 -0
  108. data/lib/faker/tv_shows/spongebob.rb +50 -0
  109. data/lib/faker/tv_shows/suits.rb +1 -1
  110. data/lib/faker/tv_shows/supernatural.rb +48 -0
  111. data/lib/faker/tv_shows/the_office.rb +37 -0
  112. data/lib/faker/version.rb +2 -2
  113. data/lib/faker.rb +26 -67
  114. data/lib/helpers/base58.rb +1 -1
  115. data/lib/helpers/deprecator.rb +53 -0
  116. data/lib/helpers/positional_generator.rb +480 -0
  117. data/lib/helpers/unique_generator.rb +13 -14
  118. data/lib/locales/README.md +18 -2
  119. data/lib/locales/ar.yml +6 -1
  120. data/lib/locales/bg.yml +1 -2
  121. data/lib/locales/da-DK.yml +529 -35
  122. data/lib/locales/de-AT.yml +3487 -27
  123. data/lib/locales/de-CH.yml +4328 -12
  124. data/lib/locales/de.yml +7185 -99
  125. data/lib/locales/ee.yml +0 -1
  126. data/lib/locales/en/address.yml +1826 -562
  127. data/lib/locales/en/airport.yml +381 -0
  128. data/lib/locales/en/animal.yml +1 -1
  129. data/lib/locales/en/archer.yml +75 -0
  130. data/lib/locales/en/australia.yml +108 -0
  131. data/lib/locales/en/avatar.yml +31 -0
  132. data/lib/locales/en/bank.yml +1 -1
  133. data/lib/locales/en/bible.yml +90 -0
  134. data/lib/locales/en/bird.yml +1281 -0
  135. data/lib/locales/en/book.yml +487 -3
  136. data/lib/locales/en/brooklyn_nine_nine.yml +35 -0
  137. data/lib/locales/en/cat.yml +1 -1
  138. data/lib/locales/en/chess.yml +103 -0
  139. data/lib/locales/en/coffee.yml +1 -1
  140. data/lib/locales/en/commerce.yml +17 -0
  141. data/lib/locales/en/community.yml +17 -17
  142. data/lib/locales/en/company.yml +1 -0
  143. data/lib/locales/en/computer.yml +23 -4
  144. data/lib/locales/en/cowboy_bebop.yml +163 -0
  145. data/lib/locales/en/device.yml +112 -4
  146. data/lib/locales/en/dnd.yml +186 -1
  147. data/lib/locales/en/dog.yml +262 -7
  148. data/lib/locales/en/dota.yml +173 -0
  149. data/lib/locales/en/dune.yml +266 -397
  150. data/lib/locales/en/educator.yml +6 -0
  151. data/lib/locales/en/emotion.yml +480 -0
  152. data/lib/locales/en/file.yml +9 -1
  153. data/lib/locales/en/final_fantasy_xiv.yml +754 -0
  154. data/lib/locales/en/finance.yml +27 -4
  155. data/lib/locales/en/food.yml +1067 -10
  156. data/lib/locales/en/football.yml +3 -3
  157. data/lib/locales/en/fullmetal_alchemist_brotherhood.yml +78 -0
  158. data/lib/locales/en/game.yml +11 -0
  159. data/lib/locales/en/hackers.yml +53 -0
  160. data/lib/locales/en/harry_potter.yml +1 -1
  161. data/lib/locales/en/heroes.yml +2 -2
  162. data/lib/locales/en/hobby.yml +171 -0
  163. data/lib/locales/en/horse.yml +2 -2
  164. data/lib/locales/en/id_number.yml +1 -1
  165. data/lib/locales/en/internet.yml +136 -3
  166. data/lib/locales/en/kamen_rider.yml +452 -0
  167. data/lib/locales/en/kpop.yml +7 -7
  168. data/lib/locales/en/lebowski.yml +1 -1
  169. data/lib/locales/en/lovecraft.yml +76 -6
  170. data/lib/locales/en/minecraft.yml +4 -4
  171. data/lib/locales/en/mitch_hedberg.yml +46 -0
  172. data/lib/locales/en/mountain.yml +14 -1
  173. data/lib/locales/en/mountaineering.yml +14 -0
  174. data/lib/locales/en/movie.yml +2 -1
  175. data/lib/locales/en/music.yml +152 -142
  176. data/lib/locales/en/naruto.yml +2 -3
  177. data/lib/locales/en/one_piece.yml +1 -1
  178. data/lib/locales/en/opera.yml +2 -2
  179. data/lib/locales/en/overwatch.yml +5 -7
  180. data/lib/locales/en/phone_number.yml +78 -3
  181. data/lib/locales/en/rock_band.yml +1 -0
  182. data/lib/locales/en/science.yml +481 -3
  183. data/lib/locales/en/shakespeare.yml +21 -24
  184. data/lib/locales/en/smashing_pumpkins.yml +382 -0
  185. data/lib/locales/en/source.yml +5 -0
  186. data/lib/locales/en/south_park.yml +360 -2
  187. data/lib/locales/en/space.yml +1 -1
  188. data/lib/locales/en/spongebob.yml +489 -0
  189. data/lib/locales/en/sport.yml +130 -0
  190. data/lib/locales/en/star_wars.yml +1 -1
  191. data/lib/locales/en/stranger_thing.yml +1 -1
  192. data/lib/locales/en/super_smash_bros.yml +7 -2
  193. data/lib/locales/en/supernatural.yml +141 -0
  194. data/lib/locales/en/tarkov.yml +593 -0
  195. data/lib/locales/en/tea.yml +172 -0
  196. data/lib/locales/en/the_kingkiller_chronicle.yml +56 -0
  197. data/lib/locales/en/the_office.yml +86 -0
  198. data/lib/locales/en/{room.yml → the_room.yml} +1 -1
  199. data/lib/locales/en/{show.yml → theater.yml} +1 -1
  200. data/lib/locales/en/touhou.yml +839 -0
  201. data/lib/locales/en/train_station.yml +280 -0
  202. data/lib/locales/en/tron.yml +227 -0
  203. data/lib/locales/en/vehicle.yml +2809 -75
  204. data/lib/locales/en/witcher.yml +37 -0
  205. data/lib/locales/en-AU.yml +718 -47
  206. data/lib/locales/en-CA.yml +373 -18
  207. data/lib/locales/en-GB.yml +116 -8
  208. data/lib/locales/en-IND.yml +1259 -17
  209. data/lib/locales/en-KE.yml +212 -0
  210. data/lib/locales/en-MS.yml +364 -17
  211. data/lib/locales/en-NEP.yml +212 -38
  212. data/lib/locales/en-NG.yml +1 -0
  213. data/lib/locales/en-NZ.yml +1153 -123
  214. data/lib/locales/en-PAK.yml +369 -10
  215. data/lib/locales/en-SG.yml +581 -16
  216. data/lib/locales/en-UG.yml +1 -0
  217. data/lib/locales/en-US.yml +6914 -74
  218. data/lib/locales/en-ZA.yml +1 -1
  219. data/lib/locales/en-au-ocker.yml +266 -22
  220. data/lib/locales/es-AR.yml +4570 -0
  221. data/lib/locales/es-MX.yml +1 -2
  222. data/lib/locales/es.yml +2 -3
  223. data/lib/locales/fi-FI.yml +3 -1
  224. data/lib/locales/fr/address.yml +20 -0
  225. data/lib/locales/fr/adjective.yml +266 -0
  226. data/lib/locales/fr/ancient.yml +141 -0
  227. data/lib/locales/fr/animal.yml +5 -0
  228. data/lib/locales/fr/appliance.yml +4 -0
  229. data/lib/locales/fr/book.yml +7 -0
  230. data/lib/locales/fr/color.yml +4 -0
  231. data/lib/locales/fr/company.yml +17 -0
  232. data/lib/locales/fr/compass.yml +23 -0
  233. data/lib/locales/fr/demographic.yml +4 -0
  234. data/lib/locales/fr/gender.yml +6 -0
  235. data/lib/locales/fr/internet.yml +4 -0
  236. data/lib/locales/fr/lorem.yml +5 -0
  237. data/lib/locales/fr/measurement.yml +7 -0
  238. data/lib/locales/fr/name.yml +22 -0
  239. data/lib/locales/fr/phone_number.yml +7 -0
  240. data/lib/locales/fr/pokemon.yml +7 -0
  241. data/lib/locales/fr-CA.yml +2733 -44
  242. data/lib/locales/fr-CH.yml +1 -2
  243. data/lib/locales/fr.yml +2 -118
  244. data/lib/locales/hy.yml +3624 -119
  245. data/lib/locales/id.yml +839 -12
  246. data/lib/locales/it.yml +1304 -32
  247. data/lib/locales/ja/README.md +13 -0
  248. data/lib/locales/ja/address.yml +120539 -0
  249. data/lib/locales/ja/adjective.yml +148 -0
  250. data/lib/locales/ja/ancient.yml +4 -0
  251. data/lib/locales/ja/animal.yml +5 -0
  252. data/lib/locales/ja/bank.yml +4 -0
  253. data/lib/locales/ja/book.yml +7 -0
  254. data/lib/locales/ja/cat.yml +5 -0
  255. data/lib/locales/ja/coffee.yml +4 -0
  256. data/lib/locales/ja/color.yml +4 -0
  257. data/lib/locales/ja/commerce.yml +11 -0
  258. data/lib/locales/ja/company.yml +8 -0
  259. data/lib/locales/ja/dog.yml +6 -0
  260. data/lib/locales/ja/emotion.yml +51 -0
  261. data/lib/locales/ja/food.yml +4 -0
  262. data/lib/locales/ja/football.yml +115 -0
  263. data/lib/locales/ja/gender.yml +4 -0
  264. data/lib/locales/ja/lorem.yml +9 -0
  265. data/lib/locales/ja/name.yml +13 -0
  266. data/lib/locales/ja/naruto.yml +230 -0
  267. data/lib/locales/ja/overwatch.yml +5 -0
  268. data/lib/locales/ja/phone_number.yml +7 -0
  269. data/lib/locales/ja/pokemon.yml +7 -0
  270. data/lib/locales/ja/relationship.yml +10 -0
  271. data/lib/locales/ja/restaurant.yml +11 -0
  272. data/lib/locales/ja/space.yml +5 -0
  273. data/lib/locales/ja/sport.yml +130 -0
  274. data/lib/locales/ja/studio_ghibli.yml +112 -0
  275. data/lib/locales/ja/subscription.yml +8 -0
  276. data/lib/locales/ja/super_mario.yml +9 -0
  277. data/lib/locales/ja/super_smash_bros.yml +8 -0
  278. data/lib/locales/ja/touhou.yml +466 -0
  279. data/lib/locales/ja/university.yml +9 -0
  280. data/lib/locales/ja/zelda.yml +5 -0
  281. data/lib/locales/ko.yml +1361 -20
  282. data/lib/locales/lt.yml +315 -0
  283. data/lib/locales/lv.yml +1 -2
  284. data/lib/locales/mi-NZ.yml +283 -0
  285. data/lib/locales/nb-NO.yml +518 -29
  286. data/lib/locales/nl.yml +1 -1
  287. data/lib/locales/pl.yml +1 -2
  288. data/lib/locales/pt-BR.yml +8157 -660
  289. data/lib/locales/pt.yml +844 -45
  290. data/lib/locales/ru.yml +1355 -32
  291. data/lib/locales/sk.yml +4410 -43
  292. data/lib/locales/sv.yml +100 -0
  293. data/lib/locales/th.yml +76 -76
  294. data/lib/locales/tr.yml +1 -2
  295. data/lib/locales/uk.yml +1808 -44
  296. data/lib/locales/vi.yml +1 -0
  297. data/lib/locales/zh-CN/bank.yml +17 -0
  298. data/lib/locales/zh-CN.yml +1 -0
  299. data/lib/locales/zh-TW.yml +1 -0
  300. metadata +134 -133
  301. data/History.md +0 -176
  302. data/lib/faker/default/fillmurray.rb +0 -45
  303. data/lib/faker/default/lorem_pixel.rb +0 -69
  304. data/lib/locales/ja.yml +0 -105
  305. /data/lib/faker/default/{faker_adjective.rb → adjective.rb} +0 -0
@@ -2,13 +2,35 @@
2
2
 
3
3
  module Faker
4
4
  class Internet < Base
5
- class << self
6
- def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil, domain: nil)
7
- warn_for_deprecated_arguments do |keywords|
8
- keywords << :name if legacy_name != NOT_GIVEN
9
- keywords << :separators if legacy_separators != NOT_GIVEN
10
- end
5
+ # Private, Host, and Link-Local network address blocks as defined in https://en.wikipedia.org/wiki/IPv4#Special-use_addresses
6
+ PRIVATE_IPV4_ADDRESS_RANGES = [
7
+ [10..10, 0..255, 0..255, 1..255], # 10.0.0.0/8 - Used for local communications within a private network
8
+ [100..100, 64..127, 0..255, 1..255], # 100.64.0.0/10 - Shared address space for communications between an ISP and its subscribers
9
+ [127..127, 0..255, 0..255, 1..255], # 127.0.0.0/8 - Used for loopback addresses to the local host
10
+ [169..169, 254..254, 0..255, 1..255], # 169.254.0.0/16 - Used for link-local addresses between two hosts on a single link when
11
+ [172..172, 16..31, 0..255, 1..255], # 172.16.0.0/12 - Used for local communications within a private network
12
+ [192..192, 0..0, 0..0, 1..255], # 192.0.0.0/24 - IETF Protocol Assignments
13
+ [192..192, 168..168, 0..255, 1..255], # 192.168.0.0/16 - Used for local communications within a private network
14
+ [198..198, 18..19, 0..255, 1..255] # 198.18.0.0/15 - Used for benchmark testing of inter-network communications between subnets
15
+ ].each(&:freeze).freeze
11
16
 
17
+ class << self
18
+ ##
19
+ # Returns the email address
20
+ #
21
+ # @return [String]
22
+ #
23
+ # @param name [String]
24
+ # @param separators [Array]
25
+ # @param domain [String]
26
+ #
27
+ # @example
28
+ # Faker::Internet.email #=> "renee@zieme.test"
29
+ # Faker::Internet.email(name: 'smith') #=> "smith@bergnaum.test"
30
+ # Faker::Internet.email(name: 'sam smith', separators: ['-']) #=> "smith-sam@tromp.example"
31
+ # Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: 'test') #=> "sam-smith@test.example"
32
+ # Faker::Internet.email(domain: 'gmail.com') #=> "foo@gmail.com"
33
+ def email(name: nil, separators: nil, domain: nil)
12
34
  local_part = if separators
13
35
  username(specifier: name, separators: separators)
14
36
  else
@@ -16,41 +38,37 @@ module Faker
16
38
  end
17
39
 
18
40
  sanitized_local_part = sanitize_email_local_part(local_part)
19
- construct_email(sanitized_local_part, domain_name(domain: domain))
20
- end
21
-
22
- def free_email(legacy_name = NOT_GIVEN, name: nil)
23
- warn_for_deprecated_arguments do |keywords|
24
- keywords << :name if legacy_name != NOT_GIVEN
25
- end
26
-
27
- construct_email(
28
- sanitize_email_local_part(username(specifier: name)),
29
- fetch('internet.free_email')
30
- )
31
- end
32
41
 
33
- def safe_email(legacy_name = NOT_GIVEN, name: nil)
34
- warn_for_deprecated_arguments do |keywords|
35
- keywords << :name if legacy_name != NOT_GIVEN
36
- end
42
+ generate_domain = if domain.nil?
43
+ domain_name
44
+ else
45
+ domain_name(domain: domain)
46
+ end
37
47
 
38
- construct_email(
39
- sanitize_email_local_part(username(specifier: name)),
40
- "example.#{sample(%w[org com net])}"
41
- )
48
+ construct_email(sanitized_local_part, generate_domain)
42
49
  end
43
50
 
44
- def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
45
- warn_for_deprecated_arguments do |keywords|
46
- keywords << :specifier if legacy_specifier != NOT_GIVEN
47
- keywords << :separators if legacy_separators != NOT_GIVEN
48
- end
49
-
51
+ ##
52
+ # Returns the username
53
+ #
54
+ # @return [String]
55
+ #
56
+ # @param specifier [Integer, Range, String] When int value passed it returns the username longer than specifier. Max value can be 10^6
57
+ # @param separators [Array]
58
+ #
59
+ # @example
60
+ # Faker::Internet.username(specifier: 10) #=> "lulu.goodwin"
61
+ # Faker::Internet.username(specifier: 5..10) #=> "morris"
62
+ # Faker::Internet.username(specifier: 5..10) #=> "berryberry"
63
+ # Faker::Internet.username(specifier: 20, separators: ['_']) #=> "nikki_sawaynnikki_saway"
64
+ def username(specifier: nil, separators: %w[. _])
50
65
  with_locale(:en) do
51
- return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
52
-
53
66
  case specifier
67
+ when ::String
68
+ names = specifier.gsub("'", '').scan(/[[:word:]]+/)
69
+ shuffled_names = shuffle(names)
70
+
71
+ return shuffled_names.join(sample(separators)).downcase
54
72
  when Integer
55
73
  # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
56
74
  raise ArgumentError, 'Given argument is too large' if specifier > 10**6
@@ -83,8 +101,6 @@ module Faker
83
101
  end
84
102
  end
85
103
 
86
- # rubocop:disable Metrics/ParameterLists
87
-
88
104
  ##
89
105
  # Produces a randomized string of characters suitable for passwords
90
106
  #
@@ -107,106 +123,184 @@ module Faker
107
123
  # Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true, special_characters: true) #=> "*%NkOnJsH4"
108
124
  #
109
125
  # @faker.version 2.1.3
110
- 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)
111
- # rubocop:enable Metrics/ParameterLists
112
- warn_for_deprecated_arguments do |keywords|
113
- keywords << :min_length if legacy_min_length != NOT_GIVEN
114
- keywords << :max_length if legacy_max_length != NOT_GIVEN
115
- keywords << :mix_case if legacy_mix_case != NOT_GIVEN
116
- keywords << :special_characters if legacy_special_characters != NOT_GIVEN
117
- end
126
+ def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
127
+ raise ArgumentError, 'min_length and max_length must be greater than or equal to one' if min_length < 1 || max_length < 1
128
+ raise ArgumentError, 'min_length must be smaller than or equal to max_length' unless min_length <= max_length
118
129
 
119
- min_alpha = mix_case && min_length > 1 ? 2 : 0
120
- temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
121
- diff_length = max_length - min_length
130
+ character_types = []
131
+ required_min_length = 0
122
132
 
123
- if diff_length.positive?
124
- diff_rand = rand(diff_length + 1)
125
- temp += Lorem.characters(number: diff_rand)
133
+ if mix_case
134
+ character_types << :mix_case
135
+ required_min_length += 2
126
136
  end
127
137
 
138
+ if special_characters
139
+ character_types << :special_characters
140
+ required_min_length += 1
141
+ end
142
+
143
+ raise ArgumentError, "min_length should be at least #{required_min_length} to enable #{character_types.join(', ')} configuration" if min_length < required_min_length
144
+
145
+ target_length = rand(min_length..max_length)
146
+
147
+ password = []
148
+ character_bag = []
149
+
150
+ # use lower_chars by default and add upper_chars if mix_case
151
+ lower_chars = self::LLetters
152
+ password << sample(lower_chars)
153
+ character_bag += lower_chars
154
+
155
+ digits = ('0'..'9').to_a
156
+ password << sample(digits)
157
+ character_bag += digits
158
+
128
159
  if mix_case
129
- alpha_count = 0
130
- temp.chars.each_with_index do |char, index|
131
- if char =~ /[[:alpha:]]/
132
- temp[index] = char.upcase if alpha_count.even?
133
- alpha_count += 1
134
- end
135
- end
160
+ upper_chars = self::ULetters
161
+ password << sample(upper_chars)
162
+ character_bag += upper_chars
136
163
  end
137
164
 
138
165
  if special_characters
139
- chars = %w[! @ # $ % ^ & *]
140
- rand(1..min_length).times do |i|
141
- temp[i] = chars[rand(chars.length)]
142
- end
166
+ special_chars = %w[! @ # $ % ^ & *]
167
+ password << sample(special_chars)
168
+ character_bag += special_chars
143
169
  end
144
170
 
145
- temp
146
- end
171
+ password << sample(character_bag) while password.length < target_length
147
172
 
148
- def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false, domain: nil)
149
- warn_for_deprecated_arguments do |keywords|
150
- keywords << :subdomain if legacy_subdomain != NOT_GIVEN
151
- end
173
+ shuffle(password).join
174
+ end
152
175
 
176
+ ##
177
+ # Returns the domain name
178
+ #
179
+ # @return [String]
180
+ #
181
+ # @param subdomain [Bool] If true passed adds a subdomain in response
182
+ # @param domain [String]
183
+ #
184
+ # @example
185
+ # Faker::Internet.domain_name #=> "altenwerth-gerhold.example"
186
+ # Faker::Internet.domain_name(subdomain: true) #=> "metz.mclaughlin-brekke.test"
187
+ # Faker::Internet.domain_name(subdomain: true, domain: 'faker') #=> "foo.faker.test"
188
+ # Faker::Internet.domain_name(domain: 'faker-ruby.org') #=> "faker-ruby.org"
189
+ # Faker::Internet.domain_name(subdomain: true, domain: 'faker-ruby.org') #=> "foo.faker-ruby.org"
190
+ # Faker::Internet.domain_name(subdomain: true, domain: 'faker.faker-ruby.org') #=> "faker.faker-ruby.org"
191
+ def domain_name(subdomain: false, domain: nil)
153
192
  with_locale(:en) do
154
193
  if domain
155
194
  domain
156
195
  .split('.')
157
196
  .map { |domain_part| Char.prepare(domain_part) }
158
197
  .tap do |domain_elements|
159
- domain_elements << domain_suffix if domain_elements.length < 2
160
- domain_elements.unshift(Char.prepare(domain_word)) if subdomain && domain_elements.length < 3
198
+ if domain_elements.length < 2
199
+ domain_elements << domain_suffix(safe: true)
200
+ end
201
+ if subdomain && domain_elements.length < 3
202
+ domain_elements.unshift(Char.prepare(domain_word))
203
+ end
161
204
  end.join('.')
162
205
  else
163
- [domain_word, domain_suffix].tap do |domain_elements|
164
- domain_elements.unshift(Char.prepare(domain_word)) if subdomain
206
+ [domain_word, domain_suffix(safe: true)].tap do |domain_elements|
207
+ if subdomain
208
+ domain_elements.unshift(Char.prepare(domain_word))
209
+ end
165
210
  end.join('.')
166
211
  end
167
212
  end
168
213
  end
169
214
 
170
- def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
171
- warn_for_deprecated_arguments do |keywords|
172
- keywords << :string if legacy_string != NOT_GIVEN
173
- end
174
-
215
+ ##
216
+ # Fixes ä, ö, ü, ß characters in string passed with ae, oe, ue, ss resp.
217
+ #
218
+ # @return [String]
219
+ #
220
+ # @param string [String]
221
+ #
222
+ # @example
223
+ # Faker::Internet.fix_umlauts #=> ""
224
+ # Faker::Internet.fix_umlauts(string: 'faker') #=> "faker"
225
+ # Faker::Internet.fix_umlauts(string: 'faküer') #=> "fakueer"
226
+ def fix_umlauts(string: '')
175
227
  Char.fix_umlauts(string)
176
228
  end
177
229
 
230
+ ##
231
+ # Returns the domain word for internet
232
+ #
233
+ # @return [String]
234
+ #
235
+ # @example
236
+ # Faker::Internet.domain_word #=> "senger"
178
237
  def domain_word
179
- with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
238
+ with_locale(:en) { Char.prepare(Company.name.split.first) }
180
239
  end
181
240
 
182
- def domain_suffix
183
- fetch('internet.domain_suffix')
184
- end
185
-
186
- def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
187
- warn_for_deprecated_arguments do |keywords|
188
- keywords << :prefix if legacy_prefix != NOT_GIVEN
241
+ ## Returns the domain suffix e.g. com, org, co, biz, info etc.
242
+ #
243
+ # @return [String]
244
+ #
245
+ # @example
246
+ # Faker::Internet.domain_suffix #=> "com"
247
+ # Faker::Internet.domain_suffix #=> "biz"
248
+ # Faker::Internet.domain_suffix(safe: true) #=> "example"
249
+ # Faker::Internet.domain_suffix(safe: true) #=> "test"
250
+ def domain_suffix(safe: nil)
251
+ if safe
252
+ fetch('internet.safe_domain_suffix')
253
+ else
254
+ fetch('internet.domain_suffix')
189
255
  end
256
+ end
190
257
 
258
+ ##
259
+ # Returns the MAC address
260
+ #
261
+ # @return [String]
262
+ #
263
+ # @example
264
+ # Faker::Internet.mac_address #=> "74:d0:c9:22:95:12"
265
+ # Faker::Internet.mac_address(prefix: 'a') #=> "0a:91:ce:24:89:3b"
266
+ # Faker::Internet.mac_address(prefix: 'aa') #=> "aa:38:a0:3e:e8:41"
267
+ # Faker::Internet.mac_address(prefix: 'aa:44') #=> "aa:44:30:88:6e:95"
268
+ def mac_address(prefix: '')
191
269
  prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
192
270
  address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
193
271
  (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
194
272
  end
195
273
 
274
+ ##
275
+ # Returns the IPv4 address
276
+ #
277
+ # @return [String]
278
+ #
279
+ # @example
280
+ # Faker::Internet.ip_v4_address #=> "97.117.128.93"
196
281
  def ip_v4_address
197
282
  [rand_in_range(0, 255), rand_in_range(0, 255),
198
283
  rand_in_range(0, 255), rand_in_range(0, 255)].join('.')
199
284
  end
200
285
 
286
+ ##
287
+ # Returns the private IPv4 address
288
+ #
289
+ # @return [String]
290
+ #
291
+ # @example
292
+ # Faker::Internet.private_ip_v4_address #=> "127.120.80.42"
201
293
  def private_ip_v4_address
202
- addr = nil
203
- loop do
204
- addr = ip_v4_address
205
- break if private_net_checker[addr]
206
- end
207
- addr
294
+ sample(PRIVATE_IPV4_ADDRESS_RANGES).map { |range| rand(range) }.join('.')
208
295
  end
209
296
 
297
+ ##
298
+ # Returns the public IPv4 address
299
+ #
300
+ # @return [String]
301
+ #
302
+ # @example
303
+ # Faker::Internet.public_ip_v4_address #=> "127.120.80.42"
210
304
  def public_ip_v4_address
211
305
  addr = nil
212
306
  loop do
@@ -216,6 +310,13 @@ module Faker
216
310
  addr
217
311
  end
218
312
 
313
+ ##
314
+ # Returns the private network regular expressions
315
+ #
316
+ # @return [Array]
317
+ #
318
+ # @example
319
+ # 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])\./]
219
320
  def private_nets_regex
220
321
  [
221
322
  /^10\./, # 10.0.0.0 - 10.255.255.255
@@ -229,10 +330,25 @@ module Faker
229
330
  ]
230
331
  end
231
332
 
333
+ ##
334
+ # Returns lambda to check if address passed is private or not
335
+ #
336
+ # @return [Lambda]
337
+ #
338
+ # @example
339
+ # Faker::Internet.private_net_checker.call("127.120.80.42") #=> true
340
+ # Faker::Internet.private_net_checker.call("148.120.80.42") #=> false
232
341
  def private_net_checker
233
342
  ->(addr) { private_nets_regex.any? { |net| net =~ addr } }
234
343
  end
235
344
 
345
+ ##
346
+ # Returns the reserved network regular expressions
347
+ #
348
+ # @return [Array]
349
+ #
350
+ # @example
351
+ # 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])\./]
236
352
  def reserved_nets_regex
237
353
  [
238
354
  /^0\./, # 0.0.0.0 - 0.255.255.255
@@ -245,58 +361,143 @@ module Faker
245
361
  ]
246
362
  end
247
363
 
364
+ ##
365
+ # Returns lambda function to check address passed is reserved or not
366
+ #
367
+ # @return [Lambda]
368
+ #
369
+ # @example
370
+ # Faker::Internet.reserved_net_checker.call('192.88.99.255') #=> true
371
+ # Faker::Internet.reserved_net_checker.call('192.88.199.255') #=> false
248
372
  def reserved_net_checker
249
373
  ->(addr) { (private_nets_regex + reserved_nets_regex).any? { |net| net =~ addr } }
250
374
  end
251
375
 
376
+ ##
377
+ # Returns Ipv4 address with CIDR, range from 1 to 31
378
+ #
379
+ # @return [String]
380
+ #
381
+ # @example
382
+ # Faker::Internet.ip_v4_cidr #=> "129.162.99.74/16"
383
+ # Faker::Internet.ip_v4_cidr #=> "129.162.99.74/24"
252
384
  def ip_v4_cidr
253
385
  "#{ip_v4_address}/#{rand(1..31)}"
254
386
  end
255
387
 
388
+ ##
389
+ # Returns Ipv6 address
390
+ #
391
+ # @return [String]
392
+ #
393
+ # @example
394
+ # Faker::Internet.ip_v6_address #=> "7754:76d4:c7aa:7646:ea68:1abb:4055:4343"
256
395
  def ip_v6_address
257
396
  (1..8).map { rand(65_536).to_s(16) }.join(':')
258
397
  end
259
398
 
399
+ ##
400
+ # Returns Ipv6 address with CIDR, range between 1 to 127
401
+ #
402
+ # @return [String]
403
+ #
404
+ # @example
405
+ # Faker::Internet.ip_v6_cidr #=> "beca:9b99:4bb6:9712:af2f:516f:8507:96e1/99"
260
406
  def ip_v6_cidr
261
407
  "#{ip_v6_address}/#{rand(1..127)}"
262
408
  end
263
409
 
264
- # rubocop:disable Metrics/ParameterLists
265
- def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
266
- # rubocop:enable Metrics/ParameterLists
267
- warn_for_deprecated_arguments do |keywords|
268
- keywords << :host if legacy_host != NOT_GIVEN
269
- keywords << :path if legacy_path != NOT_GIVEN
270
- keywords << :scheme if legacy_scheme != NOT_GIVEN
271
- end
272
-
410
+ ##
411
+ # Returns URL
412
+ #
413
+ # @return [String]
414
+ #
415
+ # @param host [String]
416
+ # @param path [String]
417
+ # @param scheme [String]
418
+ #
419
+ # @example
420
+ # Faker::Internet.url #=> "http://treutel.test/demarcus"
421
+ # Faker::Internet.url(host: 'faker') #=> "http://faker/shad"
422
+ # Faker::Internet.url(host: 'faker', path: '/docs') #=> "http://faker/docs"
423
+ # Faker::Internet.url(host: 'faker', path: '/docs', scheme: 'https') #=> "https://faker/docs"
424
+ def url(host: domain_name, path: "/#{username}", scheme: 'http')
273
425
  "#{scheme}://#{host}#{path}"
274
426
  end
275
427
 
276
- def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
277
- warn_for_deprecated_arguments do |keywords|
278
- keywords << :words if legacy_words != NOT_GIVEN
279
- keywords << :glue if legacy_glue != NOT_GIVEN
280
- end
281
-
428
+ ##
429
+ # Returns unique string in URL
430
+ #
431
+ # @return [String]
432
+ #
433
+ # @param words [String] Comma or period separated words list
434
+ # @param glue [String] Separator to add between words passed, default used are '-' or '_'
435
+ #
436
+ # @example
437
+ # Faker::Internet.slug #=> "repudiandae-sed"
438
+ # Faker::Internet.slug(words: 'test, faker') #=> "test-faker"
439
+ # Faker::Internet.slug(words: 'test. faker') #=> "test-faker"
440
+ # Faker::Internet.slug(words: 'test. faker', glue: '$') #=> "test$faker"
441
+ def slug(words: nil, glue: nil)
282
442
  glue ||= sample(%w[- _])
283
- (words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
443
+ return words.delete(',.').gsub(' ', glue).downcase unless words.nil?
444
+
445
+ sample(translate('faker.internet.slug'), 2).join(glue)
284
446
  end
285
447
 
448
+ ##
449
+ # Generates random token
450
+ #
451
+ # @return[String]
452
+ #
453
+ # @example
454
+ # Faker::Internet.device_token #=> "749f535671cf6b34d8e794d212d00c703b96274e07161b18b082d0d70ef1052f"
286
455
  def device_token
287
456
  shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
288
457
  end
289
458
 
290
- def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
291
- warn_for_deprecated_arguments do |keywords|
292
- keywords << :vendor if legacy_vendor != NOT_GIVEN
293
- end
294
-
459
+ ##
460
+ # Generates the random browser identifier
461
+ #
462
+ # @return [String]
463
+ #
464
+ # @param vendor [String] Name of vendor, supported vendors are aol, chrome, firefox, internet_explorer, netscape, opera, safari
465
+ #
466
+ # @example
467
+ # 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"
468
+ # 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"
469
+ # 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"
470
+ # 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"
471
+ def user_agent(vendor: nil)
295
472
  agent_hash = translate('faker.internet.user_agent')
296
473
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
297
474
  sample(agents)
298
475
  end
299
476
 
477
+ ##
478
+ # Generate Web Crawler's user agents
479
+ #
480
+ # @return [String]
481
+ #
482
+ # @param vendor [String] Name of vendor, supported vendors are googlebot, bingbot, duckduckbot, baiduspider, yandexbot
483
+ #
484
+ # @example
485
+ # Faker::Internet.bot_user_agent #=> "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
486
+ # Faker::Internet.bot_user_agent(vendor: 'googlebot') #=> "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/99.0.4844.84 Safari/537.36"
487
+ # Faker::Internet.bot_user_agent(vendor: 'bingbot') #=> "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/86.0.4240.68 Safari/537.36 Edg/86.0.622.31"
488
+ def bot_user_agent(vendor: nil)
489
+ agent_hash = translate('faker.internet.bot_user_agent')
490
+ agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
491
+ sample(agents)
492
+ end
493
+
494
+ ##
495
+ # Generated universally unique identifier
496
+ #
497
+ # @return [String]
498
+ #
499
+ # @example
500
+ # Faker::Internet.uuid #=> "8a6cdd40-6d78-4fdb-912b-190e3057197f"
300
501
  def uuid
301
502
  # borrowed from: https://github.com/ruby/ruby/blob/d48783bb0236db505fe1205d1d9822309de53a36/lib/securerandom.rb#L250
302
503
  ary = Faker::Config.random.bytes(16).unpack('NnnnnN')
@@ -334,6 +535,24 @@ module Faker
334
535
  s
335
536
  end
336
537
 
538
+ ##
539
+ # Produces a randomized hash of internet user details
540
+ # @example
541
+ # Faker::Internet.user #=> { username: 'alexie', email: 'trudie@grant.test' }
542
+ #
543
+ # @example
544
+ # Faker::Internet.user('username', 'email', 'password') #=> { username: 'alexie', email: 'gayle@kohler.test', password: 'DtEf9P8wS31iMyC' }
545
+ #
546
+ # @return [hash]
547
+ #
548
+ # @faker.version next
549
+ def user(*args)
550
+ user_hash = {}
551
+ args = %w[username email] if args.empty?
552
+ args.each { |arg| user_hash[:"#{arg}"] = send(arg) }
553
+ user_hash
554
+ end
555
+
337
556
  alias user_name username
338
557
 
339
558
  private
@@ -343,10 +562,10 @@ module Faker
343
562
  Array('0'..'9'),
344
563
  Array('A'..'Z'),
345
564
  Array('a'..'z'),
346
- "!#$%&'*+-/=?^_`{|}~.".split(//)
565
+ "!#$%&'*+-/=?^_`{|}~.".chars
347
566
  ].flatten
348
567
 
349
- local_part.split(//).map do |char|
568
+ local_part.chars.map do |char|
350
569
  char_range.include?(char) ? char : '#'
351
570
  end.join
352
571
  end
@@ -17,12 +17,7 @@ module Faker
17
17
  # Faker::Finance.amount_between(0, 10) #=> 4.33
18
18
  #
19
19
  # @faker.version 1.9.0
20
- def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0)
21
- warn_for_deprecated_arguments do |keywords|
22
- keywords << :from if legacy_from != NOT_GIVEN
23
- keywords << :to if legacy_to != NOT_GIVEN
24
- end
25
-
20
+ def amount_between(from: 0, to: 0)
26
21
  Faker::Base.rand_in_range(from, to).round(2)
27
22
  end
28
23
 
@@ -36,11 +31,7 @@ module Faker
36
31
  # Faker::Invoice.creditor_reference #=> "RF34118592570724925498"
37
32
  #
38
33
  # @faker.version 1.9.0
39
- def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
40
- warn_for_deprecated_arguments do |keywords|
41
- keywords << :ref if legacy_ref != NOT_GIVEN
42
- end
43
-
34
+ def creditor_reference(ref: '')
44
35
  ref = reference if ref.empty?
45
36
 
46
37
  "RF#{iban_checksum('RF', ref)}#{ref}"
@@ -56,11 +47,7 @@ module Faker
56
47
  # Faker::Invoice.reference #=> "45656646957845"
57
48
  #
58
49
  # @faker.version 1.9.0
59
- def reference(legacy_ref = NOT_GIVEN, ref: '')
60
- warn_for_deprecated_arguments do |keywords|
61
- keywords << :ref if legacy_ref != NOT_GIVEN
62
- end
63
-
50
+ def reference(ref: '')
64
51
  pattern = fetch('invoice.reference.pattern')
65
52
 
66
53
  ref = Base.regexify(/#{pattern}/) if ref.empty?
@@ -115,7 +102,7 @@ module Faker
115
102
  mod10_remainder(weighted_sum)
116
103
  end
117
104
 
118
- # Calculates weigthed sum
105
+ # Calculates weighted sum
119
106
  #
120
107
  # For example with 12345678, [1,2]
121
108
  # Ref.num. 1 2 3 4 5 6 7 8