faker 1.9.6 → 2.7.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 +386 -6
- data/README.md +12 -5
- data/lib/faker.rb +56 -1
- data/lib/faker/blockchain/aeternity.rb +70 -0
- data/lib/faker/blockchain/bitcoin.rb +26 -0
- data/lib/faker/blockchain/ethereum.rb +10 -0
- data/lib/faker/blockchain/tezos.rb +62 -6
- data/lib/faker/books/book.rb +36 -0
- data/lib/faker/books/culture_series.rb +49 -0
- data/lib/faker/books/dune.rb +66 -5
- data/lib/faker/books/lovecraft.rb +221 -18
- data/lib/faker/creature/animal.rb +10 -1
- data/lib/faker/creature/cat.rb +28 -1
- data/lib/faker/creature/dog.rb +73 -1
- data/lib/faker/creature/horse.rb +19 -1
- data/lib/faker/default/address.rb +25 -5
- data/lib/faker/default/alphanumeric.rb +58 -9
- data/lib/faker/default/app.rb +55 -1
- data/lib/faker/default/appliance.rb +18 -0
- data/lib/faker/default/artist.rb +9 -0
- data/lib/faker/default/avatar.rb +43 -1
- data/lib/faker/default/bank.rb +10 -2
- data/lib/faker/default/boolean.rb +16 -1
- data/lib/faker/default/cannabis.rb +4 -0
- data/lib/faker/default/chile_rut.rb +13 -3
- data/lib/faker/default/chuck_norris.rb +1 -1
- data/lib/faker/default/code.rb +18 -5
- data/lib/faker/default/commerce.rb +18 -4
- data/lib/faker/default/company.rb +11 -3
- data/lib/faker/default/crypto_coin.rb +21 -4
- data/lib/faker/default/date.rb +122 -9
- data/lib/faker/default/demographic.rb +5 -1
- data/lib/faker/default/dessert.rb +27 -0
- data/lib/faker/default/device.rb +56 -2
- data/lib/faker/default/driving_licence.rb +13 -7
- data/lib/faker/default/educator.rb +0 -3
- data/lib/faker/default/electrical_components.rb +27 -0
- data/lib/faker/default/file.rb +20 -3
- data/lib/faker/default/fillmurray.rb +10 -2
- data/lib/faker/default/finance.rb +5 -1
- data/lib/faker/default/gender.rb +18 -0
- data/lib/faker/default/greek_philosophers.rb +18 -0
- data/lib/faker/default/hacker.rb +59 -1
- data/lib/faker/default/hipster.rb +55 -16
- data/lib/faker/default/house.rb +18 -0
- data/lib/faker/default/id_number.rb +85 -11
- data/lib/faker/default/industry_segments.rb +36 -0
- data/lib/faker/default/internet.rb +107 -22
- data/lib/faker/default/invoice.rb +16 -3
- data/lib/faker/default/json.rb +19 -2
- data/lib/faker/default/lorem.rb +91 -20
- data/lib/faker/default/lorem_flickr.rb +38 -5
- data/lib/faker/default/lorem_pixel.rb +10 -1
- data/lib/faker/default/markdown.rb +12 -7
- data/lib/faker/default/marketing.rb +9 -0
- data/lib/faker/default/measurement.rb +40 -8
- data/lib/faker/default/military.rb +45 -0
- data/lib/faker/default/name.rb +6 -4
- data/lib/faker/default/nation.rb +48 -5
- data/lib/faker/default/nato_phonetic_alphabet.rb +9 -0
- data/lib/faker/default/nhs.rb +11 -7
- data/lib/faker/default/number.rb +202 -30
- data/lib/faker/default/omniauth.rb +98 -15
- data/lib/faker/default/phone_number.rb +5 -1
- data/lib/faker/default/placeholdit.rb +11 -1
- data/lib/faker/default/programming_language.rb +18 -0
- data/lib/faker/default/relationship.rb +5 -1
- data/lib/faker/default/restaurant.rb +54 -2
- data/lib/faker/default/science.rb +27 -0
- data/lib/faker/default/source.rb +59 -3
- data/lib/faker/default/south_africa.rb +1 -1
- data/lib/faker/default/space.rb +2 -2
- data/lib/faker/default/string.rb +5 -1
- data/lib/faker/default/stripe.rb +20 -4
- data/lib/faker/default/subscription.rb +45 -0
- data/lib/faker/default/superhero.rb +45 -0
- data/lib/faker/default/time.rb +133 -8
- data/lib/faker/default/twitter.rb +62 -48
- data/lib/faker/default/types.rb +29 -7
- data/lib/faker/default/vehicle.rb +19 -6
- data/lib/faker/default/world_cup.rb +61 -2
- data/lib/faker/games/dota.rb +53 -2
- data/lib/faker/games/elder_scrolls.rb +73 -1
- data/lib/faker/games/fallout.rb +38 -1
- data/lib/faker/games/game.rb +27 -0
- data/lib/faker/games/half_life.rb +28 -1
- data/lib/faker/games/heroes.rb +28 -1
- data/lib/faker/games/heroes_of_the_storm.rb +37 -1
- data/lib/faker/games/league_of_legends.rb +55 -1
- data/lib/faker/games/myst.rb +46 -1
- data/lib/faker/games/overwatch.rb +28 -1
- data/lib/faker/games/pokemon.rb +28 -1
- data/lib/faker/games/sonic_the_hedgehog.rb +28 -1
- data/lib/faker/games/super_smash_bros.rb +19 -1
- data/lib/faker/games/witcher.rb +55 -1
- data/lib/faker/games/world_of_warcraft.rb +19 -1
- data/lib/faker/games/zelda.rb +38 -2
- data/lib/faker/japanese_media/dragon_ball.rb +10 -1
- data/lib/faker/japanese_media/one_piece.rb +55 -1
- data/lib/faker/japanese_media/sword_art_online.rb +37 -1
- data/lib/faker/movies/back_to_the_future.rb +29 -1
- data/lib/faker/movies/ghostbusters.rb +29 -1
- data/lib/faker/movies/harry_potter.rb +55 -1
- data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +70 -1
- data/lib/faker/movies/hobbit.rb +38 -1
- data/lib/faker/movies/lebowski.rb +28 -1
- data/lib/faker/movies/lord_of_the_rings.rb +29 -1
- data/lib/faker/movies/movie.rb +9 -0
- data/lib/faker/movies/princess_bride.rb +20 -1
- data/lib/faker/movies/star_wars.rb +101 -5
- data/lib/faker/movies/v_for_vendetta.rb +30 -1
- data/lib/faker/music/grateful_dead.rb +18 -0
- data/lib/faker/music/phish.rb +9 -0
- data/lib/faker/music/rock_band.rb +9 -0
- data/lib/faker/music/umphreys_mcgee.rb +9 -0
- data/lib/faker/sports/basketball.rb +36 -0
- data/lib/faker/sports/football.rb +45 -0
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +10 -1
- data/lib/faker/tv_shows/bojack_horseman.rb +29 -1
- data/lib/faker/tv_shows/breaking_bad.rb +19 -1
- data/lib/faker/tv_shows/buffy.rb +46 -1
- data/lib/faker/tv_shows/community.rb +20 -1
- data/lib/faker/tv_shows/dr_who.rb +79 -3
- data/lib/faker/tv_shows/dumb_and_dumber.rb +29 -1
- data/lib/faker/tv_shows/family_guy.rb +29 -1
- data/lib/faker/tv_shows/friends.rb +28 -1
- data/lib/faker/tv_shows/game_of_thrones.rb +47 -1
- data/lib/faker/tv_shows/hey_arnold.rb +28 -1
- data/lib/faker/tv_shows/how_i_met_your_mother.rb +38 -1
- data/lib/faker/tv_shows/michael_scott.rb +14 -1
- data/lib/faker/tv_shows/new_girl.rb +20 -1
- data/lib/faker/tv_shows/parks_and_rec.rb +19 -1
- data/lib/faker/tv_shows/rick_and_morty.rb +29 -1
- data/lib/faker/tv_shows/ru_paul.rb +19 -1
- data/lib/faker/tv_shows/seinfeld.rb +29 -1
- data/lib/faker/tv_shows/silicon_valley.rb +76 -1
- data/lib/faker/tv_shows/simpsons.rb +29 -1
- data/lib/faker/tv_shows/south_park.rb +20 -1
- data/lib/faker/tv_shows/star_trek.rb +37 -1
- data/lib/faker/tv_shows/stargate.rb +29 -1
- data/lib/faker/tv_shows/stranger_things.rb +20 -1
- data/lib/faker/tv_shows/the_expanse.rb +37 -1
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +29 -1
- data/lib/faker/tv_shows/the_it_crowd.rb +38 -1
- data/lib/faker/tv_shows/the_thick_of_it.rb +29 -1
- data/lib/faker/tv_shows/twin_peaks.rb +29 -1
- data/lib/faker/tv_shows/venture_bros.rb +39 -1
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en-CA.yml +2 -1
- data/lib/locales/en-IND.yml +1 -1
- data/lib/locales/en-TH.yml +360 -0
- data/lib/locales/en.yml +4 -1
- data/lib/locales/en/address.yml +1 -4
- data/lib/locales/en/animal.yml +2 -2
- data/lib/locales/en/cannabis.yml +1 -0
- data/lib/locales/en/color.yml +1 -1
- data/lib/locales/en/dr_who.yml +1 -1
- data/lib/locales/en/science.yml +1 -1
- data/lib/locales/en/space.yml +1 -1
- data/lib/locales/en/super_smash_bros.yml +5 -0
- data/lib/locales/fr-CA.yml +1 -1
- data/lib/locales/ja.yml +12 -9
- data/lib/locales/th.yml +380 -0
- data/lib/locales/vi.yml +1 -1
- metadata +44 -27
- data/lib/faker/default/creature.rb +0 -6
- data/lib/faker/default/games.rb +0 -6
- data/lib/faker/default/japanese_media.rb +0 -6
- data/lib/faker/default/movies.rb +0 -6
- data/lib/faker/default/tv_shows.rb +0 -6
- data/lib/faker/deprecate/unreleased/football.rb +0 -35
- data/lib/faker/deprecate/unreleased/movies/grateful_dead.rb +0 -22
data/lib/faker/default/name.rb
CHANGED
@@ -5,8 +5,6 @@ module Faker
|
|
5
5
|
flexible :name
|
6
6
|
|
7
7
|
class << self
|
8
|
-
extend Gem::Deprecate
|
9
|
-
|
10
8
|
def name
|
11
9
|
parse('name.name')
|
12
10
|
end
|
@@ -48,8 +46,12 @@ module Faker
|
|
48
46
|
fetch('name.suffix')
|
49
47
|
end
|
50
48
|
|
51
|
-
def initials(
|
52
|
-
|
49
|
+
def initials(legacy_number = NOT_GIVEN, number: 3)
|
50
|
+
warn_for_deprecated_arguments do |keywords|
|
51
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
52
|
+
end
|
53
|
+
|
54
|
+
(0...number).map { rand(65..90).chr }.join
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
data/lib/faker/default/nation.rb
CHANGED
@@ -4,27 +4,70 @@ module Faker
|
|
4
4
|
class Nation < Base
|
5
5
|
flexible :nation
|
6
6
|
class << self
|
7
|
-
|
7
|
+
##
|
8
|
+
# Produces a random nationality.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Faker::Nation.nationality #=> "Nepalese"
|
14
|
+
#
|
15
|
+
# @faker.version 1.9.0
|
8
16
|
def nationality
|
9
17
|
fetch('nation.nationality')
|
10
18
|
end
|
11
19
|
|
12
|
-
#
|
20
|
+
# rubocop:disable Style/AsciiComments
|
21
|
+
|
22
|
+
##
|
23
|
+
# Produces a random national flag emoji.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Faker::Nation.flag #=> "🇫🇮"
|
29
|
+
#
|
30
|
+
# @faker.version 1.9.0
|
13
31
|
def flag
|
14
32
|
sample(translate('faker.nation.flag')).pack('C*').force_encoding('utf-8')
|
15
33
|
end
|
34
|
+
# rubocop:enable Style/AsciiComments
|
16
35
|
|
17
|
-
|
36
|
+
##
|
37
|
+
# Produces a random national language.
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Faker::Nation.language #=> "Nepali"
|
43
|
+
#
|
44
|
+
# @faker.version 1.9.0
|
18
45
|
def language
|
19
46
|
fetch('nation.language')
|
20
47
|
end
|
21
48
|
|
22
|
-
|
49
|
+
##
|
50
|
+
# Produces a random capital city.
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
# Faker::Nation.capital_city #=> "Kathmandu"
|
56
|
+
#
|
57
|
+
# @faker.version 1.9.0
|
23
58
|
def capital_city
|
24
59
|
fetch('nation.capital_city')
|
25
60
|
end
|
26
61
|
|
27
|
-
|
62
|
+
##
|
63
|
+
# Produces a random national sport.
|
64
|
+
#
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# Faker::Nation.national_sport #=> "dandi biyo"
|
69
|
+
#
|
70
|
+
# @faker.version 1.9.0
|
28
71
|
def national_sport
|
29
72
|
fetch('team.sport')
|
30
73
|
end
|
@@ -3,6 +3,15 @@
|
|
3
3
|
module Faker
|
4
4
|
class NatoPhoneticAlphabet < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces a code word from the NATO phonetic alphabet.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::NatoPhoneticAlphabet.code_word #=> "Hotel"
|
13
|
+
#
|
14
|
+
# @faker.version 1.9.0
|
6
15
|
def code_word
|
7
16
|
fetch('nato_phonetic_alphabet.code_word')
|
8
17
|
end
|
data/lib/faker/default/nhs.rb
CHANGED
@@ -7,15 +7,19 @@ module Faker
|
|
7
7
|
base_number = rand(400_000_001...499_999_999)
|
8
8
|
# If the check digit is equivalent to 10, the number is invalid.
|
9
9
|
# See https://en.wikipedia.org/wiki/NHS_number
|
10
|
-
base_number -= 1 if check_digit(base_number) == 10
|
11
|
-
"#{base_number}#{check_digit(base_number)}".to_s
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
base_number -= 1 if check_digit(number: base_number) == 10
|
11
|
+
"#{base_number}#{check_digit(number: base_number)}".to_s
|
12
|
+
.chars
|
13
|
+
.insert(3, ' ')
|
14
|
+
.insert(7, ' ')
|
15
|
+
.join('')
|
16
16
|
end
|
17
17
|
|
18
|
-
def check_digit(
|
18
|
+
def check_digit(legacy_number = NOT_GIVEN, number: 0)
|
19
|
+
warn_for_deprecated_arguments do |keywords|
|
20
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
21
|
+
end
|
22
|
+
|
19
23
|
sum = 0
|
20
24
|
number.to_s.chars.each_with_index do |digit, idx|
|
21
25
|
position = idx + 1
|
data/lib/faker/default/number.rb
CHANGED
@@ -3,82 +3,257 @@
|
|
3
3
|
module Faker
|
4
4
|
class Number < Base
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
##
|
7
|
+
# Produce a random number.
|
8
|
+
#
|
9
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
10
|
+
# @return [Integer]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Faker::Number.number(digits: 10) #=> 1968353479
|
14
|
+
#
|
15
|
+
# @faker.version 1.0.0
|
16
|
+
def number(legacy_digits = NOT_GIVEN, digits: 10)
|
17
|
+
warn_for_deprecated_arguments do |keywords|
|
18
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
14
19
|
end
|
15
20
|
|
16
|
-
|
21
|
+
return if digits < 1
|
22
|
+
return rand(0..9).round if digits == 1
|
23
|
+
|
24
|
+
# Ensure the first digit is not zero
|
25
|
+
([non_zero_digit] + generate(digits - 1)).join.to_i
|
17
26
|
end
|
18
27
|
|
19
|
-
|
28
|
+
##
|
29
|
+
# Produce a random number with a leading zero.
|
30
|
+
#
|
31
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
32
|
+
# @return [String]
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Faker::Number.leading_zero_number(digits: 10) #=> "0669336915"
|
36
|
+
#
|
37
|
+
# @faker.version 1.0.0
|
38
|
+
def leading_zero_number(legacy_digits = NOT_GIVEN, digits: 10)
|
39
|
+
warn_for_deprecated_arguments do |keywords|
|
40
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
41
|
+
end
|
42
|
+
|
20
43
|
'0' + (2..digits).collect { digit }.join
|
21
44
|
end
|
22
45
|
|
23
|
-
|
46
|
+
##
|
47
|
+
# Produce a number with a number of digits, preserves leading zeroes.
|
48
|
+
#
|
49
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
50
|
+
# @return [String]
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# Faker::Number.decimal_part(digits: 2) #=> "09"
|
54
|
+
#
|
55
|
+
# @faker.version 1.0.0
|
56
|
+
def decimal_part(legacy_digits = NOT_GIVEN, digits: 10)
|
57
|
+
warn_for_deprecated_arguments do |keywords|
|
58
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
59
|
+
end
|
60
|
+
|
24
61
|
num = ''
|
25
62
|
if digits > 1
|
26
63
|
num = non_zero_digit
|
27
64
|
digits -= 1
|
28
65
|
end
|
29
|
-
leading_zero_number(digits) + num
|
66
|
+
leading_zero_number(digits: digits) + num.to_s
|
30
67
|
end
|
31
68
|
|
32
|
-
|
33
|
-
|
34
|
-
|
69
|
+
##
|
70
|
+
# Produces a float.
|
71
|
+
#
|
72
|
+
# @param l_digits [Integer] Number of digits that the generated decimal should have to the left of the decimal point.
|
73
|
+
# @param r_digits [Integer] Number of digits that the generated decimal should have to the right of the decimal point.
|
74
|
+
# @return [Float]
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# Faker::Number.decimal(l_digits: 2) #=> 11.88
|
78
|
+
# Faker::Number.decimal(l_digits: 3, r_digits: 3) #=> 181.843
|
79
|
+
#
|
80
|
+
# @faker.version 1.0.0
|
81
|
+
def decimal(legacy_l_digits = NOT_GIVEN, legacy_r_digits = NOT_GIVEN, l_digits: 5, r_digits: 2)
|
82
|
+
warn_for_deprecated_arguments do |keywords|
|
83
|
+
keywords << :l_digits if legacy_l_digits != NOT_GIVEN
|
84
|
+
keywords << :r_digits if legacy_r_digits != NOT_GIVEN
|
85
|
+
end
|
35
86
|
|
36
|
-
|
87
|
+
l_d = number(digits: l_digits)
|
88
|
+
r_d = if r_digits == 1
|
89
|
+
generate(r_digits)
|
90
|
+
else
|
91
|
+
# Ensure the last digit is not zero
|
92
|
+
# so it does not get truncated on converting to float
|
93
|
+
generate(r_digits - 1).join + non_zero_digit.to_s
|
94
|
+
end
|
95
|
+
"#{l_d}.#{r_d}".to_f
|
37
96
|
end
|
38
97
|
|
98
|
+
##
|
99
|
+
# Produces a non-zero single-digit integer.
|
100
|
+
#
|
101
|
+
# @return [Integer]
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# Faker::Number.non_zero_digit #=> 8
|
105
|
+
#
|
106
|
+
# @faker.version 1.0.0
|
39
107
|
def non_zero_digit
|
40
|
-
rand(1..9)
|
108
|
+
rand(1..9)
|
41
109
|
end
|
42
110
|
|
111
|
+
##
|
112
|
+
# Produces a single-digit integer.
|
113
|
+
#
|
114
|
+
# @return [Integer]
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# Faker::Number.digit #=> 1
|
118
|
+
#
|
119
|
+
# @faker.version 1.0.0
|
43
120
|
def digit
|
44
|
-
rand(10)
|
121
|
+
rand(10)
|
45
122
|
end
|
46
123
|
|
47
|
-
|
124
|
+
##
|
125
|
+
# Produces a number in hexadecimal format.
|
126
|
+
#
|
127
|
+
# @param digits [Integer] Number of digits in the he
|
128
|
+
# @return [String]
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# Faker::Number.hexadecimal(digits: 3) #=> "e74"
|
132
|
+
#
|
133
|
+
# @faker.version 1.0.0
|
134
|
+
def hexadecimal(legacy_digits = NOT_GIVEN, digits: 6)
|
135
|
+
warn_for_deprecated_arguments do |keywords|
|
136
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
137
|
+
end
|
138
|
+
|
48
139
|
hex = ''
|
49
140
|
digits.times { hex += rand(15).to_s(16) }
|
50
141
|
hex
|
51
142
|
end
|
52
143
|
|
53
|
-
|
144
|
+
##
|
145
|
+
# Produces a float given a mean and standard deviation.
|
146
|
+
#
|
147
|
+
# @param mean [Integer]
|
148
|
+
# @param standard_deviation [Integer, Float]
|
149
|
+
# @return [Float]
|
150
|
+
#
|
151
|
+
# @example
|
152
|
+
# Faker::Number.normal(mean: 50, standard_deviation: 3.5) #=> 47.14669604069156
|
153
|
+
#
|
154
|
+
# @faker.version 1.0.0
|
155
|
+
def normal(legacy_mean = NOT_GIVEN, legacy_standard_deviation = NOT_GIVEN, mean: 1, standard_deviation: 1)
|
156
|
+
warn_for_deprecated_arguments do |keywords|
|
157
|
+
keywords << :mean if legacy_mean != NOT_GIVEN
|
158
|
+
keywords << :standard_deviation if legacy_standard_deviation != NOT_GIVEN
|
159
|
+
end
|
160
|
+
|
54
161
|
theta = 2 * Math::PI * rand
|
55
162
|
rho = Math.sqrt(-2 * Math.log(1 - rand))
|
56
163
|
scale = standard_deviation * rho
|
57
164
|
mean + scale * Math.cos(theta)
|
58
165
|
end
|
59
166
|
|
60
|
-
|
167
|
+
##
|
168
|
+
# Produces a number between two provided values. Boundaries are inclusive.
|
169
|
+
#
|
170
|
+
# @param from [Integer] The lowest number to include.
|
171
|
+
# @param to [Integer] The highest number to include.
|
172
|
+
# @return [Integer]
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# Faker::Number.between(from: 1, to: 10) #=> 7
|
176
|
+
#
|
177
|
+
# @faker.version 1.0.0
|
178
|
+
def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 1.00, to: 5000.00)
|
179
|
+
warn_for_deprecated_arguments do |keywords|
|
180
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
181
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
182
|
+
end
|
183
|
+
|
61
184
|
Faker::Base.rand_in_range(from, to)
|
62
185
|
end
|
63
186
|
|
64
|
-
|
65
|
-
|
187
|
+
##
|
188
|
+
# Produces a number within two provided values. Boundaries are inclusive or exclusive depending on the range passed.
|
189
|
+
#
|
190
|
+
# @param range [Range] The range from which to generate a number.
|
191
|
+
# @return [Integer]
|
192
|
+
#
|
193
|
+
# @example
|
194
|
+
# Faker::Number.within(range: 1..10) #=> 7
|
195
|
+
#
|
196
|
+
# @faker.version 1.0.0
|
197
|
+
def within(legacy_range = NOT_GIVEN, range: 1.00..5000.00)
|
198
|
+
warn_for_deprecated_arguments do |keywords|
|
199
|
+
keywords << :range if legacy_range != NOT_GIVEN
|
200
|
+
end
|
201
|
+
|
202
|
+
between(from: range.min, to: range.max)
|
66
203
|
end
|
67
204
|
|
68
|
-
|
69
|
-
|
205
|
+
##
|
206
|
+
# Produces a positive float.
|
207
|
+
#
|
208
|
+
# @param from [Integer] The lower boundary.
|
209
|
+
# @param to [Integer] The higher boundary.
|
210
|
+
# @return [Float]
|
211
|
+
#
|
212
|
+
# @example
|
213
|
+
# Faker::Number.positive #=> 235.59238499107653
|
214
|
+
#
|
215
|
+
# @faker.version 1.0.0
|
216
|
+
def positive(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 1.00, to: 5000.00)
|
217
|
+
warn_for_deprecated_arguments do |keywords|
|
218
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
219
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
220
|
+
end
|
221
|
+
|
222
|
+
random_number = between(from: from, to: to)
|
70
223
|
|
71
224
|
greater_than_zero(random_number)
|
72
225
|
end
|
73
226
|
|
74
|
-
|
75
|
-
|
227
|
+
##
|
228
|
+
# Produces a negative float.
|
229
|
+
#
|
230
|
+
# @param from [Integer] The lower boundary.
|
231
|
+
# @param to [Integer] The higher boundary.
|
232
|
+
# @return [Float]
|
233
|
+
#
|
234
|
+
# @example
|
235
|
+
# Faker::Number.negative #=> -4480.042585669558
|
236
|
+
#
|
237
|
+
# @faker.version 1.0.0
|
238
|
+
def negative(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: -5000.00, to: -1.00)
|
239
|
+
warn_for_deprecated_arguments do |keywords|
|
240
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
241
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
242
|
+
end
|
243
|
+
|
244
|
+
random_number = between(from: from, to: to)
|
76
245
|
|
77
246
|
less_than_zero(random_number)
|
78
247
|
end
|
79
248
|
|
80
249
|
private
|
81
250
|
|
251
|
+
def generate(count)
|
252
|
+
return [] if count.zero?
|
253
|
+
|
254
|
+
Array.new(count) { digit }
|
255
|
+
end
|
256
|
+
|
82
257
|
def greater_than_zero(number)
|
83
258
|
should_be(number, :>)
|
84
259
|
end
|
@@ -94,9 +269,6 @@ module Faker
|
|
94
269
|
number * -1
|
95
270
|
end
|
96
271
|
end
|
97
|
-
|
98
|
-
deprecate :decimal_part, nil, 2019, 06
|
99
|
-
deprecate :leading_zero_number, nil, 2019, 06
|
100
272
|
end
|
101
273
|
end
|
102
274
|
end
|
@@ -10,12 +10,20 @@ module Faker
|
|
10
10
|
|
11
11
|
def initialize(name: nil, email: nil)
|
12
12
|
@name = name || "#{Name.first_name} #{Name.last_name}"
|
13
|
-
@email = email || Internet.safe_email(self.name)
|
13
|
+
@email = email || Internet.safe_email(name: self.name)
|
14
14
|
@first_name, @last_name = self.name.split
|
15
15
|
end
|
16
16
|
|
17
17
|
class << self
|
18
|
-
|
18
|
+
# rubocop:disable Metrics/ParameterLists
|
19
|
+
def google(legacy_name = NOT_GIVEN, legacy_email = NOT_GIVEN, legacy_uid = NOT_GIVEN, name: nil, email: nil, uid: Number.number(digits: 9).to_s)
|
20
|
+
# rubocop:enable Metrics/ParameterLists
|
21
|
+
warn_for_deprecated_arguments do |keywords|
|
22
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
23
|
+
keywords << :email if legacy_email != NOT_GIVEN
|
24
|
+
keywords << :uid if legacy_uid != NOT_GIVEN
|
25
|
+
end
|
26
|
+
|
19
27
|
auth = Omniauth.new(name: name, email: email)
|
20
28
|
{
|
21
29
|
provider: 'google_oauth2',
|
@@ -27,7 +35,7 @@ module Faker
|
|
27
35
|
email: auth.email,
|
28
36
|
image: image
|
29
37
|
},
|
30
|
-
credentials:
|
38
|
+
credentials: {
|
31
39
|
token: Crypto.md5,
|
32
40
|
refresh_token: Crypto.md5,
|
33
41
|
expires_at: Time.forward.to_i,
|
@@ -35,7 +43,7 @@ module Faker
|
|
35
43
|
},
|
36
44
|
extra: {
|
37
45
|
raw_info: {
|
38
|
-
sub:
|
46
|
+
sub: uid,
|
39
47
|
email: auth.email,
|
40
48
|
email_verified: random_boolean.to_s,
|
41
49
|
name: auth.name,
|
@@ -44,7 +52,7 @@ module Faker
|
|
44
52
|
profile: "https://plus.google.com/#{uid}",
|
45
53
|
picture: image,
|
46
54
|
gender: gender,
|
47
|
-
birthday: Date.backward(36_400).strftime('%Y-%m-%d'),
|
55
|
+
birthday: Date.backward(days: 36_400).strftime('%Y-%m-%d'),
|
48
56
|
local: 'en',
|
49
57
|
hd: "#{Company.name.downcase}.com"
|
50
58
|
},
|
@@ -52,7 +60,7 @@ module Faker
|
|
52
60
|
'iss' => 'accounts.google.com',
|
53
61
|
'at_hash' => Crypto.md5,
|
54
62
|
'email_verified' => true,
|
55
|
-
'sub' => Number.number(28).to_s,
|
63
|
+
'sub' => Number.number(digits: 28).to_s,
|
56
64
|
'azp' => 'APP_ID',
|
57
65
|
'email' => auth.email,
|
58
66
|
'aud' => 'APP_ID',
|
@@ -64,7 +72,16 @@ module Faker
|
|
64
72
|
}
|
65
73
|
end
|
66
74
|
|
67
|
-
|
75
|
+
# rubocop:disable Metrics/ParameterLists
|
76
|
+
def facebook(legacy_name = NOT_GIVEN, legacy_email = NOT_GIVEN, legacy_username = NOT_GIVEN, legacy_uid = NOT_GIVEN, name: nil, email: nil, username: nil, uid: Number.number(digits: 7).to_s)
|
77
|
+
# rubocop:enable Metrics/ParameterLists
|
78
|
+
warn_for_deprecated_arguments do |keywords|
|
79
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
80
|
+
keywords << :email if legacy_email != NOT_GIVEN
|
81
|
+
keywords << :username if legacy_username != NOT_GIVEN
|
82
|
+
keywords << :uid if legacy_uid != NOT_GIVEN
|
83
|
+
end
|
84
|
+
|
68
85
|
auth = Omniauth.new(name: name, email: email)
|
69
86
|
username ||= "#{auth.first_name.downcase[0]}#{auth.last_name.downcase}"
|
70
87
|
{
|
@@ -92,7 +109,7 @@ module Faker
|
|
92
109
|
link: "http://www.facebook.com/#{username}",
|
93
110
|
username: username,
|
94
111
|
location: {
|
95
|
-
id: Number.number(9),
|
112
|
+
id: Number.number(digits: 9).to_s,
|
96
113
|
name: city_state
|
97
114
|
},
|
98
115
|
gender: gender,
|
@@ -106,7 +123,15 @@ module Faker
|
|
106
123
|
}
|
107
124
|
end
|
108
125
|
|
109
|
-
|
126
|
+
# rubocop:disable Metrics/ParameterLists
|
127
|
+
def twitter(legacy_name = NOT_GIVEN, legacy_nickname = NOT_GIVEN, legacy_uid = NOT_GIVEN, name: nil, nickname: nil, uid: Number.number(digits: 6).to_s)
|
128
|
+
# rubocop:enable Metrics/ParameterLists
|
129
|
+
warn_for_deprecated_arguments do |keywords|
|
130
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
131
|
+
keywords << :nickname if legacy_nickname != NOT_GIVEN
|
132
|
+
keywords << :uid if legacy_uid != NOT_GIVEN
|
133
|
+
end
|
134
|
+
|
110
135
|
auth = Omniauth.new(name: name)
|
111
136
|
nickname ||= auth.name.downcase.delete(' ')
|
112
137
|
location = city_state
|
@@ -179,7 +204,15 @@ module Faker
|
|
179
204
|
}
|
180
205
|
end
|
181
206
|
|
182
|
-
|
207
|
+
# rubocop:disable Metrics/ParameterLists
|
208
|
+
def linkedin(legacy_name = NOT_GIVEN, legacy_email = NOT_GIVEN, legacy_uid = NOT_GIVEN, name: nil, email: nil, uid: Number.number(digits: 6).to_s)
|
209
|
+
# rubocop:enable Metrics/ParameterLists
|
210
|
+
warn_for_deprecated_arguments do |keywords|
|
211
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
212
|
+
keywords << :email if legacy_email != NOT_GIVEN
|
213
|
+
keywords << :uid if legacy_uid != NOT_GIVEN
|
214
|
+
end
|
215
|
+
|
183
216
|
auth = Omniauth.new(name: name, email: email)
|
184
217
|
first_name = auth.first_name.downcase
|
185
218
|
last_name = auth.last_name.downcase
|
@@ -242,7 +275,15 @@ module Faker
|
|
242
275
|
}
|
243
276
|
end
|
244
277
|
|
245
|
-
|
278
|
+
# rubocop:disable Metrics/ParameterLists
|
279
|
+
def github(legacy_name = NOT_GIVEN, legacy_email = NOT_GIVEN, legacy_uid = NOT_GIVEN, name: nil, email: nil, uid: Number.number(digits: 8).to_s)
|
280
|
+
# rubocop:enable Metrics/ParameterLists
|
281
|
+
warn_for_deprecated_arguments do |keywords|
|
282
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
283
|
+
keywords << :email if legacy_email != NOT_GIVEN
|
284
|
+
keywords << :uid if legacy_uid != NOT_GIVEN
|
285
|
+
end
|
286
|
+
|
246
287
|
auth = Omniauth.new(name: name, email: email)
|
247
288
|
login = auth.name.downcase.tr(' ', '-')
|
248
289
|
html_url = "https://github.com/#{login}"
|
@@ -261,7 +302,7 @@ module Faker
|
|
261
302
|
},
|
262
303
|
credentials: {
|
263
304
|
token: Crypto.md5,
|
264
|
-
expires:
|
305
|
+
expires: false
|
265
306
|
},
|
266
307
|
extra: {
|
267
308
|
raw_info: {
|
@@ -281,7 +322,7 @@ module Faker
|
|
281
322
|
events_url: "#{api_url}/events{/privacy}",
|
282
323
|
received_events_url: "#{api_url}/received_events",
|
283
324
|
type: 'User',
|
284
|
-
site_admin:
|
325
|
+
site_admin: random_boolean,
|
285
326
|
name: auth.name,
|
286
327
|
company: nil,
|
287
328
|
blog: nil,
|
@@ -293,8 +334,50 @@ module Faker
|
|
293
334
|
public_gists: random_number_from_range(1..1000),
|
294
335
|
followers: random_number_from_range(1..1000),
|
295
336
|
following: random_number_from_range(1..1000),
|
296
|
-
created_at: Time.backward(36_400).iso8601,
|
297
|
-
updated_at: Time.backward(2).iso8601
|
337
|
+
created_at: Time.backward(days: 36_400).iso8601,
|
338
|
+
updated_at: Time.backward(days: 2).iso8601
|
339
|
+
}
|
340
|
+
}
|
341
|
+
}
|
342
|
+
end
|
343
|
+
|
344
|
+
##
|
345
|
+
# Generate a mock Omniauth response from Apple
|
346
|
+
#
|
347
|
+
# @param name [String] A specific name to return in the response
|
348
|
+
# @param email [String] A specific email to return in the response
|
349
|
+
# @param uid [String] A specific UID to return in the response
|
350
|
+
#
|
351
|
+
# @return [Hash] An auth hash in the format provided by omniauth-apple
|
352
|
+
def apple(name: nil, email: nil, uid: nil)
|
353
|
+
uid ||= "#{Number.number(digits: 6)}.#{Number.hexadecimal(digits: 32)}.#{Number.number(digits: 4)}"
|
354
|
+
auth = Omniauth.new(name: name, email: email)
|
355
|
+
{
|
356
|
+
provider: 'apple',
|
357
|
+
uid: uid,
|
358
|
+
info: {
|
359
|
+
sub: uid,
|
360
|
+
email: auth.email,
|
361
|
+
first_name: auth.first_name,
|
362
|
+
last_name: auth.last_name
|
363
|
+
},
|
364
|
+
credentials: {
|
365
|
+
token: Crypto.md5,
|
366
|
+
refresh_token: Crypto.md5,
|
367
|
+
expires_at: Time.forward.to_i,
|
368
|
+
expires: true
|
369
|
+
},
|
370
|
+
extra: {
|
371
|
+
raw_info: {
|
372
|
+
iss: 'https://appleid.apple.com',
|
373
|
+
aud: 'CLIENT_ID',
|
374
|
+
exp: Time.forward.to_i,
|
375
|
+
iat: Time.forward.to_i,
|
376
|
+
sub: uid,
|
377
|
+
at_hash: Crypto.md5,
|
378
|
+
auth_time: Time.forward.to_i,
|
379
|
+
email: auth.email,
|
380
|
+
email_verified: true
|
298
381
|
}
|
299
382
|
}
|
300
383
|
}
|