faker 2.1.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -7
  3. data/README.md +2 -3
  4. data/lib/faker.rb +56 -1
  5. data/lib/faker/blockchain/bitcoin.rb +26 -0
  6. data/lib/faker/blockchain/ethereum.rb +10 -0
  7. data/lib/faker/blockchain/tezos.rb +62 -6
  8. data/lib/faker/books/book.rb +36 -0
  9. data/lib/faker/books/culture_series.rb +49 -0
  10. data/lib/faker/books/dune.rb +66 -5
  11. data/lib/faker/books/lovecraft.rb +210 -7
  12. data/lib/faker/creature/animal.rb +9 -0
  13. data/lib/faker/creature/cat.rb +27 -0
  14. data/lib/faker/creature/dog.rb +72 -0
  15. data/lib/faker/creature/horse.rb +18 -0
  16. data/lib/faker/default/address.rb +25 -5
  17. data/lib/faker/default/alphanumeric.rb +56 -7
  18. data/lib/faker/default/app.rb +54 -1
  19. data/lib/faker/default/artist.rb +9 -0
  20. data/lib/faker/default/avatar.rb +42 -1
  21. data/lib/faker/default/bank.rb +10 -2
  22. data/lib/faker/default/boolean.rb +16 -1
  23. data/lib/faker/default/chile_rut.rb +12 -2
  24. data/lib/faker/default/code.rb +16 -3
  25. data/lib/faker/default/commerce.rb +17 -3
  26. data/lib/faker/default/company.rb +10 -2
  27. data/lib/faker/default/crypto_coin.rb +15 -3
  28. data/lib/faker/default/date.rb +37 -5
  29. data/lib/faker/default/demographic.rb +5 -1
  30. data/lib/faker/default/driving_licence.rb +10 -4
  31. data/lib/faker/default/file.rb +19 -2
  32. data/lib/faker/default/fillmurray.rb +9 -1
  33. data/lib/faker/default/finance.rb +5 -1
  34. data/lib/faker/default/gender.rb +18 -0
  35. data/lib/faker/default/hacker.rb +59 -1
  36. data/lib/faker/default/hipster.rb +45 -6
  37. data/lib/faker/default/house.rb +18 -0
  38. data/lib/faker/default/id_number.rb +11 -3
  39. data/lib/faker/default/internet.rb +94 -13
  40. data/lib/faker/default/invoice.rb +16 -3
  41. data/lib/faker/default/json.rb +19 -2
  42. data/lib/faker/default/lorem.rb +81 -10
  43. data/lib/faker/default/lorem_flickr.rb +38 -5
  44. data/lib/faker/default/lorem_pixel.rb +10 -1
  45. data/lib/faker/default/markdown.rb +6 -1
  46. data/lib/faker/default/measurement.rb +40 -8
  47. data/lib/faker/default/name.rb +5 -1
  48. data/lib/faker/default/nhs.rb +5 -1
  49. data/lib/faker/default/number.rb +56 -11
  50. data/lib/faker/default/omniauth.rb +92 -9
  51. data/lib/faker/default/phone_number.rb +5 -1
  52. data/lib/faker/default/placeholdit.rb +11 -1
  53. data/lib/faker/default/programming_language.rb +18 -0
  54. data/lib/faker/default/relationship.rb +5 -1
  55. data/lib/faker/default/source.rb +59 -3
  56. data/lib/faker/default/string.rb +5 -1
  57. data/lib/faker/default/stripe.rb +20 -4
  58. data/lib/faker/default/time.rb +37 -4
  59. data/lib/faker/default/twitter.rb +32 -18
  60. data/lib/faker/default/types.rb +27 -5
  61. data/lib/faker/default/vehicle.rb +17 -4
  62. data/lib/faker/default/world_cup.rb +11 -2
  63. data/lib/faker/games/dota.rb +5 -1
  64. data/lib/faker/games/elder_scrolls.rb +72 -0
  65. data/lib/faker/games/fallout.rb +37 -0
  66. data/lib/faker/games/game.rb +27 -0
  67. data/lib/faker/games/half_life.rb +27 -0
  68. data/lib/faker/games/overwatch.rb +27 -0
  69. data/lib/faker/games/super_smash_bros.rb +18 -0
  70. data/lib/faker/games/zelda.rb +36 -0
  71. data/lib/faker/movies/star_wars.rb +6 -4
  72. data/lib/faker/tv_shows/breaking_bad.rb +18 -0
  73. data/lib/faker/version.rb +1 -1
  74. data/lib/locales/en-CA.yml +1 -1
  75. data/lib/locales/en/science.yml +1 -1
  76. data/lib/locales/ja.yml +1 -1
  77. metadata +31 -15
@@ -6,14 +6,41 @@ module Faker
6
6
  flexible :cat
7
7
 
8
8
  class << self
