faker 3.1.1 → 3.2.1

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -1
  3. data/README.md +15 -6
  4. data/lib/faker/default/chile_rut.rb +23 -17
  5. data/lib/faker/default/code.rb +60 -18
  6. data/lib/faker/default/company.rb +44 -5
  7. data/lib/faker/default/date.rb +61 -5
  8. data/lib/faker/default/driving_licence.rb +19 -8
  9. data/lib/faker/default/food.rb +13 -0
  10. data/lib/faker/default/html.rb +230 -0
  11. data/lib/faker/default/id_number.rb +17 -3
  12. data/lib/faker/default/internet.rb +62 -31
  13. data/lib/faker/default/lorem.rb +5 -2
  14. data/lib/faker/default/marketing.rb +1 -1
  15. data/lib/faker/default/omniauth.rb +1 -1
  16. data/lib/faker/default/release notes.md +59 -0
  17. data/lib/faker/default/twitter.rb +1 -1
  18. data/lib/faker/default/types.rb +3 -2
  19. data/lib/faker/default/vehicle.rb +19 -8
  20. data/lib/faker/games/dnd.rb +49 -7
  21. data/lib/faker/games/final_fantasy_xiv.rb +73 -0
  22. data/lib/faker/movies/avatar.rb +49 -0
  23. data/lib/faker/quotes/quote.rb +13 -0
  24. data/lib/faker/sports/chess.rb +90 -0
  25. data/lib/faker/travel/airport.rb +2 -6
  26. data/lib/faker/travel/train_station.rb +54 -0
  27. data/lib/faker/tv_shows/archer.rb +51 -0
  28. data/lib/faker/tv_shows/south_park.rb +15 -0
  29. data/lib/faker/version.rb +1 -1
  30. data/lib/faker.rb +13 -6
  31. data/lib/helpers/positional_generator.rb +480 -0
  32. data/lib/locales/README.md +18 -2
  33. data/lib/locales/ar.yml +1 -0
  34. data/lib/locales/bg.yml +1 -1
  35. data/lib/locales/da-DK.yml +1 -0
  36. data/lib/locales/de-AT.yml +1 -1
  37. data/lib/locales/de-CH.yml +4336 -11
  38. data/lib/locales/de.yml +1 -0
  39. data/lib/locales/en/archer.yml +75 -0
  40. data/lib/locales/en/avatar.yml +31 -0
  41. data/lib/locales/en/chess.yml +103 -0
  42. data/lib/locales/en/company.yml +1 -0
  43. data/lib/locales/en/dnd.yml +186 -1
  44. data/lib/locales/en/final_fantasy_xiv.yml +754 -0
  45. data/lib/locales/en/food.yml +12 -0
  46. data/lib/locales/en/internet.yml +3 -0
  47. data/lib/locales/en/minecraft.yml +4 -4
  48. data/lib/locales/en/mitch_hedberg.yml +46 -0
  49. data/lib/locales/en/opera.yml +1 -1
  50. data/lib/locales/en/south_park.yml +360 -2
  51. data/lib/locales/en/train_station.yml +280 -0
  52. data/lib/locales/en-AU.yml +1 -0
  53. data/lib/locales/en-CA.yml +1 -0
  54. data/lib/locales/en-GB.yml +2 -0
  55. data/lib/locales/en-MS.yml +1 -0
  56. data/lib/locales/en-NG.yml +1 -0
  57. data/lib/locales/en-NZ.yml +1 -0
  58. data/lib/locales/en-PAK.yml +1 -0
  59. data/lib/locales/en-SG.yml +1 -0
  60. data/lib/locales/en-UG.yml +1 -0
  61. data/lib/locales/en-US.yml +1 -0
  62. data/lib/locales/en-ZA.yml +1 -0
  63. data/lib/locales/en-au-ocker.yml +2 -0
  64. data/lib/locales/es-AR.yml +1 -0
  65. data/lib/locales/es-MX.yml +1 -0
  66. data/lib/locales/es.yml +1 -0
  67. data/lib/locales/fi-FI.yml +1 -0
  68. data/lib/locales/fr/name.yml +2 -1
  69. data/lib/locales/fr-CA.yml +1 -0
  70. data/lib/locales/fr-CH.yml +1 -0
  71. data/lib/locales/hy.yml +1 -0
  72. data/lib/locales/it.yml +1 -0
  73. data/lib/locales/ja/sport.yml +130 -0
  74. data/lib/locales/ko.yml +1 -0
  75. data/lib/locales/mi-NZ.yml +2 -0
  76. data/lib/locales/nb-NO.yml +1 -0
  77. data/lib/locales/nl.yml +1 -0
  78. data/lib/locales/pl.yml +1 -0
  79. data/lib/locales/pt-BR.yml +1 -0
  80. data/lib/locales/pt.yml +1 -0
  81. data/lib/locales/ru.yml +1 -0
  82. data/lib/locales/sk.yml +1 -0
  83. data/lib/locales/sv.yml +1 -0
  84. data/lib/locales/tr.yml +1 -0
  85. data/lib/locales/uk.yml +3 -0
  86. data/lib/locales/vi.yml +1 -0
  87. data/lib/locales/zh-CN.yml +1 -0
  88. data/lib/locales/zh-TW.yml +1 -0
  89. metadata +18 -144
  90. data/lib/faker/default/fillmurray.rb +0 -38
