faker 2.2.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -15
  3. data/README.md +2 -2
  4. data/lib/faker.rb +34 -0
  5. data/lib/faker/blockchain/aeternity.rb +70 -0
  6. data/lib/faker/blockchain/bitcoin.rb +26 -0
  7. data/lib/faker/blockchain/ethereum.rb +10 -0
  8. data/lib/faker/blockchain/tezos.rb +62 -6
  9. data/lib/faker/books/book.rb +36 -0
  10. data/lib/faker/books/culture_series.rb +49 -0
  11. data/lib/faker/books/dune.rb +60 -9
  12. data/lib/faker/books/lovecraft.rb +189 -33
  13. data/lib/faker/creature/animal.rb +9 -0
  14. data/lib/faker/creature/cat.rb +27 -0
  15. data/lib/faker/creature/dog.rb +72 -0
  16. data/lib/faker/creature/horse.rb +18 -0
  17. data/lib/faker/default/address.rb +10 -15
  18. data/lib/faker/default/alphanumeric.rb +29 -18
  19. data/lib/faker/default/app.rb +50 -11
  20. data/lib/faker/default/appliance.rb +18 -0
  21. data/lib/faker/default/artist.rb +9 -0
  22. data/lib/faker/default/avatar.rb +38 -19
  23. data/lib/faker/default/bank.rb +4 -6
  24. data/lib/faker/default/boolean.rb +14 -4
  25. data/lib/faker/default/chile_rut.rb +6 -14
  26. data/lib/faker/default/chuck_norris.rb +1 -1
  27. data/lib/faker/default/code.rb +7 -13
  28. data/lib/faker/default/commerce.rb +8 -17
  29. data/lib/faker/default/company.rb +4 -6
  30. data/lib/faker/default/crypto_coin.rb +6 -9
  31. data/lib/faker/default/date.rb +100 -30
  32. data/lib/faker/default/demographic.rb +2 -3
  33. data/lib/faker/default/dessert.rb +27 -0
  34. data/lib/faker/default/device.rb +54 -0
  35. data/lib/faker/default/driving_licence.rb +7 -17
  36. data/lib/faker/default/electrical_components.rb +27 -0
  37. data/lib/faker/default/file.rb +9 -26
  38. data/lib/faker/default/fillmurray.rb +4 -11
  39. data/lib/faker/default/finance.rb +2 -3
  40. data/lib/faker/default/gender.rb +18 -0
  41. data/lib/faker/default/greek_philosophers.rb +18 -0
  42. data/lib/faker/default/hacker.rb +59 -1
  43. data/lib/faker/default/hipster.rb +21 -54
  44. data/lib/faker/default/house.rb +18 -0
  45. data/lib/faker/default/id_number.rb +5 -7
  46. data/lib/faker/default/industry_segments.rb +36 -0
  47. data/lib/faker/default/internet.rb +49 -76
  48. data/lib/faker/default/invoice.rb +7 -13
  49. data/lib/faker/default/json.rb +9 -16
  50. data/lib/faker/default/lorem.rb +38 -77
  51. data/lib/faker/default/lorem_flickr.rb +17 -48
  52. data/lib/faker/default/lorem_pixel.rb +7 -23
  53. data/lib/faker/default/markdown.rb +3 -7
  54. data/lib/faker/default/marketing.rb +9 -0
  55. data/lib/faker/default/measurement.rb +16 -24
  56. data/lib/faker/default/military.rb +45 -0
  57. data/lib/faker/default/name.rb +2 -3
  58. data/lib/faker/default/nation.rb +48 -5
  59. data/lib/faker/default/nato_phonetic_alphabet.rb +9 -0
  60. data/lib/faker/default/nhs.rb +2 -3
  61. data/lib/faker/default/number.rb +150 -51
  62. data/lib/faker/default/omniauth.rb +67 -63
  63. data/lib/faker/default/phone_number.rb +2 -3
  64. data/lib/faker/default/placeholdit.rb +6 -19
  65. data/lib/faker/default/programming_language.rb +18 -0
  66. data/lib/faker/default/relationship.rb +2 -3
  67. data/lib/faker/default/restaurant.rb +54 -2
  68. data/lib/faker/default/science.rb +27 -0
  69. data/lib/faker/default/source.rb +51 -14
  70. data/lib/faker/default/string.rb +2 -3
  71. data/lib/faker/default/stripe.rb +8 -12
  72. data/lib/faker/default/subscription.rb +45 -0
  73. data/lib/faker/default/superhero.rb +45 -0
  74. data/lib/faker/default/time.rb +102 -56
  75. data/lib/faker/default/twitter.rb +23 -32
  76. data/lib/faker/default/types.rb +12 -23
  77. data/lib/faker/default/vehicle.rb +8 -14
  78. data/lib/faker/default/world_cup.rb +55 -10
  79. data/lib/faker/games/dota.rb +49 -3
  80. data/lib/faker/games/elder_scrolls.rb +72 -0
  81. data/lib/faker/games/fallout.rb +37 -0
  82. data/lib/faker/games/game.rb +27 -0
  83. data/lib/faker/games/half_life.rb +27 -0
  84. data/lib/faker/games/heroes.rb +27 -0
  85. data/lib/faker/games/heroes_of_the_storm.rb +36 -0
  86. data/lib/faker/games/league_of_legends.rb +54 -0
  87. data/lib/faker/games/myst.rb +45 -0
  88. data/lib/faker/games/overwatch.rb +27 -0
  89. data/lib/faker/games/pokemon.rb +27 -0
  90. data/lib/faker/games/sonic_the_hedgehog.rb +27 -0
  91. data/lib/faker/games/super_smash_bros.rb +18 -0
  92. data/lib/faker/games/witcher.rb +54 -0
  93. data/lib/faker/games/world_of_warcraft.rb +18 -0
  94. data/lib/faker/games/zelda.rb +37 -1
  95. data/lib/faker/japanese_media/dragon_ball.rb +9 -0
  96. data/lib/faker/japanese_media/one_piece.rb +54 -0
  97. data/lib/faker/japanese_media/sword_art_online.rb +36 -0
  98. data/lib/faker/movies/back_to_the_future.rb +28 -0
  99. data/lib/faker/movies/ghostbusters.rb +28 -0
  100. data/lib/faker/movies/harry_potter.rb +54 -0
  101. data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +69 -0
  102. data/lib/faker/movies/hobbit.rb +37 -0
  103. data/lib/faker/movies/lebowski.rb +27 -0
  104. data/lib/faker/movies/lord_of_the_rings.rb +28 -0
  105. data/lib/faker/movies/movie.rb +9 -0
  106. data/lib/faker/movies/princess_bride.rb +19 -0
  107. data/lib/faker/movies/star_wars.rb +97 -6
  108. data/lib/faker/movies/v_for_vendetta.rb +29 -0
  109. data/lib/faker/music/grateful_dead.rb +18 -0
  110. data/lib/faker/music/phish.rb +9 -0
  111. data/lib/faker/music/rock_band.rb +9 -0
  112. data/lib/faker/music/umphreys_mcgee.rb +9 -0
  113. data/lib/faker/sports/basketball.rb +36 -0
  114. data/lib/faker/sports/football.rb +45 -0
  115. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +9 -0
  116. data/lib/faker/tv_shows/bojack_horseman.rb +28 -0
  117. data/lib/faker/tv_shows/breaking_bad.rb +18 -0
  118. data/lib/faker/tv_shows/buffy.rb +45 -0
  119. data/lib/faker/tv_shows/community.rb +19 -0
  120. data/lib/faker/tv_shows/dr_who.rb +78 -2
  121. data/lib/faker/tv_shows/dumb_and_dumber.rb +28 -0
  122. data/lib/faker/tv_shows/family_guy.rb +28 -0
  123. data/lib/faker/tv_shows/friends.rb +27 -0
  124. data/lib/faker/tv_shows/game_of_thrones.rb +46 -0
  125. data/lib/faker/tv_shows/hey_arnold.rb +27 -0
  126. data/lib/faker/tv_shows/how_i_met_your_mother.rb +37 -0
  127. data/lib/faker/tv_shows/michael_scott.rb +13 -0
  128. data/lib/faker/tv_shows/new_girl.rb +19 -0
  129. data/lib/faker/tv_shows/parks_and_rec.rb +18 -0
  130. data/lib/faker/tv_shows/rick_and_morty.rb +28 -0
  131. data/lib/faker/tv_shows/ru_paul.rb +18 -0
  132. data/lib/faker/tv_shows/seinfeld.rb +28 -0
  133. data/lib/faker/tv_shows/silicon_valley.rb +75 -0
  134. data/lib/faker/tv_shows/simpsons.rb +28 -0
  135. data/lib/faker/tv_shows/south_park.rb +19 -0
  136. data/lib/faker/tv_shows/star_trek.rb +36 -0
  137. data/lib/faker/tv_shows/stargate.rb +28 -0
  138. data/lib/faker/tv_shows/stranger_things.rb +19 -0
  139. data/lib/faker/tv_shows/the_expanse.rb +36 -0
  140. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +28 -0
  141. data/lib/faker/tv_shows/the_it_crowd.rb +37 -0
  142. data/lib/faker/tv_shows/the_thick_of_it.rb +28 -0
  143. data/lib/faker/tv_shows/twin_peaks.rb +28 -0
  144. data/lib/faker/tv_shows/venture_bros.rb +38 -0
  145. data/lib/faker/version.rb +1 -1
  146. data/lib/locales/en-CA.yml +1 -1
  147. data/lib/locales/en-TH.yml +360 -0
  148. data/lib/locales/en/color.yml +1 -1
  149. data/lib/locales/en/dr_who.yml +1 -1
  150. data/lib/locales/en/science.yml +1 -1
  151. data/lib/locales/ja.yml +8 -9
  152. data/lib/locales/th.yml +380 -0
  153. metadata +39 -14
