faker 2.2.2 → 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 +135 -0
- data/README.md +5 -2
- 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 +56 -0
- data/lib/faker/books/book.rb +36 -0
- data/lib/faker/books/culture_series.rb +49 -0
- data/lib/faker/books/dune.rb +56 -3
- data/lib/faker/books/lovecraft.rb +172 -0
- data/lib/faker/creature/animal.rb +9 -0
- data/lib/faker/creature/cat.rb +27 -0
- data/lib/faker/creature/dog.rb +72 -0
- data/lib/faker/creature/horse.rb +18 -0
- data/lib/faker/default/alphanumeric.rb +23 -6
- data/lib/faker/default/app.rb +46 -0
- data/lib/faker/default/appliance.rb +18 -0
- data/lib/faker/default/artist.rb +9 -0
- data/lib/faker/default/avatar.rb +32 -0
- data/lib/faker/default/boolean.rb +12 -1
- data/lib/faker/default/chuck_norris.rb +1 -1
- data/lib/faker/default/date.rb +83 -2
- data/lib/faker/default/dessert.rb +27 -0
- data/lib/faker/default/device.rb +54 -0
- data/lib/faker/default/driving_licence.rb +2 -2
- data/lib/faker/default/electrical_components.rb +27 -0
- 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/house.rb +18 -0
- data/lib/faker/default/id_number.rb +29 -0
- data/lib/faker/default/industry_segments.rb +36 -0
- data/lib/faker/default/internet.rb +19 -11
- data/lib/faker/default/lorem.rb +8 -7
- data/lib/faker/default/marketing.rb +9 -0
- data/lib/faker/default/military.rb +45 -0
- data/lib/faker/default/nation.rb +48 -5
- data/lib/faker/default/nato_phonetic_alphabet.rb +9 -0
- data/lib/faker/default/number.rb +124 -0
- data/lib/faker/default/omniauth.rb +42 -0
- data/lib/faker/default/programming_language.rb +18 -0
- data/lib/faker/default/restaurant.rb +54 -2
- data/lib/faker/default/science.rb +27 -0
- data/lib/faker/default/source.rb +43 -2
- data/lib/faker/default/subscription.rb +45 -0
- data/lib/faker/default/superhero.rb +45 -0
- data/lib/faker/default/time.rb +85 -8
- data/lib/faker/default/world_cup.rb +50 -0
- data/lib/faker/games/dota.rb +47 -0
- data/lib/faker/games/elder_scrolls.rb +72 -0
- data/lib/faker/games/fallout.rb +37 -0
- data/lib/faker/games/game.rb +27 -0
- data/lib/faker/games/half_life.rb +27 -0
- data/lib/faker/games/heroes.rb +27 -0
- data/lib/faker/games/heroes_of_the_storm.rb +36 -0
- data/lib/faker/games/league_of_legends.rb +54 -0
- data/lib/faker/games/myst.rb +45 -0
- data/lib/faker/games/overwatch.rb +27 -0
- data/lib/faker/games/pokemon.rb +27 -0
- data/lib/faker/games/sonic_the_hedgehog.rb +27 -0
- data/lib/faker/games/super_smash_bros.rb +18 -0
- data/lib/faker/games/witcher.rb +54 -0
- data/lib/faker/games/world_of_warcraft.rb +18 -0
- data/lib/faker/games/zelda.rb +37 -1
- data/lib/faker/japanese_media/dragon_ball.rb +9 -0
- data/lib/faker/japanese_media/one_piece.rb +54 -0
- data/lib/faker/japanese_media/sword_art_online.rb +36 -0
- data/lib/faker/movies/back_to_the_future.rb +28 -0
- data/lib/faker/movies/ghostbusters.rb +28 -0
- data/lib/faker/movies/harry_potter.rb +54 -0
- data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +69 -0
- data/lib/faker/movies/hobbit.rb +37 -0
- data/lib/faker/movies/lebowski.rb +27 -0
- data/lib/faker/movies/lord_of_the_rings.rb +28 -0
- data/lib/faker/movies/movie.rb +9 -0
- data/lib/faker/movies/princess_bride.rb +19 -0
- data/lib/faker/movies/star_wars.rb +94 -0
- data/lib/faker/movies/v_for_vendetta.rb +29 -0
- 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 +9 -0
- data/lib/faker/tv_shows/bojack_horseman.rb +28 -0
- data/lib/faker/tv_shows/breaking_bad.rb +18 -0
- data/lib/faker/tv_shows/buffy.rb +45 -0
- data/lib/faker/tv_shows/community.rb +19 -0
- data/lib/faker/tv_shows/dr_who.rb +78 -2
- data/lib/faker/tv_shows/dumb_and_dumber.rb +28 -0
- data/lib/faker/tv_shows/family_guy.rb +28 -0
- data/lib/faker/tv_shows/friends.rb +27 -0
- data/lib/faker/tv_shows/game_of_thrones.rb +46 -0
- data/lib/faker/tv_shows/hey_arnold.rb +27 -0
- data/lib/faker/tv_shows/how_i_met_your_mother.rb +37 -0
- data/lib/faker/tv_shows/michael_scott.rb +13 -0
- data/lib/faker/tv_shows/new_girl.rb +19 -0
- data/lib/faker/tv_shows/parks_and_rec.rb +18 -0
- data/lib/faker/tv_shows/rick_and_morty.rb +28 -0
- data/lib/faker/tv_shows/ru_paul.rb +18 -0
- data/lib/faker/tv_shows/seinfeld.rb +28 -0
- data/lib/faker/tv_shows/silicon_valley.rb +75 -0
- data/lib/faker/tv_shows/simpsons.rb +28 -0
- data/lib/faker/tv_shows/south_park.rb +19 -0
- data/lib/faker/tv_shows/star_trek.rb +36 -0
- data/lib/faker/tv_shows/stargate.rb +28 -0
- data/lib/faker/tv_shows/stranger_things.rb +19 -0
- data/lib/faker/tv_shows/the_expanse.rb +36 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +28 -0
- data/lib/faker/tv_shows/the_it_crowd.rb +37 -0
- data/lib/faker/tv_shows/the_thick_of_it.rb +28 -0
- data/lib/faker/tv_shows/twin_peaks.rb +28 -0
- data/lib/faker/tv_shows/venture_bros.rb +38 -0
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en-CA.yml +2 -1
- data/lib/locales/en-TH.yml +360 -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/super_smash_bros.yml +1 -0
- data/lib/locales/fr-CA.yml +1 -1
- data/lib/locales/ja.yml +12 -9
- data/lib/locales/th.yml +380 -0
- metadata +41 -16
data/lib/faker/creature/dog.rb
CHANGED
@@ -6,34 +6,106 @@ module Faker
|
|
6
6
|
flexible :dog
|
7
7
|
|
8
8
|
class << self
|
9
|
+
##
|
10
|
+
# Produces a random name for a dog
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Faker::Creature::Dog.name #=> "Spike"
|
16
|
+
#
|
17
|
+
# @faker.version 1.9.2
|
9
18
|
def name
|
10
19
|
fetch('creature.dog.name')
|
11
20
|
end
|
12
21
|
|
22
|
+
##
|
23
|
+
# Produces a random dog breed
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Faker::Creature::Dog.breed #=> "Yorkshire Terrier"
|
29
|
+
#
|
30
|
+
# @faker.version 1.9.2
|
13
31
|
def breed
|
14
32
|
fetch('creature.dog.breed')
|
15
33
|
end
|
16
34
|
|
35
|
+
##
|
36
|
+
# Produces a random sound made by a dog
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# Faker::Creature::Dog.sound #=> "woof woof"
|
42
|
+
#
|
43
|
+
# @faker.version 1.9.2
|
17
44
|
def sound
|
18
45
|
fetch('creature.dog.sound')
|
19
46
|
end
|
20
47
|
|
48
|
+
##
|
49
|
+
# Produces a random dog meme phrase
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# Faker::Creature::Dog.meme_phrase #=> "smol pupperino"
|
55
|
+
#
|
56
|
+
# @faker.version 1.9.2
|
21
57
|
def meme_phrase
|
22
58
|
fetch('creature.dog.meme_phrase')
|
23
59
|
end
|
24
60
|
|
61
|
+
##
|
62
|
+
# Produces a random dog age
|
63
|
+
#
|
64
|
+
# @return [String]
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# Faker::Creature::Dog.age #=> "puppy"
|
68
|
+
#
|
69
|
+
# @faker.version 1.9.2
|
25
70
|
def age
|
26
71
|
fetch('creature.dog.age')
|
27
72
|
end
|
28
73
|
|
74
|
+
##
|
75
|
+
# Produces a random gender
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# Faker::Creature::Dog.gender #=> "Female"
|
81
|
+
#
|
82
|
+
# @faker.version 1.9.2
|
29
83
|
def gender
|
30
84
|
Faker::Gender.binary_type
|
31
85
|
end
|
32
86
|
|
87
|
+
##
|
88
|
+
# Produces a random coat length
|
89
|
+
#
|
90
|
+
# @return [String]
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# Faker::Creature::Dog.coat_length #=> "short"
|
94
|
+
#
|
95
|
+
# @faker.version 1.9.2
|
33
96
|
def coat_length
|
34
97
|
fetch('creature.dog.coat_length')
|
35
98
|
end
|
36
99
|
|
100
|
+
##
|
101
|
+
# Produces a random size of a dog
|
102
|
+
#
|
103
|
+
# @return [String]
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# Faker::Creature::Dog.size #=> "small"
|
107
|
+
#
|
108
|
+
# @faker.version 1.9.2
|
37
109
|
def size
|
38
110
|
fetch('creature.dog.size')
|
39
111
|
end
|
data/lib/faker/creature/horse.rb
CHANGED
@@ -6,10 +6,28 @@ module Faker
|
|
6
6
|
flexible :horse
|
7
7
|
|
8
8
|
class << self
|
9
|
+
##
|
10
|
+
# Produces a random name for a horse
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Faker::Creature::Horse.name #=> "Noir"
|
16
|
+
#
|
17
|
+
# @faker.version 1.9.2
|
9
18
|
def name
|
10
19
|
fetch('creature.horse.name')
|
11
20
|
end
|
12
21
|
|
22
|
+
##
|
23
|
+
# Produces a random horse breed
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Faker::Creature::Horse.breed #=> "Spanish Barb see Barb Horse"
|
29
|
+
#
|
30
|
+
# @faker.version 1.9.2
|
13
31
|
def breed
|
14
32
|
fetch('creature.horse.breed')
|
15
33
|
end
|
@@ -2,9 +2,23 @@
|
|
2
2
|
|
3
3
|
module Faker
|
4
4
|
class Alphanumeric < Base
|
5
|
+
##
|
6
|
+
# List of characters allowed for alphanumeric strings
|
7
|
+
# @private
|
5
8
|
ALPHANUMS = LLetters + Numbers
|
6
9
|
|
7
10
|
class << self
|
11
|
+
##
|
12
|
+
# Produces a random string of alphabetic characters (no digits)
|
13
|
+
#
|
14
|
+
# @param number [Integer] The length of the string to generate
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Faker::Alphanumeric.alpha(number: 10) #=> "zlvubkrwga"
|
20
|
+
#
|
21
|
+
# @faker.version 1.9.2
|
8
22
|
def alpha(legacy_number = NOT_GIVEN, number: 32)
|
9
23
|
warn_for_deprecated_arguments do |keywords|
|
10
24
|
keywords << :number if legacy_number != NOT_GIVEN
|
@@ -18,15 +32,18 @@ module Faker
|
|
18
32
|
##
|
19
33
|
# Produces a random string of alphanumeric characters
|
20
34
|
#
|
21
|
-
# @param [Integer] number
|
22
|
-
# @param [Integer]
|
23
|
-
# @param [Integer]
|
35
|
+
# @param number [Integer] The number of characters to generate
|
36
|
+
# @param min_alpha [Integer] The minimum number of alphabetic to add to the string
|
37
|
+
# @param min_numeric [Integer] The minimum number of numbers to add to the string
|
24
38
|
#
|
25
39
|
# @return [String]
|
26
40
|
#
|
27
|
-
# @example
|
28
|
-
#
|
29
|
-
# @example
|
41
|
+
# @example
|
42
|
+
# Faker::Alphanumeric.alphanumeric(number: 10) #=> "3yfq2phxtb"
|
43
|
+
# @example
|
44
|
+
# Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3) #=> "3yfq2phxtb"
|
45
|
+
# @example
|
46
|
+
# Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3) #=> "3yfq2phx8b"
|
30
47
|
#
|
31
48
|
# @faker.version 2.1.3
|
32
49
|
def alphanumeric(legacy_number = NOT_GIVEN, number: 32, min_alpha: 0, min_numeric: 0)
|
data/lib/faker/default/app.rb
CHANGED
@@ -3,19 +3,65 @@
|
|
3
3
|
module Faker
|
4
4
|
class App < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces an app name.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::App.name #=> "Treeflex"
|
13
|
+
#
|
14
|
+
# @faker.version 1.4.3
|
6
15
|
def name
|
7
16
|
fetch('app.name')
|
8
17
|
end
|
9
18
|
|
19
|
+
##
|
20
|
+
# Produces a version string.
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Faker::App.version #=> "1.85"
|
26
|
+
#
|
27
|
+
# @faker.version 1.4.3
|
10
28
|
def version
|
11
29
|
parse('app.version')
|
12
30
|
end
|
13
31
|
|
32
|
+
##
|
33
|
+
# Produces the name of an app's author.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Faker::App.author #=> "Daphne Swift"
|
39
|
+
#
|
40
|
+
# @faker.version 1.4.3
|
14
41
|
def author
|
15
42
|
parse('app.author')
|
16
43
|
end
|
17
44
|
|
18
45
|
# rubocop:disable Metrics/ParameterLists
|
46
|
+
|
47
|
+
##
|
48
|
+
# Produces a String representing a semantic version identifier.
|
49
|
+
#
|
50
|
+
# @param major [Integer, Range] An integer to use or a range to pick the integer from.
|
51
|
+
# @param minor [Integer, Range] An integer to use or a range to pick the integer from.
|
52
|
+
# @param patch [Integer, Range] An integer to use or a range to pick the integer from.
|
53
|
+
# @return [String]
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# Faker::App.semantic_version #=> "3.2.5"
|
57
|
+
# @example
|
58
|
+
# Faker::App.semantic_version(major: 42) #=> "42.5.2"
|
59
|
+
# @example
|
60
|
+
# Faker::App.semantic_version(minor: 100..101) #=> "42.100.4"
|
61
|
+
# @example
|
62
|
+
# Faker::App.semantic_version(patch: 5..6) #=> "7.2.6"
|
63
|
+
#
|
64
|
+
# @faker.version 1.4.3
|
19
65
|
def semantic_version(legacy_major = NOT_GIVEN, legacy_minor = NOT_GIVEN, legacy_patch = NOT_GIVEN, major: 0..9, minor: 0..9, patch: 1..9)
|
20
66
|
# rubocop:enable Metrics/ParameterLists
|
21
67
|
warn_for_deprecated_arguments do |keywords|
|
@@ -3,10 +3,28 @@
|
|
3
3
|
module Faker
|
4
4
|
class Appliance < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces the name of an appliance brand.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::Appliance.brand #=> "Bosch"
|
13
|
+
#
|
14
|
+
# @faker.version 1.9.0
|
6
15
|
def brand
|
7
16
|
fetch('appliance.brand')
|
8
17
|
end
|
9
18
|
|
19
|
+
##
|
20
|
+
# Produces the name of a type of appliance equipment.
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Faker::Appliance.equipment #=> "Appliance plug"
|
26
|
+
#
|
27
|
+
# @faker.version 1.9.0
|
10
28
|
def equipment
|
11
29
|
fetch('appliance.equipment')
|
12
30
|
end
|
data/lib/faker/default/artist.rb
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
module Faker
|
4
4
|
class Artist < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces the name of an artist.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::Artist.name #=> "Michelangelo"
|
13
|
+
#
|
14
|
+
# @faker.version 1.8.8
|
6
15
|
def name
|
7
16
|
fetch('artist.names')
|
8
17
|
end
|
data/lib/faker/default/avatar.rb
CHANGED
@@ -3,9 +3,41 @@
|
|
3
3
|
module Faker
|
4
4
|
class Avatar < Base
|
5
5
|
class << self
|
6
|
+
# @private
|
6
7
|
SUPPORTED_FORMATS = %w[png jpg bmp].freeze
|
7
8
|
|
8
9
|
# rubocop:disable Metrics/ParameterLists
|
10
|
+
|
11
|
+
##
|
12
|
+
# Produces a URL for an avatar from robohash.org
|
13
|
+
#
|
14
|
+
# @param slug [String, nil]
|
15
|
+
# @param size [String] image size in pixels, in the format of 'AxB'
|
16
|
+
# @param format [String] The image file format
|
17
|
+
# @param set [String] The avatar set to use
|
18
|
+
# @param bgset [String, nil] The background set to use
|
19
|
+
# @return [String] A robohash.org URL
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# Faker::Avatar.image
|
23
|
+
# #=> "https://robohash.org/sitsequiquia.png?size=300x300&set=set1"
|
24
|
+
# @example
|
25
|
+
# Faker::Avatar.image(slug: "my-own-slug")
|
26
|
+
# #=> "https://robohash.org/my-own-slug.png?size=300x300&set=set1"
|
27
|
+
# @example
|
28
|
+
# Faker::Avatar.image(slug: "my-own-slug", size: "50x50")
|
29
|
+
# #=> "https://robohash.org/my-own-slug.png?size=50x50&set=set1"
|
30
|
+
# @example
|
31
|
+
# Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "jpg")
|
32
|
+
# #=> "https://robohash.org/my-own-slug.jpg?size=50x50&set=set1"
|
33
|
+
# @example
|
34
|
+
# Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "bmp")
|
35
|
+
# #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1"
|
36
|
+
# @example
|
37
|
+
# Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "bmp", set: "set1", bgset: "bg1")
|
38
|
+
# #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1&bgset=bg1"
|
39
|
+
#
|
40
|
+
# @faker.version 1.4.3
|
9
41
|
def image(legacy_slug = NOT_GIVEN, legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_set = NOT_GIVEN, legacy_bgset = NOT_GIVEN, slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
|
10
42
|
# rubocop:enable Metrics/ParameterLists
|
11
43
|
warn_for_deprecated_arguments do |keywords|
|
@@ -3,11 +3,22 @@
|
|
3
3
|
module Faker
|
4
4
|
class Boolean < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces a boolean
|
8
|
+
#
|
9
|
+
# @param true_ratio [Float] The likelihood (as a float, out of 1.0) for the method to return `true`.
|
10
|
+
# @return [Boolean]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Faker::Boolean.boolean #=> true
|
14
|
+
# @example
|
15
|
+
# Faker::Boolean.boolean(true_ratio: 0.2) #=> false
|
16
|
+
#
|
17
|
+
# @faker.version 1.6.2
|
6
18
|
def boolean(legacy_true_ratio = NOT_GIVEN, true_ratio: 0.5)
|
7
19
|
warn_for_deprecated_arguments do |keywords|
|
8
20
|
keywords << :true_ratio if legacy_true_ratio != NOT_GIVEN
|
9
21
|
end
|
10
|
-
|
11
22
|
(rand < true_ratio)
|
12
23
|
end
|
13
24
|
end
|
data/lib/faker/default/date.rb
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
module Faker
|
4
4
|
class Date < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produce a random date between two dates.
|
8
|
+
#
|
9
|
+
# @param from [Date] The start of the usable date range.
|
10
|
+
# @param to [Date] The end of the usable date range.
|
11
|
+
# @return [Date]
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Faker::Date.between(from: 2.days.ago, to: Date.today)
|
15
|
+
# #=> #<Date: 2014-09-24>
|
16
|
+
#
|
17
|
+
# @faker.version 1.0.0
|
6
18
|
def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from:, to:)
|
7
19
|
warn_for_deprecated_arguments do |keywords|
|
8
20
|
keywords << :from if legacy_from != NOT_GIVEN
|
@@ -16,8 +28,21 @@ module Faker
|
|
16
28
|
end
|
17
29
|
|
18
30
|
# rubocop:disable Metrics/ParameterLists
|
31
|
+
|
32
|
+
##
|
33
|
+
# Produce a random date between two dates.
|
34
|
+
#
|
35
|
+
# @param from [Date] The start of the usable date range.
|
36
|
+
# @param to [Date] The end of the usable date range.
|
37
|
+
# @param excepted [Date] A date to exclude.
|
38
|
+
# @return [Date]
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today)
|
42
|
+
# #=> #<Date: 2014-10-03>
|
43
|
+
#
|
44
|
+
# @faker.version 1.6.2
|
19
45
|
def between_except(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_excepted = NOT_GIVEN, from:, to:, excepted:)
|
20
|
-
# rubocop:enable Metrics/ParameterLists
|
21
46
|
warn_for_deprecated_arguments do |keywords|
|
22
47
|
keywords << :from if legacy_from != NOT_GIVEN
|
23
48
|
end
|
@@ -37,7 +62,18 @@ module Faker
|
|
37
62
|
break date.to_date if date != excepted
|
38
63
|
end
|
39
64
|
end
|
40
|
-
|
65
|
+
# rubocop:enable Metrics/ParameterLists
|
66
|
+
|
67
|
+
##
|
68
|
+
# Produce a random date in the future (up to N days).
|
69
|
+
#
|
70
|
+
# @param days [Integer] The maximum number of days to go into the future.
|
71
|
+
# @return [Date]
|
72
|
+
#
|
73
|
+
# @example
|
74
|
+
# Faker::Date.forward(days: 23) #=> #<Date: 2014-10-03>
|
75
|
+
#
|
76
|
+
# @faker.version 1.0.0
|
41
77
|
def forward(legacy_days = NOT_GIVEN, days: 365)
|
42
78
|
warn_for_deprecated_arguments do |keywords|
|
43
79
|
keywords << :days if legacy_days != NOT_GIVEN
|
@@ -49,6 +85,16 @@ module Faker
|
|
49
85
|
between(from: from, to: to).to_date
|
50
86
|
end
|
51
87
|
|
88
|
+
##
|
89
|
+
# Produce a random date in the past (up to N days).
|
90
|
+
#
|
91
|
+
# @param days [Integer] The maximum number of days to go into the past.
|
92
|
+
# @return [Date]
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# Faker::Date.backward(days: 14) #=> #<Date: 2019-09-12>
|
96
|
+
#
|
97
|
+
# @faker.version 1.0.0
|
52
98
|
def backward(legacy_days = NOT_GIVEN, days: 365)
|
53
99
|
warn_for_deprecated_arguments do |keywords|
|
54
100
|
keywords << :days if legacy_days != NOT_GIVEN
|
@@ -60,6 +106,17 @@ module Faker
|
|
60
106
|
between(from: from, to: to).to_date
|
61
107
|
end
|
62
108
|
|
109
|
+
##
|
110
|
+
# Produce a random date in the past (up to N days).
|
111
|
+
#
|
112
|
+
# @param min_age [Integer] The minimum age that the birthday would imply.
|
113
|
+
# @param max_age [Integer] The maximum age that the birthday would imply.
|
114
|
+
# @return [Date]
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# Faker::Date.birthday(min_age: 18, max_age: 65) #=> #<Date: 1986-03-28>
|
118
|
+
#
|
119
|
+
# @faker.version 1.4.3
|
63
120
|
def birthday(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, min_age: 18, max_age: 65)
|
64
121
|
warn_for_deprecated_arguments do |keywords|
|
65
122
|
keywords << :min_age if legacy_min_age != NOT_GIVEN
|
@@ -76,6 +133,30 @@ module Faker
|
|
76
133
|
between(from: from, to: to).to_date
|
77
134
|
end
|
78
135
|
|
136
|
+
##
|
137
|
+
# Produces a date in the year and/or month specified.
|
138
|
+
#
|
139
|
+
# @param month [Integer] represents the month of the date
|
140
|
+
# @param year [Integer] represents the year of the date
|
141
|
+
# @return [Date]
|
142
|
+
#
|
143
|
+
# @example
|
144
|
+
# Faker::Date.in_date_period #=> #<Date: 2019-09-01>
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# Faker::Date.in_date_period(year: 2018, month: 2) #=> #<Date: 2018-02-26>
|
148
|
+
#
|
149
|
+
# @example
|
150
|
+
# Faker::Date.in_date_period(month: 2) #=> #<Date: 2019-02-26>
|
151
|
+
#
|
152
|
+
# @faker.version next
|
153
|
+
def in_date_period(month: nil, year: ::Date.today.year)
|
154
|
+
from = ::Date.new(year, month || 1, 1)
|
155
|
+
to = ::Date.new(year, month || 12, ::Date.civil(year, month || 12, -1).day)
|
156
|
+
|
157
|
+
between(from: from, to: to).to_date
|
158
|
+
end
|
159
|
+
|
79
160
|
private
|
80
161
|
|
81
162
|
def birthday_date(date, age)
|