9
+ ##
10
+ # Produces a random name for a cat
11
+ #
12
+ # @return [String]
13
+ #
14
+ # @example
15
+ # Faker::Creature::Cat.name #=> "Felix"
16
+ #
17
+ # @faker.version 1.9.2
9
18
  def name
10
19
  fetch('creature.cat.name')
11
20
  end
12
21
 
22
+ ##
23
+ # Produces a random cat breed
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faker::Creature::Cat.breed #=> "Scottish Fold"
29
+ #
30
+ # @faker.version 1.9.2
13
31
  def breed
14
32
  fetch('creature.cat.breed')
15
33
  end
16
34
 
35
+ ##
36
+ # Produces a random cat breed registry
37
+ #
38
+ # @return [String]
39
+ #
40
+ # @example
41
+ # Faker::Creature::Cat.registry #=> "Fancy Southern Africa Cat Council"
42
+ #
43
+ # @faker.version 1.9.2
17
44
  def registry
18
45
  fetch('creature.cat.registry')
19
46
  end
@@ -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
@@ -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
@@ -5,7 +5,11 @@ module Faker
5
5
  flexible :address
6
6
 
7
7
  class << self
8
- def city(options: {})
8
+ def city(legacy_options = NOT_GIVEN, options: {})
9
+ warn_for_deprecated_arguments do |keywords|
10
+ keywords << :options if legacy_options != NOT_GIVEN
11
+ end
12
+
9
13
  parse(options[:with_state] ? 'address.city_with_state' : 'address.city')
10
14
  end
11
15
 
@@ -13,7 +17,11 @@ module Faker
13
17
  parse('address.street_name')
14
18
  end
15
19
 
16
- def street_address(include_secondary: false)
20
+ def street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: false)
21
+ warn_for_deprecated_arguments do |keywords|
22
+ keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN
23
+ end
24
+
17
25
  numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : ''))
18
26
  end
19
27
 
@@ -29,7 +37,11 @@ module Faker
29
37
  parse('address.community')
30
38
  end
31
39
 
32
- def zip_code(state_abbreviation: '')
40
+ def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '')
41
+ warn_for_deprecated_arguments do |keywords|
42
+ keywords << :state_abbreviation if legacy_state_abbreviation != NOT_GIVEN
43
+ end
44
+
33
45
  if state_abbreviation.empty?
34
46
  letterified_string = letterify(fetch('address.postcode'))
35
47
  return numerify(letterified_string, leading_zero: true)
@@ -71,11 +83,19 @@ module Faker
71
83
  fetch('address.country')
72
84
  end
73
85
 
74
- def country_by_code(code: 'US')
86
+ def country_by_code(legacy_code = NOT_GIVEN, code: 'US')
87
+ warn_for_deprecated_arguments do |keywords|
88
+ keywords << :code if legacy_code != NOT_GIVEN
89
+ end
90
+
75
91
  fetch('address.country_by_code.' + code)
76
92
  end
77
93
 
78
- def country_name_to_code(name: 'united_states')
94
+ def country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states')
95
+ warn_for_deprecated_arguments do |keywords|
96
+ keywords << :name if legacy_name != NOT_GIVEN
97
+ end
98
+
79
99
  fetch('address.country_by_name.' + name)
80
100
  end
81
101
 
@@ -2,22 +2,71 @@
2
2
 
3
3
  module Faker
4
4
  class Alphanumeric < Base
5
- class << self
6
- ALPHABET = ('a'..'z').to_a
7
- ALPHANUMS = ALPHABET + (0..9).to_a
5
+ ##
6
+ # List of characters allowed for alphanumeric strings
7
+ # @private
8
+ ALPHANUMS = LLetters + Numbers
8
9
 
9
- def alpha(number: 32)
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
22
+ def alpha(legacy_number = NOT_GIVEN, number: 32)
23
+ warn_for_deprecated_arguments do |keywords|
24
+ keywords << :number if legacy_number != NOT_GIVEN
25
+ end
10
26
  char_count = resolve(number)
11
27
  return '' if char_count.to_i < 1
12
28
 
13
- Array.new(char_count) { sample(ALPHABET) }.join
29
+ Array.new(char_count) { sample(self::LLetters) }.join
14
30
  end
15
31
 
16
- def alphanumeric(number: 32)
32
+ ##
33
+ # Produces a random string of alphanumeric characters
34
+ #
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
38
+ #
39
+ # @return [String]
40
+ #
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"
47
+ #
48
+ # @faker.version 2.1.3
49
+ def alphanumeric(legacy_number = NOT_GIVEN, number: 32, min_alpha: 0, min_numeric: 0)
50
+ warn_for_deprecated_arguments do |keywords|
51
+ keywords << :number if legacy_number != NOT_GIVEN
52
+ end
17
53
  char_count = resolve(number)
18
54
  return '' if char_count.to_i < 1