@@ -3,30 +3,49 @@
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
- if legacy_slug != NOT_GIVEN
12
- warn_with_uplevel 'Passing `slug` with the 1st argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(slug: ...)` instead.', uplevel: 1
13
- slug = legacy_slug
14
- end
15
- if legacy_size != NOT_GIVEN
16
- warn_with_uplevel 'Passing `size` with the 2nd argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(size: ...)` instead.', uplevel: 1
17
- size = legacy_size
18
- end
19
- if legacy_format != NOT_GIVEN
20
- warn_with_uplevel 'Passing `format` with the 3rd argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(format: ...)` instead.', uplevel: 1
21
- format = legacy_format
22
- end
23
- if legacy_set != NOT_GIVEN
24
- warn_with_uplevel 'Passing `set` with the 4th argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(set: ...)` instead.', uplevel: 1
25
- set = legacy_set
26
- end
27
- if legacy_bgset != NOT_GIVEN
28
- warn_with_uplevel 'Passing `bgset` with the 5th argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(bgset: ...)` instead.', uplevel: 1
29
- bgset = legacy_bgset
43
+ warn_for_deprecated_arguments do |keywords|
44
+ keywords << :slug if legacy_slug != NOT_GIVEN
45
+ keywords << :size if legacy_size != NOT_GIVEN
46
+ keywords << :format if legacy_format != NOT_GIVEN
47
+ keywords << :set if legacy_set != NOT_GIVEN
48
+ keywords << :bgset if legacy_bgset != NOT_GIVEN
30
49
  end