@@ -43,6 +43,19 @@ module Faker
43
43
  fetch('dnd.cities')
44
44
  end
45
45
 
46
+ ##
47
+ # Produces the first name of a character or monster from Dungeons and Dragons.
48
+ #
49
+ # @return [String]
50
+ #
51
+ # @example
52
+ # Faker::Games::DnD.name #=> "Eilonwy"
53
+ #
54
+ # @faker.version next
55
+ def first_name
56
+ fetch('dnd.name.first_name')
57
+ end
58
+
46
59
  ##
47
60
  # Produces the name of a class from Dungeons and Dragons (PHB).
48
61
  #
@@ -69,6 +82,19 @@ module Faker
69
82
  fetch('dnd.languages')
70
83
  end
71
84
 
85
+ ##
86
+ # Produces a last name from Dungeons and Dragons.
87
+ #
88
+ # @return [String]
89
+ #
90
+ # @example
91
+ # Faker::Games::DnD.last_name #=> "Leafwhisper"
92
+ #
93
+ # @faker.version next
94
+ def last_name
95
+ fetch('dnd.name.last_name')
96
+ end
97
+
72
98
  ##
73
99
  # Produces the name of a melee weapon from Dungeons and Dragons.
74
100
  #
@@ -95,6 +121,19 @@ module Faker
95
121
  fetch('dnd.monsters')
96
122
  end
97
123
 
124
+ ##
125
+ # Produces a full name from Dungeons and Dragons.
126
+ #
127
+ # @return [String]
128
+ #
129
+ # @example
130
+ # Faker::Games::DnD.name #=> "Drakon Blackthorn"
131
+ #
132
+ # @faker.version next
133
+ def name
134
+ "#{fetch('dnd.name.first_name')} #{fetch('dnd.name.last_name')}"
135
+ end
136
+
98
137
  ##
99
138
  # Produces the name of a race from Dungeons and Dragons (PHB).
100
139
  #
@@ -121,14 +160,17 @@ module Faker
121
160
  fetch('dnd.ranged_weapons')
122
161
  end
123
162
 
124
- # This method is deprecated. The implementation will be removed in a near future release.
125
- # Use `DnD.race` instead.
163
+ ##
164
+ # Produces a last name from Dungeons and Dragons.
126
165
  #
127
- # @deprecated Use {#race} instead.
128
- def species
129
- warn '`DnD.species` is deprecated. Use `DnD.race` instead.'
130
-
131
- super
166
+ # @return [String]
167
+ #
168
+ # @example
169
+ # Faker::Games::DnD.title_name #=> "Corvus the Cunning"
170
+ #
171
+ # @faker.version next
172
+ def title_name
173
+ "#{fetch('dnd.name.first_name')} #{fetch('dnd.name.title')}"
132
174
  end
133
175
  end
