faker 2.11.0 → 2.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +421 -13
- data/History.md +4 -4
- data/README.md +33 -3
- data/lib/faker.rb +28 -23
- data/lib/faker/blockchain/aeternity.rb +4 -4
- data/lib/faker/blockchain/bitcoin.rb +2 -2
- data/lib/faker/blockchain/tezos.rb +30 -2
- data/lib/faker/books/dune.rb +15 -2
- data/lib/faker/books/lovecraft.rb +8 -4
- data/lib/faker/creature/bird.rb +203 -0
- data/lib/faker/default/address.rb +35 -5
- data/lib/faker/default/app.rb +1 -1
- data/lib/faker/default/avatar.rb +1 -1
- data/lib/faker/default/bank.rb +96 -3
- data/lib/faker/default/barcode.rb +165 -0
- data/lib/faker/default/beer.rb +3 -3
- data/lib/faker/default/blood.rb +48 -0
- data/lib/faker/default/business.rb +1 -1
- data/lib/faker/default/camera.rb +46 -0
- data/lib/faker/default/cannabis.rb +10 -0
- data/lib/faker/default/chile_rut.rb +47 -3
- data/lib/faker/default/chuck_norris.rb +1 -0
- data/lib/faker/default/code.rb +98 -17
- data/lib/faker/default/commerce.rb +74 -11
- data/lib/faker/default/company.rb +96 -11
- data/lib/faker/default/compass.rb +135 -0
- data/lib/faker/default/computer.rb +63 -0
- data/lib/faker/default/construction.rb +54 -0
- data/lib/faker/default/cosmere.rb +90 -0
- data/lib/faker/default/crypto.rb +17 -4
- data/lib/faker/default/crypto_coin.rb +45 -0
- data/lib/faker/default/date.rb +16 -12
- data/lib/faker/default/driving_licence.rb +67 -1
- data/lib/faker/default/drone.rb +332 -0
- data/lib/faker/default/educator.rb +13 -0
- data/lib/faker/default/faker_adjective.rb +35 -0
- data/lib/faker/default/file.rb +53 -2
- data/lib/faker/default/finance.rb +45 -0
- data/lib/faker/default/food.rb +1 -1
- data/lib/faker/default/gender.rb +1 -1
- data/lib/faker/default/hipster.rb +107 -10
- data/lib/faker/default/id_number.rb +122 -2
- data/lib/faker/default/internet.rb +266 -12
- data/lib/faker/default/internet_http.rb +48 -0
- data/lib/faker/default/invoice.rb +33 -6
- data/lib/faker/default/json.rb +61 -5
- data/lib/faker/default/lorem.rb +160 -5
- data/lib/faker/default/lorem_flickr.rb +67 -7
- data/lib/faker/default/lorem_pixel.rb +23 -0
- data/lib/faker/default/markdown.rb +91 -0
- data/lib/faker/default/measurement.rb +93 -2
- data/lib/faker/default/military.rb +26 -0
- data/lib/faker/default/mountain.rb +33 -0
- data/lib/faker/default/name.rb +98 -0
- data/lib/faker/default/nhs.rb +19 -0
- data/lib/faker/default/number.rb +28 -13
- data/lib/faker/default/omniauth.rb +62 -14
- data/lib/faker/default/phone_number.rb +88 -5
- data/lib/faker/default/placeholdit.rb +23 -1
- data/lib/faker/default/relationship.rb +1 -1
- data/lib/faker/default/science.rb +26 -0
- data/lib/faker/default/slack_emoji.rb +81 -0
- data/lib/faker/default/south_africa.rb +90 -0
- data/lib/faker/default/space.rb +1 -1
- data/lib/faker/default/string.rb +20 -3
- data/lib/faker/default/stripe.rb +64 -3
- data/lib/faker/default/tea.rb +41 -0
- data/lib/faker/default/twitter.rb +35 -0
- data/lib/faker/default/types.rb +84 -3
- data/lib/faker/default/university.rb +45 -0
- data/lib/faker/default/vehicle.rb +184 -4
- data/lib/faker/default/verb.rb +45 -0
- data/lib/faker/default/world_cup.rb +4 -4
- data/lib/faker/fantasy/tolkien.rb +67 -0
- data/lib/faker/games/clash_of_clans.rb +48 -0
- data/lib/faker/games/control.rb +113 -0
- data/lib/faker/games/dnd.rb +136 -0
- data/lib/faker/games/elder_scrolls.rb +26 -0
- data/lib/faker/games/heroes.rb +13 -0
- data/lib/faker/games/heroes_of_the_storm.rb +16 -5
- data/lib/faker/games/minecraft.rb +113 -0
- data/lib/faker/games/street_fighter.rb +61 -0
- data/lib/faker/games/super_mario.rb +48 -0
- data/lib/faker/games/touhou.rb +75 -0
- data/lib/faker/games/warhammer_fantasy.rb +74 -0
- data/lib/faker/games/witcher.rb +39 -0
- data/lib/faker/games/world_of_warcraft.rb +26 -1
- data/lib/faker/japanese_media/conan.rb +48 -0
- data/lib/faker/japanese_media/doraemon.rb +48 -0
- data/lib/faker/japanese_media/dragon_ball.rb +26 -0
- data/lib/faker/japanese_media/naruto.rb +61 -0
- data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
- data/lib/faker/movies/departed.rb +49 -0
- data/lib/faker/movies/hobbit.rb +4 -4
- data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
- data/lib/faker/movies/lord_of_the_rings.rb +3 -3
- data/lib/faker/movies/movie.rb +13 -0
- data/lib/faker/movies/room.rb +63 -0
- data/lib/faker/movies/star_wars.rb +74 -2
- data/lib/faker/music/hiphop.rb +48 -0
- data/lib/faker/music/music.rb +12 -0
- data/lib/faker/music/opera.rb +237 -1
- data/lib/faker/music/pearl_jam.rb +50 -0
- data/lib/faker/music/phish.rb +27 -1
- data/lib/faker/music/prince.rb +64 -0
- data/lib/faker/music/rock_band.rb +12 -0
- data/lib/faker/music/rush.rb +37 -0
- data/lib/faker/music/show.rb +49 -0
- data/lib/faker/quotes/quote.rb +80 -1
- data/lib/faker/quotes/rajnikanth.rb +1 -0
- data/lib/faker/quotes/shakespeare.rb +70 -0
- data/lib/faker/sports/volleyball.rb +74 -0
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
- data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
- data/lib/faker/tv_shows/buffy.rb +17 -4
- data/lib/faker/tv_shows/dr_who.rb +1 -1
- data/lib/faker/tv_shows/final_space.rb +51 -0
- data/lib/faker/tv_shows/futurama.rb +65 -0
- data/lib/faker/tv_shows/simpsons.rb +14 -0
- data/lib/faker/tv_shows/suits.rb +37 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
- data/lib/faker/version.rb +1 -1
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/char.rb +22 -27
- data/lib/helpers/unique_generator.rb +0 -2
- data/lib/locales/de-AT.yml +4 -2
- data/lib/locales/de-CH.yml +1696 -1
- data/lib/locales/de.yml +4 -2
- data/lib/locales/en-AU.yml +50 -10
- data/lib/locales/en-CA.yml +2 -0
- data/lib/locales/en-GB.yml +1 -1
- data/lib/locales/en-IND.yml +2 -1
- data/lib/locales/en-MS.yml +2 -1
- data/lib/locales/en-NEP.yml +4 -1
- data/lib/locales/en-NZ.yml +3 -1
- data/lib/locales/en-PAK.yml +2 -1
- data/lib/locales/en-SG.yml +2 -1
- data/lib/locales/en-US.yml +37 -11
- data/lib/locales/en-au-ocker.yml +2 -1
- data/lib/locales/en.yml +0 -3
- data/lib/locales/en/address.yml +2 -0
- data/lib/locales/en/adjective.yml +179 -0
- data/lib/locales/en/animal.yml +1 -1
- data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/barcode.yml +24 -0
- data/lib/locales/en/big_bang_theory.yml +38 -0
- data/lib/locales/en/bird.yml +1281 -0
- data/lib/locales/en/blood.yml +13 -0
- data/lib/locales/en/book.yml +487 -3
- data/lib/locales/en/buffy.yml +1 -1
- data/lib/locales/en/camera.yml +611 -0
- data/lib/locales/en/clash_of_clan.yml +101 -0
- data/lib/locales/en/company.yml +2 -2
- data/lib/locales/en/computer.yml +36 -0
- data/lib/locales/en/conan.yml +171 -0
- data/lib/locales/en/control.yml +247 -0
- data/lib/locales/en/demographic.yml +218 -5
- data/lib/locales/en/departed.yml +50 -0
- data/lib/locales/en/device.yml +112 -4
- data/lib/locales/en/dnd.yml +451 -0
- data/lib/locales/en/doraemon.yml +286 -0
- data/lib/locales/en/dota.yml +531 -63
- data/lib/locales/en/dragon_ball.yml +243 -1
- data/lib/locales/en/driving_license.yml +181 -0
- data/lib/locales/en/drone.yml +95 -0
- data/lib/locales/en/dune.yml +270 -131
- data/lib/locales/en/educator.yml +6 -0
- data/lib/locales/en/elder_scrolls.yml +583 -9
- data/lib/locales/en/fallout.yml +311 -133
- data/lib/locales/en/final_space.yml +37 -0
- data/lib/locales/en/finance.yml +53 -0
- data/lib/locales/en/football.yml +3 -3
- data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
- data/lib/locales/en/futurama.yml +344 -0
- data/lib/locales/en/half_life.yml +84 -3
- data/lib/locales/en/heroes.yml +408 -3
- data/lib/locales/en/heroes_of_the_storm.yml +131 -4
- data/lib/locales/en/house.yml +1 -1
- data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
- data/lib/locales/en/jack_handey.yml +54 -0
- data/lib/locales/en/league_of_legends.yml +285 -6
- data/lib/locales/en/lebowski.yml +1 -1
- data/lib/locales/en/lovecraft.yml +76 -6
- data/lib/locales/en/military.yml +179 -5
- data/lib/locales/en/minecraft.yml +663 -0
- data/lib/locales/en/mountain.yml +158 -0
- data/lib/locales/en/movie.yml +192 -1
- data/lib/locales/en/music.yml +461 -29
- data/lib/locales/en/myst.yml +87 -31
- data/lib/locales/en/name.yml +5 -4
- data/lib/locales/en/naruto.yml +231 -0
- data/lib/locales/en/one_piece.yml +2 -2
- data/lib/locales/en/opera.yml +168 -0
- data/lib/locales/en/overwatch.yml +2650 -2622
- data/lib/locales/en/pearl_jam.yml +213 -0
- data/lib/locales/en/phish.yml +392 -1
- data/lib/locales/en/pokemon.yml +417 -4
- data/lib/locales/en/prince.yml +227 -0
- data/lib/locales/en/quote.yml +692 -163
- data/lib/locales/en/rock_band.yml +1 -0
- data/lib/locales/en/room.yml +68 -0
- data/lib/locales/en/rush.yml +32 -0
- data/lib/locales/en/science.yml +355 -3
- data/lib/locales/en/shakespeare.yml +21 -24
- data/lib/locales/en/show.yml +597 -0
- data/lib/locales/en/simpsons.yml +668 -0
- data/lib/locales/en/source.yml +30 -0
- data/lib/locales/en/space.yml +1 -1
- data/lib/locales/en/star_trek.yml +1 -1
- data/lib/locales/en/star_wars.yml +568 -220
- data/lib/locales/en/street_fighter.yml +1524 -0
- data/lib/locales/en/studio_ghibli.yml +107 -0
- data/lib/locales/en/suits.yml +45 -0
- data/lib/locales/en/super_mario.yml +58 -0
- data/lib/locales/en/super_smash_bros.yml +18 -4
- data/lib/locales/en/tea.yml +172 -0
- data/lib/locales/en/tolkien.yml +2453 -0
- data/lib/locales/en/touhou.yml +839 -0
- data/lib/locales/en/volleyball.yml +501 -0
- data/lib/locales/en/warhammer_fantasy.yml +582 -0
- data/lib/locales/en/witcher.yml +426 -7
- data/lib/locales/en/world_of_warcraft.yml +122 -4
- data/lib/locales/en/zelda.yml +962 -4
- data/lib/locales/es-AR.yml +4603 -0
- data/lib/locales/es.yml +56 -0
- data/lib/locales/fi-FI.yml +1 -1
- data/lib/locales/fr-CA.yml +21 -5
- data/lib/locales/fr-CH.yml +2 -2
- data/lib/locales/fr.yml +1 -113
- data/lib/locales/fr/address.yml +21 -0
- data/lib/locales/fr/book.yml +7 -0
- data/lib/locales/fr/color.yml +4 -0
- data/lib/locales/fr/company.yml +17 -0
- data/lib/locales/fr/compass.yml +23 -0
- data/lib/locales/fr/demographic.yml +4 -0
- data/lib/locales/fr/gender.yml +6 -0
- data/lib/locales/fr/internet.yml +5 -0
- data/lib/locales/fr/lorem.yml +5 -0
- data/lib/locales/fr/measurement.yml +7 -0
- data/lib/locales/fr/name.yml +21 -0
- data/lib/locales/fr/phone_number.yml +7 -0
- data/lib/locales/fr/pokemon.yml +9 -0
- data/lib/locales/id.yml +3 -1
- data/lib/locales/it.yml +2 -1
- data/lib/locales/ja/README.md +13 -0
- data/lib/locales/ja/address.yml +17 -0
- data/lib/locales/ja/ancient.yml +4 -0
- data/lib/locales/ja/bank.yml +4 -0
- data/lib/locales/ja/book.yml +7 -0
- data/lib/locales/ja/coffee.yml +4 -0
- data/lib/locales/ja/color.yml +4 -0
- data/lib/locales/ja/commerce.yml +11 -0
- data/lib/locales/ja/company.yml +8 -0
- data/lib/locales/ja/creature.yml +9 -0
- data/lib/locales/ja/food.yml +4 -0
- data/lib/locales/ja/games.yml +18 -0
- data/lib/locales/ja/gender.yml +4 -0
- data/lib/locales/ja/lorem.yml +9 -0
- data/lib/locales/ja/name.yml +13 -0
- data/lib/locales/ja/phone_number.yml +7 -0
- data/lib/locales/ja/restaurant.yml +11 -0
- data/lib/locales/ja/space.yml +5 -0
- data/lib/locales/ja/subscription.yml +8 -0
- data/lib/locales/ja/university.yml +9 -0
- data/lib/locales/ko.yml +94 -2
- data/lib/locales/nb-NO.yml +4 -2
- data/lib/locales/pt-BR.yml +3 -1
- data/lib/locales/pt.yml +3 -1
- data/lib/locales/ru.yml +42 -1
- data/lib/locales/sk.yml +4 -2
- data/lib/locales/uk.yml +2 -0
- metadata +133 -24
- data/lib/locales/en/hobbit.yml +0 -19
- data/lib/locales/en/lord_of_the_rings.yml +0 -6
- data/lib/locales/ja.yml +0 -101
@@ -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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|