31
50
 
32
51
  raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
@@ -6,9 +6,8 @@ module Faker
6
6
 
7
7
  class << self
8
8
  def account_number(legacy_digits = NOT_GIVEN, digits: 10)
9
- if legacy_digits != NOT_GIVEN
10
- warn_with_uplevel 'Passing `digits` with the 1st argument of `Bank.account_number` is deprecated. Use keyword argument like `Bank.account_number(digits: ...)` instead.', uplevel: 1
11
- digits = legacy_digits
9
+ warn_for_deprecated_arguments do |keywords|
10
+ keywords << :digits if legacy_digits != NOT_GIVEN
12
11
  end
13
12
 
14
13
  output = ''
@@ -22,9 +21,8 @@ module Faker
22
21
  # Each country has it's own format for bank accounts
23
22
  # Many of them use letters in certain parts of the account
24
23
  # Using regex patterns we can create virtually any type of bank account
25
- if legacy_country_code != NOT_GIVEN
26
- warn_with_uplevel 'Passing `country_code` with the 1st argument of `Bank.iban` is deprecated. Use keyword argument like `Bank.iban(country_code: ...)` instead.', uplevel: 1
27
- country_code = legacy_country_code
24
+ warn_for_deprecated_arguments do |keywords|
25
+ keywords << :country_code if legacy_country_code != NOT_GIVEN
28
26
  end