134
176
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Games
5
+ class FinalFantasyXIV < Base
6
+ class << self
7
+ ##
8
+ # Produces the name of a character from FFXIV.
9
+ #
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::Games::FinalFantasyXIV.character #=> "Y'shtola Rhul"
14
+ #
15
+ # @faker.version next
16
+ def character
17
+ fetch('games.final_fantasy_xiv.characters')
18
+ end
19
+
20
+ ##
21
+ # Produces a job name from Final Fantasy XIV. Either a battle or non-battle playable job.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faker::Games::FinalFantasyXIV.job #=> "Paladin"
27
+ #
28
+ # @faker.version next
29
+ def job
30
+ fetch('games.final_fantasy_xiv.jobs')
31
+ end
32
+
33
+ # Produces the name of a playable race from Final Fantasy XIV.
34
+ #
35
+ # @return [String]
36
+ #
37
+ # @example
38
+ # Faker::Games::FinalFantasyXIV.race #=> "Miqo'te"
39
+ #
40
+ # @faker.version next
41
+ def race
42
+ fetch('games.final_fantasy_xiv.races')
43
+ end
44
+
45
+ ##
46
+ # Produces a data center from Final Fantasy XIV.
47
+ #
48
+ # @return [String]
49
+ #
50
+ # @example
51
+ # Faker::Games::FinalFantasyXIV.data_center #=> "Aether"
52
+ #
53
+ # @faker.version next
54
+ def data_center
55
+ fetch('games.final_fantasy_xiv.data_centers')
56
+ end
57
+
58
+ ##
59
+ # Produces a geographical zone from Final Fantasy XIV.
60
+ #
61
+ # @return [String]
62
+ #
63
+ # @example
64
+ # Faker::Games::FinalFantasyXIV.zone #=> "Eastern La Noscea"
65
+ #
66
+ # @faker.version next
67
+ def zone
68
+ fetch('games.final_fantasy_xiv.zones')
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Movies
5
+ class Avatar < Base
6
+ class << self
7
+ ##
8
+ # Produces a character from Avatar.
9
+ #
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::Movies::Avatar.character #=> "Jake Sully"
14
+ #
15
+ # @faker.version next
16
+ def character
17
+ fetch('avatar.characters')
18
+ end
19
+
20
+ ##
21
+ # Produces a date from Avatar.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faker::Movies::Avatar.date #=> "December 15, 2022"
27
+ #
28
+ # @faker.version next
29
+ def date
30
+ fetch('avatar.dates')
31
+ end
32
+
33
+ ##
34
+ # Produces a quote from Avatar.
35
+ #
36
+ # @return [String]
37
+ #
38
+ # @example
39
+ # Faker::Movies::Avatar.quote
40
+ # #=> "If it ain't raining, we ain't training."
41
+ #
42
+ # @faker.version next
43
+ def quote
44
+ fetch('avatar.quotes')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -106,6 +106,19 @@ module Faker
106
106
  def fortune_cookie
107
107
  fetch('quote.fortune_cookie')
108
108
  end
109
+
110
+ ##
111
+ # Produces a quote from comedian Mitch Hedberg.
112
+ #
113
+ # @return [String]
114
+ #
115
+ # @example
116
+ # Faker::Quote.mitch_hedberg # => "I like Kit-Kats, unless I'm with four or more people."
117
+ #
118
+ # @faker.version next
119
+ def mitch_hedberg
120
+ fetch('quote.mitch_hedberg')
121
+ end
109
122
  end
110
123
  end
111
124
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Sports
5
+ class Chess < Base
6
+ class << self
7
+ ##
8
+ # Produces the name of a chess player name.
9
+ #
10
+ # @return [String]
11
+ #
12
+ # @example
13
+ # Faker::Sports::Chess.player #=> "Golden State Warriors"
14
+ #
15
+ # @faker.version next
16
+ def player
17
+ fetch('chess.players')
18
+ end
19
+
20
+ ##
21
+ # Produces a long (alpha-3) ISO 3166 country code.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faker::Chess.federation #=> "COL"
27
+ #
28
+ # @faker.version next
29
+ def federation
30
+ Faker::Address.country_code_long
31
+ end
32
+
33
+ def tournament
34
+ ##
35
+ # Produces the name of a famous chess tournament name.
36
+ #
37
+ # @return [String]
38
+ #
39
+ # @example
40
+ # Faker::Chess.tournament #=> "Khanty-Mansisyk (Candidates Tournament)"
41
+ #
42
+ # @faker.version next
43
+ fetch('chess.tournaments')
44
+ end
45
+
46
+ def rating(from: 2000, to: 2900)
47
+ ##
48
+ # Produces a rating between two provided values. Boundaries are inclusive.
49
+ #
50
+ # @param from [Numeric] The lowest number to include.
51
+ # @param to [Numeric] The highest number to include.
52
+ # @return [Numeric]
53
+ #
54
+ # @example
55
+ # Faker::Sports::Chess.rating #=> 2734
56
+ # Faker::Sports::Chess.rating(from: 2400, to: 2700) #=> 2580
57
+ #
58
+ # @faker.version next
59
+ Faker::Base.rand_in_range(from, to)
60
+ end
61
+
62
+ ##
63
+ # Produces the name of a chess opening.
64
+ #
65
+ # @return [String]
66
+ #
67
+ # @example
68
+ # Faker::Sports::Chess.opening #=> "Giuoco Piano"
69
+ #
70
+ # @faker.version next
71
+ def opening
72
+ fetch('chess.openings')
73
+ end
74
+
75
+ ##
76
+ # Produces a chess title.
77
+ #
78
+ # @return [String]
79
+ #
80
+ # @example
81
+ # Faker::Sports::Chess.title #=> "GM"
82
+ #
83
+ # @faker.version next
84
+ def title
85
+ fetch('chess.titles')
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -11,7 +11,7 @@ module Faker
11
11
  #
