faker 3.1.0 → 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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -5
  3. data/README.md +16 -4
  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 +23 -15
  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 -9
  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 +43 -0
  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/airport.yml +381 -0
  40. data/lib/locales/en/archer.yml +75 -0
  41. data/lib/locales/en/avatar.yml +31 -0
  42. data/lib/locales/en/chess.yml +103 -0
  43. data/lib/locales/en/company.yml +1 -0
  44. data/lib/locales/en/dnd.yml +186 -1
  45. data/lib/locales/en/final_fantasy_xiv.yml +754 -0
  46. data/lib/locales/en/food.yml +12 -0
  47. data/lib/locales/en/internet.yml +3 -0
  48. data/lib/locales/en/minecraft.yml +4 -4
  49. data/lib/locales/en/mitch_hedberg.yml +46 -0
  50. data/lib/locales/en/opera.yml +1 -1
  51. data/lib/locales/en/south_park.yml +360 -2
  52. data/lib/locales/en/star_wars.yml +1 -1
  53. data/lib/locales/en/train_station.yml +280 -0
  54. data/lib/locales/en-AU.yml +1 -0
  55. data/lib/locales/en-CA.yml +1 -0
  56. data/lib/locales/en-GB.yml +2 -0
  57. data/lib/locales/en-MS.yml +1 -0
  58. data/lib/locales/en-NG.yml +1 -0
  59. data/lib/locales/en-NZ.yml +1 -0
  60. data/lib/locales/en-PAK.yml +1 -0
  61. data/lib/locales/en-SG.yml +1 -0
  62. data/lib/locales/en-UG.yml +1 -0
  63. data/lib/locales/en-US.yml +1 -0
  64. data/lib/locales/en-ZA.yml +1 -0
  65. data/lib/locales/en-au-ocker.yml +2 -0
  66. data/lib/locales/es-AR.yml +1 -0
  67. data/lib/locales/es-MX.yml +1 -0
  68. data/lib/locales/es.yml +2 -1
  69. data/lib/locales/fi-FI.yml +1 -0
  70. data/lib/locales/fr/name.yml +2 -1
  71. data/lib/locales/fr-CA.yml +1 -0
  72. data/lib/locales/fr-CH.yml +1 -0
  73. data/lib/locales/hy.yml +1 -0
  74. data/lib/locales/it.yml +1 -0
  75. data/lib/locales/ja/sport.yml +130 -0
  76. data/lib/locales/ko.yml +1 -0
  77. data/lib/locales/mi-NZ.yml +2 -0
  78. data/lib/locales/nb-NO.yml +1 -0
  79. data/lib/locales/nl.yml +1 -0
  80. data/lib/locales/pl.yml +1 -0
  81. data/lib/locales/pt-BR.yml +1 -0
  82. data/lib/locales/pt.yml +1 -0
  83. data/lib/locales/ru.yml +1 -0
  84. data/lib/locales/sk.yml +1 -0
  85. data/lib/locales/sv.yml +1 -0
  86. data/lib/locales/tr.yml +1 -0
  87. data/lib/locales/uk.yml +4 -1
  88. data/lib/locales/vi.yml +1 -0
  89. data/lib/locales/zh-CN.yml +1 -0
  90. data/lib/locales/zh-TW.yml +1 -0
  91. metadata +23 -147
  92. data/lib/faker/default/fillmurray.rb +0 -36
@@ -97,12 +97,13 @@ module Faker
97
97
  # @example
98
98
  # Faker::Types.rb_array #=> ["a"]
99
99
  # Faker::Types.rb_array(len: 4) #=> ["a", 1, 2, "bob"]
100
+ # Faker::Types.rb_array(len: 2, type: -> { Faker::Types.rb_string }) #=> ["cat", "foo"]
100
101
  #
101
102
  # @faker.version 1.8.6
102
- def rb_array(len: 1)
103
+ def rb_array(len: 1, type: -> { random_type })
103
104
  [].tap do |ar|
104
105
  len.times do
105
- ar.push random_type
106
+ ar.push type.is_a?(Proc) ? type.call : type
106
107
  end