29
27
 
30
28
  begin
@@ -3,12 +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
- if legacy_true_ratio != NOT_GIVEN
8
- warn_with_uplevel 'Passing `true_ratio` with the 1st argument of `Boolean.boolean` is deprecated. Use keyword argument like `Boolean.boolean(true_ratio: ...)` instead.', uplevel: 1
9
- true_ratio = legacy_true_ratio
19
+ warn_for_deprecated_arguments do |keywords|
20
+ keywords << :true_ratio if legacy_true_ratio != NOT_GIVEN
10
21
  end
11
-
12
22
  (rand < true_ratio)
13
23
  end
14
24
  end
@@ -7,13 +7,9 @@ module Faker
7
7
 
8
8
  # Fixed param added for testing a specific RUT and check digit combination.
9
9
  def rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 1, fixed: false)
10
- if legacy_min_rut != NOT_GIVEN
11
- warn_with_uplevel 'Passing `min_rut` with the 1st argument of `ChileRut.rut` is deprecated. Use keyword argument like `ChileRut.rut(min_rut: ...)` instead.', uplevel: 1
12
- min_rut = legacy_min_rut
13
- end
14
- if legacy_fixed != NOT_GIVEN
15
- warn_with_uplevel 'Passing `fixed` with the 2nd argument of `ChileRut.rut` is deprecated. Use keyword argument like `ChileRut.rut(fixed: ...)` instead.', uplevel: 1
16
- fixed = legacy_fixed
10
+ warn_for_deprecated_arguments do |keywords|
11
+ keywords << :min_rut if legacy_min_rut != NOT_GIVEN
12
+ keywords << :fixed if legacy_fixed != NOT_GIVEN
17
13
  end
18
14
 
19
15
  @last_rut = fixed ? min_rut : rand_in_range(min_rut, 99_999_999)
@@ -44,13 +40,9 @@ module Faker
44
40
  end
45
41
 
46
42
  def full_rut(legacy_min_rut = NOT_GIVEN, legacy_fixed = NOT_GIVEN, min_rut: 0, fixed: false)
47
- if legacy_min_rut != NOT_GIVEN
48
- warn_with_uplevel 'Passing `min_rut` with the 1st argument of `ChileRut.full_rut` is deprecated. Use keyword argument like `ChileRut.full_rut(min_rut: ...)` instead.', uplevel: 1
49
- min_rut = legacy_min_rut
50
- end
51
- if legacy_fixed != NOT_GIVEN
52
- warn_with_uplevel 'Passing `fixed` with the 2nd argument of `ChileRut.full_rut` is deprecated. Use keyword argument like `ChileRut.full_rut(fixed: ...)` instead.', uplevel: 1
53
- fixed = legacy_fixed
43
+ warn_for_deprecated_arguments do |keywords|
44
+ keywords << :min_rut if legacy_min_rut != NOT_GIVEN
45
+ keywords << :fixed if legacy_fixed != NOT_GIVEN
54
46
  end