12
12
  # @param region [String] airport region, currently available -> united_states or european_union
13
13
  #
14
- # @retrun [String]
14
+ # @return [String]
15
15
  #
16
16
  # @example
17
17
  # Faker::Travel::Airport.name(size: 'large', region: 'united_states') => "Los Angeles International Airport"
@@ -19,8 +19,6 @@ module Faker
19
19
  # @faker.version next
20
20
  def name(size:, region:)
21
21
  fetch("airport.#{region}.#{size}")
22
- rescue I18n::MissingTranslationData
23
- p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union'
24
22
  end
25
23
 
26
24
  ##
@@ -30,7 +28,7 @@ module Faker
30
28
  #
31
29
  # @param region [String] airport region, currently available -> united_states or european_union
32
30
  #
33
- # @retrun [String]
31
+ # @return [String]
34
32
  #
35
33
  # @example
36
34
  # Faker::Travel::Airport.iata(size: 'large', region: 'united_states') => "LAX"
@@ -38,8 +36,6 @@ module Faker
38
36
  # @faker.version next
39
37
  def iata(size:, region:)
40
38
  fetch("airport.#{region}.iata_code.#{size}")
41
- rescue I18n::MissingTranslationData
42
- p 'valid arguments are size && region -> US has size large medium small, EU has size large medium -- united_states || european_union'
43
39
  end
44
40
  end
45
41
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Travel
5
+ class TrainStation < Base
6
+ class << self
7
+ ##
8
+ # Produces random Train Station by name and takes optional arguments for region and type
9
+ #
10
+ # @param region [String] Train station region: germany, spain, united_kingdom, united_states
11
+ #
12
+ # @param type [String] Train station type: metro, railway
13
+ #
14
+ # @return [String]
15
+ #
16
+ # @examples
17
+ # Faker::Travel::TrainStation.name(region: 'united_kingdom', type: 'metro') => "Brockley"
18
+ # Faker::Travel::TrainStation.name(type: 'railway') => "Düsseldorf Hauptbahnhof"
19
+ # Faker::Travel::TrainStation.name(region: 'spain') => "Santa Eulàlia"
20
+ #
21
+ # @faker.version next
22
+ def name(region: nil, type: nil)
23
+ region, type = fill_missing_inputs_with_samples(region, type)
24
+ fetch("train_station.#{region}.#{type}")
25
+ end
26
+
27
+ private
28
+
29
+ def fill_missing_inputs_with_samples(region, type)
30
+ regions = %w[germany spain united_kingdom united_states]
31
+ types = %w[metro railway]
32
+
33
+ if region.nil? && type.nil?
34
+ region = sample(regions)
35
+ type = sample(types)
36
+ elsif region.nil?
37
+ validate_arguments(type, types, 'type')
38
+ region = sample(regions)
39
+ elsif type.nil?
40
+ validate_arguments(region, regions, 'region')
41
+ type = sample(types)
42
+ end
43
+ [region, type]
44
+ end
45
+
46
+ def validate_arguments(argument, correct_values, argument_name)
47
+ return if correct_values.include?(argument)
48
+
49
+ raise ArgumentError, "'#{argument}' not found, #{argument_name} can be blank, or one of the following, as strings: #{correct_values.join(', ')}"
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class TvShows
5
+ class Archer < Base
6
+ flexible :archer
7
+
8
+ class << self
9
+ ##
10
+ # Produces a character from Archer.
11
+ #
12
+ # @return [String]
13
+ #
14
+ # @example
15
+ # Faker::TvShows::Archer.character #=> "Sterling Archer"
16
+ #
17
+ # @faker.version next
18
+ def character
19
+ fetch('archer.characters')
20
+ end
21
+
22
+ ##
23
+ # Produces a location from Archer.
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faker::TvShows::Archer.location #=> "The Tuntmore Towers"
29
+ #
30
+ # @faker.version next
31
+ def location
32
+ fetch('archer.locations')
33
+ end
34
+
35
+ ##
36
+ # Produces a quote from Archer.
37
+ #
38
+ # @return [String]
39
+ #
40
+ # @example
41
+ # Faker::TvShows::Archer.quote
42
+ # #=> "You're not my supervisor!"
43
+ #
44
+ # @faker.version next
45
+ def quote
46
+ fetch('archer.quotes')
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -32,6 +32,21 @@ module Faker
32
32
  def quote