107
108
  end
108
109
  end
@@ -9,7 +9,6 @@ module Faker
9
9
  VIN_KEYSPACE = %w[A B C D E F G H J K L M N P R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9].freeze
10
10
  VIN_TRANSLITERATION = { A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8, J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9, S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9 }.freeze
11
11
  VIN_WEIGHT = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2].freeze
12
- VIN_REGEX = /\A[A-HJ-NPR-Z0-9]{17}\z/.freeze
13
12
  SG_CHECKSUM_WEIGHTS = [3, 14, 2, 12, 2, 11, 1].freeze
14
13
  SG_CHECKSUM_CHARS = 'AYUSPLJGDBZXTRMKHEC'
15
14
 
@@ -23,14 +22,25 @@ module Faker
23
22
  #
24
23
  # @faker.version 1.6.4
25
24
  def vin
26
- front = 8.times.map { VIN_KEYSPACE.sample(random: Faker::Config.random) }.join
27
- back = 8.times.map { VIN_KEYSPACE.sample(random: Faker::Config.random) }.join
28
- checksum = "#{front}A#{back}".chars.each_with_index.map do |char, i|
29
- value = (char =~ /\A\d\z/ ? char.to_i : VIN_TRANSLITERATION[char.to_sym])
30
- value * VIN_WEIGHT[i]
31
- end.inject(:+) % 11
32
- checksum = 'X' if checksum == 10
33
- "#{front}#{checksum}#{back}"
25
+ generate(:string) do |g|
26
+ g.letter(name: :wmi, ranges: ['100'..'199', '400'..'499', '500'..'599', '700'..'799', '7A0'..'7F9'])
27
+ g.letter(name: :vds, length: 5, ranges: [VIN_KEYSPACE])
28
+ g.computed(name: :checksum, deps: %i[wmi vds model_year plant_code vis]) do |wmi, vds, model_year, plant_code, vis|
29
+ checksum = "#{wmi}#{vds}0#{model_year}#{plant_code}#{vis}".chars.each_with_index.map do |char, i|
30
+ value = (char =~ /\A\d\z/ ? char.to_i : VIN_TRANSLITERATION[char.to_sym])
31
+ value * VIN_WEIGHT[i]
32
+ end.inject(:+) % 11
33
+
34
+ if checksum == 10
35
+ 'X'
36
+ else
37
+ checksum
38
+ end
39
+ end
40
+ g.letter(name: :model_year, length: 1, ranges: [VIN_KEYSPACE - %w[U Z 0]])
41
+ g.letter(name: :plant_code, length: 1, ranges: [VIN_KEYSPACE])
42
+ g.int(name: :vis, length: 6)
43
+ end
34
44
  end
35
45
 
36
46
  # Produces a random vehicle manufacturer.
@@ -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
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Travel
5
+ class Airport < Base
6
+ class << self
7
+ ##
8
+ # Produces random Airport by name and takes arguments for size and region
9
+ #
10
+ # @param size [String] airport size, united_states has large, or medium, or small, european_union has large, or medium
11
+ #
12
+ # @param region [String] airport region, currently available -> united_states or european_union
13
+ #
14
+ # @return [String]
15
+ #
16
+ # @example
17
+ # Faker::Travel::Airport.name(size: 'large', region: 'united_states') => "Los Angeles International Airport"
18
+ #
19
+ # @faker.version next
20
+ def name(size:, region:)
21
+ fetch("airport.#{region}.#{size}")
22
+ end
23
+
24
+ ##
25
+ # Produces random Airport by IATA code and takes arguments for size and region
26
+ #
27
+ # @param size [String] airport size, united_states has large, or medium, or small, european_union has large, or medium
28
+ #
29
+ # @param region [String] airport region, currently available -> united_states or european_union
30
+ #
31
+ # @return [String]
32
+ #
33
+ # @example
34
+ # Faker::Travel::Airport.iata(size: 'large', region: 'united_states') => "LAX"
35
+ #
36
+ # @faker.version next
37
+ def iata(size:, region:)
38
+ fetch("airport.#{region}.iata_code.#{size}")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ 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.0'
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