55
47
 
56
48
  "#{rut(min_rut: min_rut, fixed: fixed)}-#{dv}"
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Faker
4
4
  class ChuckNorris < Base
5
- flexible :name
5
+ flexible :chuck_norris
6
6
 
7
7
  class << self
8
8
  # from: https://github.com/jenkinsci/chucknorris-plugin/blob/master/src/main/java/hudson/plugins/chucknorris/FactGenerator.java
@@ -13,9 +13,8 @@ module Faker
13
13
  # By default generates 10 sign isbn code in format 123456789-X
14
14
  # You can pass 13 to generate new 13 sign code
15
15
  def isbn(legacy_base = NOT_GIVEN, base: 10)
16
- if legacy_base != NOT_GIVEN
17
- warn_with_uplevel 'Passing `base` with the 1st argument of `Code.isbn` is deprecated. Use keyword argument like `Code.isbn(base: ...)` instead.', uplevel: 1
18
- base = legacy_base
16
+ warn_for_deprecated_arguments do |keywords|
17
+ keywords << :base if legacy_base != NOT_GIVEN
19
18
  end
20
19
 
21
20
  base == 13 ? generate_base13_isbn : generate_base10_isbn
@@ -24,9 +23,8 @@ module Faker
24
23
  # By default generates 13 sign ean code in format 1234567890123
25
24
  # You can pass 8 to generate ean8 code
26
25
  def ean(legacy_base = NOT_GIVEN, base: 13)
27
- if legacy_base != NOT_GIVEN
28
- warn_with_uplevel 'Passing `base` with the 1st argument of `Code.ean` is deprecated. Use keyword argument like `Code.ean(base: ...)` instead.', uplevel: 1
29
- base = legacy_base
26
+ warn_for_deprecated_arguments do |keywords|
27
+ keywords << :base if legacy_base != NOT_GIVEN
30
28
  end
31
29
 
32
30
  base == 8 ? generate_base8_ean : generate_base13_ean
@@ -41,13 +39,9 @@ module Faker
41
39
  # By default generates a Singaporean NRIC ID for someone
42
40
  # who is born between the age of 18 and 65.
43
41
  def nric(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, min_age: 18, max_age: 65)
44
- if legacy_min_age != NOT_GIVEN
45
- warn_with_uplevel 'Passing `min_age` with the 1st argument of `Code.nric` is deprecated. Use keyword argument like `Code.nric(min_age: ...)` instead.', uplevel: 1
46
- min_age = legacy_min_age
47
- end
48
- if legacy_max_age != NOT_GIVEN
49
- warn_with_uplevel 'Passing `max_age` with the 2nd argument of `Code.nric` is deprecated. Use keyword argument like `Code.nric(max_age: ...)` instead.', uplevel: 1
50
- max_age = legacy_max_age
42
+ warn_for_deprecated_arguments do |keywords|
43
+ keywords << :min_age if legacy_min_age != NOT_GIVEN
44
+ keywords << :max_age if legacy_max_age != NOT_GIVEN
51
45
  end
52
46
 
53
47
  birthyear = Date.birthday(min_age: min_age, max_age: max_age).year
@@ -8,9 +8,8 @@ module Faker
8
8
  end
9
9
 
10
10
  def promotion_code(legacy_digits = NOT_GIVEN, digits: 6)