55
+ raise ArgumentError, 'min_alpha must be greater than or equal to 0' if min_alpha&.negative?
56
+ raise ArgumentError, 'min_numeric must be greater than or equal to 0' if min_numeric&.negative?
57
+
58
+ return Array.new(char_count) { sample(ALPHANUMS) }.join if min_alpha.zero? && min_numeric.zero?
59
+
60
+ raise ArgumentError, 'min_alpha + min_numeric must be <= number' if min_alpha + min_numeric > char_count
61
+
62
+ random_count = char_count - min_alpha - min_numeric
63
+
64
+ alphas = Array.new(min_alpha) { sample(self::LLetters) }
65
+ numbers = Array.new(min_numeric) { sample(self::Numbers) }
66
+ randoms = Array.new(random_count) { sample(ALPHANUMS) }
19
67
 
20
- Array.new(char_count) { sample(ALPHANUMS) }.join
68
+ combined = alphas + numbers + randoms
69
+ combined.shuffle.join
21
70
  end
22
71
  end
23
72
  end
@@ -3,19 +3,72 @@
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
- def semantic_version(major: 0..9, minor: 0..9, patch: 1..9)
45
+ ##
46
+ # Produces a String representing a semantic version identifier.
47
+ #
48
+ # @param major [Integer, Range] An integer to use or a range to pick the integer from.
49
+ # @param minor [Integer, Range] An integer to use or a range to pick the integer from.
50
+ # @param patch [Integer, Range] An integer to use or a range to pick the integer from.
51
+ # @return [String]
52
+ #
53
+ # @example
54
+ # Faker::App.semantic_version #=> "3.2.5"
55
+ # @example
56
+ # Faker::App.semantic_version(major: 42) #=> "42.5.2"
57
+ # @example
58
+ # Faker::App.semantic_version(minor: 100..101) #=> "42.100.4"
59
+ # @example
60
+ # Faker::App.semantic_version(patch: 5..6) #=> "7.2.6"
61
+ #
62
+ # @faker.version 1.4.3
63
+ # rubocop:disable Metrics/ParameterLists
64
+ def semantic_version(legacy_major = NOT_GIVEN, legacy_minor = NOT_GIVEN, legacy_patch = NOT_GIVEN, major: 0..9, minor: 0..9, patch: 1..9)
65
+ # rubocop:enable Metrics/ParameterLists
66
+ warn_for_deprecated_arguments do |keywords|
67
+ keywords << :major if legacy_major != NOT_GIVEN
68
+ keywords << :minor if legacy_minor != NOT_GIVEN
69
+ keywords << :patch if legacy_patch != NOT_GIVEN
70
+ end
71
+
19
72
  [major, minor, patch].map { |chunk| sample(Array(chunk)) }.join('.')
20
73
  end
21
74
  end
@@ -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
@@ -3,9 +3,50 @@
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
- def image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
9
+ ##
10
+ # Produces a URL for an avatar from robohash.org
11
+ #
12
+ # @param slug [String, nil]
13
+ # @param size [String] image size in pixels, in the format of 'AxB'
14
+ # @param format [String] The image file format
15
+ # @param set [String] The avatar set to use
16
+ # @param bgset [String, nil] The background set to use
17
+ # @return [String] A robohash.org URL
18
+ #
19
+ # @example
20
+ # Faker::Avatar.image
21
+ # #=> "https://robohash.org/sitsequiquia.png?size=300x300&set=set1"
22
+ # @example
23
+ # Faker::Avatar.image(slug: "my-own-slug")
24
+ # #=> "https://robohash.org/my-own-slug.png?size=300x300&set=set1"
25
+ # @example
26
+ # Faker::Avatar.image(slug: "my-own-slug", size: "50x50")
27
+ # #=> "https://robohash.org/my-own-slug.png?size=50x50&set=set1"
28
+ # @example
29
+ # Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "jpg")
30
+ # #=> "https://robohash.org/my-own-slug.jpg?size=50x50&set=set1"
31
+ # @example
32
+ # Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "bmp")
33
+ # #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1"
34
+ # @example
35
+ # Faker::Avatar.image(slug: "my-own-slug", size: "50x50", format: "bmp", set: "set1", bgset: "bg1")
36
+ # #=> "https://robohash.org/my-own-slug.bmp?size=50x50&set=set1&bgset=bg1"
37
+ #
38
+ # @faker.version 1.4.3
39
+ # rubocop:disable Metrics/ParameterLists
40
+ 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)
41
+ # rubocop:enable Metrics/ParameterLists
42
+ warn_for_deprecated_arguments do |keywords|
43
+ keywords << :slug if legacy_slug != NOT_GIVEN
44
+ keywords << :size if legacy_size != NOT_GIVEN
45
+ keywords << :format if legacy_format != NOT_GIVEN
46
+ keywords << :set if legacy_set != NOT_GIVEN
47
+ keywords << :bgset if legacy_bgset != NOT_GIVEN
48
+ end
49
+
9
50
  raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
10
51
  raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
11
52