33
33
  fetch('south_park.quotes')
34
34
  end
35
+
36
+ ##
37
+ # Produces an episode name from South Park.
38
+ #
39
+ # @return [String]
40
+ #
41
+ # @example
42
+ # Faker::TvShows::SouthPark.episode_name
43
+ # #=> "Make Love, Not Warcraft"
44
+ #
45
+ # @faker.version next
46
+
47
+ def episode_name
48
+ fetch('south_park.episodes')
49
+ end
35
50
  end
36
51
  end
37
52
  end
data/lib/faker/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker # :nodoc:
4
- VERSION = '3.1.1'
4
+ VERSION = '3.2.1'
5
5
  end
data/lib/faker.rb CHANGED
@@ -8,18 +8,21 @@ require 'i18n'
8
8
  Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }
9
9
 
10
10
  I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
11
- I18n.reload! if I18n.backend.initialized?
12
11
 
13
12
  module Faker
14
13
  module Config
14
+ @default_locale = nil
15
+
15
16
  class << self
17
+ attr_writer :default_locale
18
+
16
19
  def locale=(new_locale)
17
20
  Thread.current[:faker_config_locale] = new_locale
18
21
  end
19
22
 
20
23
  def locale
21
24
  # Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen
22
- Thread.current[:faker_config_locale] || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
25
+ Thread.current[:faker_config_locale] || @default_locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
23
26
  end
24
27
 
25
28
  def own_locale
@@ -49,19 +52,23 @@ module Faker
49
52
 
50
53
  ## by default numerify results do not start with a zero
51
54
  def numerify(number_string, leading_zero: false)
52
- return number_string.gsub(/#/) { rand(10).to_s } if leading_zero
55
+ return number_string.gsub('#') { rand(10).to_s } if leading_zero
53
56
 
54
- number_string.sub(/#/) { rand(1..9).to_s }.gsub(/#/) { rand(10).to_s }
57
+ number_string.sub('#') { rand(1..9).to_s }.gsub('#') { rand(10).to_s }
55
58
  end
56
59
 
57
60
  def letterify(letter_string)
58
- letter_string.gsub(/\?/) { sample(ULetters) }
61
+ letter_string.gsub('?') { sample(ULetters) }
59
62
  end
60
63
 
61
64
  def bothify(string)
62
65
  letterify(numerify(string))
63
66
  end
64
67
 
68
+ def generate(as_type, &block)
69
+ PositionalGenerator.new(as_type, &block).generate
70
+ end
71
+
65
72
  # Given a regular expression, attempt to generate a string
66
73
  # that would match it. This is a rather simple implementation,
67
74
  # so don't be shocked if it blows up on you in a spectacular fashion.
@@ -85,7 +92,7 @@ module Faker
85
92
  reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp
86
93
  reg
87
94
  .gsub(%r{^/?\^?}, '').gsub(%r{\$?/?$}, '') # Ditch the anchors
88
- .gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}') # All {2} become {2,2} and ? become {0,1}
95
+ .gsub(/\{(\d+)\}/, '{\1,\1}').gsub('?', '{0,1}') # All {2} become {2,2} and ? become {0,1}
89
96
  .gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12]
90
97
  .gsub(/(\([^)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
91
98
  .gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d