11
- if legacy_digits != NOT_GIVEN
12
- warn_with_uplevel 'Passing `digits` with the 1st argument of `Commerce.promotion_code` is deprecated. Use keyword argument like `Commerce.promotion_code(digits: ...)` instead.', uplevel: 1
13
- digits = legacy_digits
11
+ warn_for_deprecated_arguments do |keywords|
12
+ keywords << :digits if legacy_digits != NOT_GIVEN
14
13
  end
15
14
 
16
15
  [
@@ -21,13 +20,9 @@ module Faker
21
20
  end
22
21
 
23
22
  def department(legacy_max = NOT_GIVEN, legacy_fixed_amount = NOT_GIVEN, max: 3, fixed_amount: false)
24
- if legacy_max != NOT_GIVEN
25
- warn_with_uplevel 'Passing `max` with the 1st argument of `Commerce.department` is deprecated. Use keyword argument like `Commerce.department(max: ...)` instead.', uplevel: 1
26
- max = legacy_max
27
- end
28
- if legacy_fixed_amount != NOT_GIVEN
29
- warn_with_uplevel 'Passing `fixed_amount` with the 2nd argument of `Commerce.department` is deprecated. Use keyword argument like `Commerce.department(fixed_amount: ...)` instead.', uplevel: 1
30
- fixed_amount = legacy_fixed_amount
23
+ warn_for_deprecated_arguments do |keywords|
24
+ keywords << :max if legacy_max != NOT_GIVEN
25
+ keywords << :fixed_amount if legacy_fixed_amount != NOT_GIVEN
31
26
  end
32
27
 
33
28
  num = max if fixed_amount
@@ -49,13 +44,9 @@ module Faker
49
44
  end
50
45
 
51
46
  def price(legacy_range = NOT_GIVEN, legacy_as_string = NOT_GIVEN, range: 0..100.0, as_string: false)
52
- if legacy_range != NOT_GIVEN
53
- warn_with_uplevel 'Passing `range` with the 1st argument of `Commerce.price` is deprecated. Use keyword argument like `Commerce.price(range: ...)` instead.', uplevel: 1
54
- range = legacy_range
55
- end
56
- if legacy_as_string != NOT_GIVEN
57
- warn_with_uplevel 'Passing `as_string` with the 2nd argument of `Commerce.price` is deprecated. Use keyword argument like `Commerce.price(as_string: ...)` instead.', uplevel: 1
58
- as_string = legacy_as_string
47
+ warn_for_deprecated_arguments do |keywords|
48
+ keywords << :range if legacy_range != NOT_GIVEN
49
+ keywords << :as_string if legacy_as_string != NOT_GIVEN
59
50
  end
60
51
 
61
52
  price = (rand(range) * 100).floor / 100.0
@@ -127,9 +127,8 @@ module Faker
127
127
 
128
128
  # Get a random Polish register of national economy number. More info https://pl.wikipedia.org/wiki/REGON
129
129
  def polish_register_of_national_economy(legacy_length = NOT_GIVEN, length: 9)
130
- if legacy_length != NOT_GIVEN
131
- warn_with_uplevel 'Passing `length` with the 1st argument of `Company.polish_register_of_national_economy` is deprecated. Use keyword argument like `Company.polish_register_of_national_economy(length: ...)` instead.', uplevel: 1
132
- length = legacy_length
130
+ warn_for_deprecated_arguments do |keywords|
131
+ keywords << :length if legacy_length != NOT_GIVEN
133
132
  end
134
133
 
135
134
  raise ArgumentError, 'Length should be 9 or 14' unless [9, 14].include? length
@@ -159,9 +158,8 @@ module Faker
159
158
  end
160
159
 
161
160
  def brazilian_company_number(legacy_formatted = NOT_GIVEN, formatted: false)
162
- if legacy_formatted != NOT_GIVEN
163
- warn_with_uplevel 'Passing `formatted` with the 1st argument of `Company.brazilian_company_number` is deprecated. Use keyword argument like `Company.brazilian_company_number(formatted: ...)` instead.', uplevel: 1
164
- formatted = legacy_formatted
161
+ warn_for_deprecated_arguments do |keywords|
162
+ keywords << :formatted if legacy_formatted != NOT_GIVEN
165
163
  end
166
164
 
167
165
  digits = Array.new(8) { Faker::Number.digit.to_i } + [0, 0, 0, Faker::Number.non_zero_digit.to_i]
@@ -8,27 +8,24 @@ module Faker
8
8
  URL_LOGO = 2
9
9
 
10
10
  def coin_name(legacy_coin = NOT_GIVEN, coin: coin_array)
11
- if legacy_coin != NOT_GIVEN
12
- warn_with_uplevel 'Passing `coin` with the 1st argument of `CryptoCoin.coin_name` is deprecated. Use keyword argument like `CryptoCoin.coin_name(coin: ...)` instead.', uplevel: 1
13
- coin = legacy_coin
11
+ warn_for_deprecated_arguments do |keywords|
12
+ keywords << :coin if legacy_coin != NOT_GIVEN
14
13
  end
15
14
 
16
15
  coin[COIN_NAME]
17
16
  end
18
17
 
19
18
  def acronym(legacy_coin = NOT_GIVEN, coin: coin_array)
20
- if legacy_coin != NOT_GIVEN
21
- warn_with_uplevel 'Passing `coin` with the 1st argument of `CryptoCoin.acronym` is deprecated. Use keyword argument like `CryptoCoin.acronym(coin: ...)` instead.', uplevel: 1
22
- coin = legacy_coin
19
+ warn_for_deprecated_arguments do |keywords|
20
+ keywords << :coin if legacy_coin != NOT_GIVEN
23
21
  end
24
22
 
25
23
  coin[ACRONYM]
26
24
  end
27
25
 
28
26
  def url_logo(legacy_coin = NOT_GIVEN, coin: coin_array)
29
- if legacy_coin != NOT_GIVEN
30
- warn_with_uplevel 'Passing `coin` with the 1st argument of `CryptoCoin.url_logo` is deprecated. Use keyword argument like `CryptoCoin.url_logo(coin: ...)` instead.', uplevel: 1
31
- coin = legacy_coin
27
+ warn_for_deprecated_arguments do |keywords|
28
+ keywords << :coin if legacy_coin != NOT_GIVEN
32
29
  end
33
30
 
34
31
  coin[URL_LOGO]
@@ -3,14 +3,22 @@
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
- if legacy_from != NOT_GIVEN
8
- warn_with_uplevel 'Passing `from` with the 1st argument of `Date.between` is deprecated. Use keyword argument like `Date.between(from: ...)` instead.', uplevel: 1
9
- from = legacy_from
10
- end
11
- if legacy_to != NOT_GIVEN
12
- warn_with_uplevel 'Passing `to` with the 2nd argument of `Date.between` is deprecated. Use keyword argument like `Date.between(to: ...)` instead.', uplevel: 1
13
- to = legacy_to
19
+ warn_for_deprecated_arguments do |keywords|
20
+ keywords << :from if legacy_from != NOT_GIVEN
21
+ keywords << :to if legacy_to != NOT_GIVEN
14
22
  end
15
23
 
16
24
  from = get_date_object(from)
@@ -20,19 +28,29 @@ module Faker
20
28
  end
21
29
 
22
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
23
45
  def between_except(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_excepted = NOT_GIVEN, from:, to:, excepted:)
24
- # rubocop:enable Metrics/ParameterLists
25
- if legacy_from != NOT_GIVEN
26
- warn_with_uplevel 'Passing `from` with the 1st argument of `Date.between_except` is deprecated. Use keyword argument like `Date.between_except(from: ...)` instead.', uplevel: 1
27
- from = legacy_from
46
+ warn_for_deprecated_arguments do |keywords|
47
+ keywords << :from if legacy_from != NOT_GIVEN
28
48
  end
29
- if legacy_to != NOT_GIVEN
30
- warn_with_uplevel 'Passing `to` with the 2nd argument of `Date.between_except` is deprecated. Use keyword argument like `Date.between_except(to: ...)` instead.', uplevel: 1
31
- to = legacy_to
49
+ warn_for_deprecated_arguments do |keywords|
50
+ keywords << :to if legacy_to != NOT_GIVEN
32
51
  end
33
- if legacy_excepted != NOT_GIVEN
34
- warn_with_uplevel 'Passing `excepted` with the 3rd argument of `Date.between_except` is deprecated. Use keyword argument like `Date.between_except(excepted: ...)` instead.', uplevel: 1
35
- excepted = legacy_excepted
52
+ warn_for_deprecated_arguments do |keywords|
53
+ keywords << :excepted if legacy_excepted != NOT_GIVEN
36
54
  end
37
55
 
38
56
  raise ArgumentError, 'From date, to date and excepted date must not be the same' if from == to && to == excepted
@@ -44,11 +62,21 @@ module Faker
44
62
  break date.to_date if date != excepted
45
63
  end
46
64
  end
47
-
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
48
77
  def forward(legacy_days = NOT_GIVEN, days: 365)
49
- if legacy_days != NOT_GIVEN
50
- warn_with_uplevel 'Passing `days` with the 1st argument of `Date.forward` is deprecated. Use keyword argument like `Date.forward(days: ...)` instead.', uplevel: 1
51
- days = legacy_days
78
+ warn_for_deprecated_arguments do |keywords|
79
+ keywords << :days if legacy_days != NOT_GIVEN
52
80
  end
53
81
 
54
82
  from = ::Date.today + 1
@@ -57,10 +85,19 @@ module Faker
57
85
  between(from: from, to: to).to_date
58
86
  end
59
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
60
98
  def backward(legacy_days = NOT_GIVEN, days: 365)
61
- if legacy_days != NOT_GIVEN
62
- warn_with_uplevel 'Passing `days` with the 1st argument of `Date.backward` is deprecated. Use keyword argument like `Date.backward(days: ...)` instead.', uplevel: 1
63
- days = legacy_days
99
+ warn_for_deprecated_arguments do |keywords|
100
+ keywords << :days if legacy_days != NOT_GIVEN
64
101
  end
65
102
 
66
103
  from = ::Date.today - days
@@ -69,14 +106,23 @@ module Faker
69
106
  between(from: from, to: to).to_date
70
107
  end
71
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
72
120
  def birthday(legacy_min_age = NOT_GIVEN, legacy_max_age = NOT_GIVEN, min_age: 18, max_age: 65)
73
- if legacy_min_age != NOT_GIVEN
74
- warn_with_uplevel 'Passing `min_age` with the 1st argument of `Date.birthday` is deprecated. Use keyword argument like `Date.birthday(min_age: ...)` instead.', uplevel: 1
75
- min_age = legacy_min_age
121
+ warn_for_deprecated_arguments do |keywords|
122
+ keywords << :min_age if legacy_min_age != NOT_GIVEN
76
123
  end
77
- if legacy_max_age != NOT_GIVEN
78
- warn_with_uplevel 'Passing `max_age` with the 2nd argument of `Date.birthday` is deprecated. Use keyword argument like `Date.birthday(max_age: ...)` instead.', uplevel: 1
79
- max_age = legacy_max_age
124
+ warn_for_deprecated_arguments do |keywords|
125
+ keywords << :max_age if legacy_max_age != NOT_GIVEN
80
126
  end
81
127
 
82
128
  t = ::Date.today
@@ -87,6 +133,30 @@ module Faker
87
133
  between(from: from, to: to).to_date
88
134
  end
89
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
+
90
160
  private
91
161
 
92
162
  def birthday_date(date, age)