faker 2.10.2 → 2.15.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 +323 -0
- data/README.md +27 -2
- data/lib/faker.rb +57 -25
- data/lib/faker/blockchain/aeternity.rb +4 -4
- data/lib/faker/books/dune.rb +15 -2
- data/lib/faker/books/lovecraft.rb +8 -4
- data/lib/faker/default/address.rb +35 -5
- data/lib/faker/default/bank.rb +80 -3
- data/lib/faker/default/barcode.rb +154 -0
- data/lib/faker/default/beer.rb +3 -3
- data/lib/faker/default/blood.rb +48 -0
- data/lib/faker/default/business.rb +1 -1
- data/lib/faker/default/camera.rb +46 -0
- data/lib/faker/default/cannabis.rb +80 -0
- data/lib/faker/default/chile_rut.rb +47 -3
- data/lib/faker/default/code.rb +98 -17
- data/lib/faker/default/commerce.rb +74 -11
- data/lib/faker/default/company.rb +78 -11
- data/lib/faker/default/compass.rb +135 -0
- data/lib/faker/default/computer.rb +63 -0
- data/lib/faker/default/construction.rb +54 -0
- data/lib/faker/default/cosmere.rb +90 -0
- data/lib/faker/default/crypto_coin.rb +45 -0
- data/lib/faker/default/date.rb +16 -12
- data/lib/faker/default/driving_licence.rb +65 -0
- data/lib/faker/default/drone.rb +332 -0
- data/lib/faker/default/faker_adjective.rb +35 -0
- data/lib/faker/default/file.rb +49 -0
- data/lib/faker/default/finance.rb +45 -0
- data/lib/faker/default/food.rb +1 -1
- data/lib/faker/default/funny_name.rb +45 -0
- data/lib/faker/default/gender.rb +1 -1
- data/lib/faker/default/hipster.rb +101 -4
- data/lib/faker/default/id_number.rb +88 -2
- data/lib/faker/default/internet.rb +68 -10
- data/lib/faker/default/internet_http.rb +48 -0
- data/lib/faker/default/invoice.rb +33 -6
- data/lib/faker/default/json.rb +59 -4
- data/lib/faker/default/lorem.rb +2 -2
- data/lib/faker/default/lorem_flickr.rb +65 -0
- data/lib/faker/default/lorem_pixel.rb +22 -0
- data/lib/faker/default/markdown.rb +89 -0
- data/lib/faker/default/measurement.rb +93 -2
- data/lib/faker/default/military.rb +26 -0
- data/lib/faker/default/mountain.rb +33 -0
- data/lib/faker/default/name.rb +98 -0
- data/lib/faker/default/nhs.rb +19 -0
- data/lib/faker/default/number.rb +6 -8
- data/lib/faker/default/omniauth.rb +107 -52
- data/lib/faker/default/phone_number.rb +88 -5
- data/lib/faker/default/placeholdit.rb +21 -0
- data/lib/faker/default/relationship.rb +1 -1
- data/lib/faker/default/slack_emoji.rb +81 -0
- data/lib/faker/default/south_africa.rb +90 -0
- data/lib/faker/default/space.rb +1 -1
- data/lib/faker/default/string.rb +19 -3
- data/lib/faker/default/stripe.rb +64 -3
- data/lib/faker/default/twitter.rb +35 -0
- data/lib/faker/default/types.rb +80 -0
- data/lib/faker/default/university.rb +45 -0
- data/lib/faker/default/vehicle.rb +184 -4
- data/lib/faker/default/verb.rb +45 -0
- data/lib/faker/default/world_cup.rb +4 -4
- data/lib/faker/fantasy/tolkien.rb +67 -0
- data/lib/faker/games/clash_of_clans.rb +48 -0
- data/lib/faker/games/control.rb +113 -0
- data/lib/faker/games/dnd.rb +136 -0
- data/lib/faker/games/elder_scrolls.rb +26 -0
- data/lib/faker/games/heroes.rb +13 -0
- data/lib/faker/games/heroes_of_the_storm.rb +16 -5
- data/lib/faker/games/minecraft.rb +113 -0
- data/lib/faker/games/street_fighter.rb +61 -0
- data/lib/faker/games/super_mario.rb +48 -0
- data/lib/faker/games/warhammer_fantasy.rb +74 -0
- data/lib/faker/games/world_of_warcraft.rb +26 -1
- data/lib/faker/japanese_media/conan.rb +48 -0
- data/lib/faker/japanese_media/doraemon.rb +48 -0
- data/lib/faker/japanese_media/dragon_ball.rb +26 -0
- data/lib/faker/japanese_media/naruto.rb +61 -0
- data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
- data/lib/faker/movies/departed.rb +49 -0
- data/lib/faker/movies/hobbit.rb +4 -4
- data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
- data/lib/faker/movies/lord_of_the_rings.rb +3 -3
- data/lib/faker/movies/movie.rb +13 -0
- data/lib/faker/movies/room.rb +63 -0
- data/lib/faker/movies/star_wars.rb +2 -2
- data/lib/faker/music/hiphop.rb +48 -0
- data/lib/faker/music/opera.rb +237 -1
- data/lib/faker/music/pearl_jam.rb +50 -0
- data/lib/faker/music/phish.rb +27 -1
- data/lib/faker/music/prince.rb +64 -0
- data/lib/faker/music/rush.rb +37 -0
- data/lib/faker/music/show.rb +49 -0
- data/lib/faker/quotes/chiquito.rb +80 -0
- data/lib/faker/quotes/quote.rb +80 -1
- data/lib/faker/quotes/rajnikanth.rb +26 -0
- data/lib/faker/quotes/shakespeare.rb +36 -0
- data/lib/faker/sports/volleyball.rb +74 -0
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
- data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
- data/lib/faker/tv_shows/buffy.rb +17 -4
- data/lib/faker/tv_shows/dr_who.rb +1 -1
- data/lib/faker/tv_shows/final_space.rb +51 -0
- data/lib/faker/tv_shows/futurama.rb +65 -0
- data/lib/faker/tv_shows/simpsons.rb +14 -0
- data/lib/faker/tv_shows/suits.rb +37 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
- data/lib/faker/version.rb +1 -1
- data/lib/helpers/base58.rb +1 -1
- data/lib/helpers/char.rb +22 -27
- data/lib/helpers/unique_generator.rb +3 -2
- data/lib/locales/de-AT.yml +4 -2
- data/lib/locales/de-CH.yml +1696 -1
- data/lib/locales/de.yml +4 -2
- data/lib/locales/en-AU.yml +50 -10
- data/lib/locales/en-CA.yml +2 -0
- data/lib/locales/en-GB.yml +1 -1
- data/lib/locales/en-IND.yml +2 -1
- data/lib/locales/en-MS.yml +2 -1
- data/lib/locales/en-NEP.yml +4 -1
- data/lib/locales/en-NZ.yml +3 -1
- data/lib/locales/en-PAK.yml +2 -1
- data/lib/locales/en-SG.yml +2 -1
- data/lib/locales/en-US.yml +36 -10
- data/lib/locales/en-au-ocker.yml +2 -1
- data/lib/locales/en.yml +0 -3
- data/lib/locales/en/address.yml +2 -0
- data/lib/locales/en/adjective.yml +179 -0
- data/lib/locales/en/animal.yml +1 -1
- data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/barcode.yml +24 -0
- data/lib/locales/en/big_bang_theory.yml +38 -0
- data/lib/locales/en/blood.yml +13 -0
- data/lib/locales/en/buffy.yml +1 -1
- data/lib/locales/en/camera.yml +611 -0
- data/lib/locales/en/chiquito.yml +64 -0
- data/lib/locales/en/clash_of_clan.yml +101 -0
- data/lib/locales/en/company.yml +2 -2
- data/lib/locales/en/computer.yml +36 -0
- data/lib/locales/en/conan.yml +171 -0
- data/lib/locales/en/control.yml +247 -0
- data/lib/locales/en/demographic.yml +218 -5
- data/lib/locales/en/departed.yml +50 -0
- data/lib/locales/en/dnd.yml +451 -0
- data/lib/locales/en/doraemon.yml +286 -0
- data/lib/locales/en/dota.yml +531 -63
- data/lib/locales/en/dragon_ball.yml +243 -1
- data/lib/locales/en/driving_license.yml +181 -0
- data/lib/locales/en/drone.yml +95 -0
- data/lib/locales/en/dune.yml +401 -131
- data/lib/locales/en/elder_scrolls.yml +583 -9
- data/lib/locales/en/fallout.yml +311 -133
- data/lib/locales/en/final_space.yml +37 -0
- data/lib/locales/en/finance.yml +53 -0
- data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
- data/lib/locales/en/futurama.yml +344 -0
- data/lib/locales/en/half_life.yml +84 -3
- data/lib/locales/en/heroes.yml +408 -3
- data/lib/locales/en/heroes_of_the_storm.yml +131 -4
- data/lib/locales/en/house.yml +1 -1
- data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
- data/lib/locales/en/jack_handey.yml +54 -0
- data/lib/locales/en/league_of_legends.yml +285 -6
- data/lib/locales/en/military.yml +179 -5
- data/lib/locales/en/minecraft.yml +663 -0
- data/lib/locales/en/mountain.yml +158 -0
- data/lib/locales/en/movie.yml +192 -1
- data/lib/locales/en/music.yml +451 -29
- data/lib/locales/en/myst.yml +87 -31
- data/lib/locales/en/name.yml +6 -5
- data/lib/locales/en/naruto.yml +231 -0
- data/lib/locales/en/one_piece.yml +2 -2
- data/lib/locales/en/opera.yml +168 -0
- data/lib/locales/en/overwatch.yml +2650 -2622
- data/lib/locales/en/pearl_jam.yml +213 -0
- data/lib/locales/en/phish.yml +392 -1
- data/lib/locales/en/pokemon.yml +417 -4
- data/lib/locales/en/prince.yml +227 -0
- data/lib/locales/en/quote.yml +692 -163
- data/lib/locales/en/rajnikanth.yml +77 -0
- data/lib/locales/en/room.yml +68 -0
- data/lib/locales/en/rush.yml +32 -0
- data/lib/locales/en/show.yml +597 -0
- data/lib/locales/en/simpsons.yml +668 -0
- data/lib/locales/en/source.yml +30 -0
- data/lib/locales/en/star_trek.yml +1 -1
- data/lib/locales/en/star_wars.yml +568 -220
- data/lib/locales/en/street_fighter.yml +1524 -0
- data/lib/locales/en/studio_ghibli.yml +107 -0
- data/lib/locales/en/suits.yml +45 -0
- data/lib/locales/en/super_mario.yml +58 -0
- data/lib/locales/en/super_smash_bros.yml +16 -4
- data/lib/locales/en/tolkien.yml +2453 -0
- data/lib/locales/en/volleyball.yml +501 -0
- data/lib/locales/en/warhammer_fantasy.yml +582 -0
- data/lib/locales/en/witcher.yml +389 -7
- data/lib/locales/en/world_of_warcraft.yml +122 -4
- data/lib/locales/en/zelda.yml +962 -4
- data/lib/locales/es.yml +56 -0
- data/lib/locales/fi-FI.yml +1 -1
- data/lib/locales/fr-CA.yml +21 -5
- data/lib/locales/fr-CH.yml +2 -2
- data/lib/locales/fr.yml +8 -2
- data/lib/locales/id.yml +2 -1
- data/lib/locales/it.yml +2 -1
- data/lib/locales/ja.yml +5 -1
- data/lib/locales/ko.yml +94 -2
- data/lib/locales/nb-NO.yml +4 -2
- data/lib/locales/pt-BR.yml +2 -1
- data/lib/locales/pt.yml +3 -1
- data/lib/locales/ru.yml +3 -1
- data/lib/locales/sk.yml +4 -2
- data/lib/locales/uk.yml +2 -0
- metadata +89 -21
- data/lib/locales/en/hobbit.yml +0 -19
- data/lib/locales/en/lord_of_the_rings.yml +0 -6
data/lib/faker.rb
CHANGED
@@ -2,29 +2,45 @@
|
|
2
2
|
|
3
3
|
mydir = __dir__
|
4
4
|
|
5
|
-
|
6
|
-
require 'psych'
|
7
|
-
end
|
8
|
-
|
5
|
+
require 'psych'
|
9
6
|
require 'i18n'
|
10
7
|
require 'set' # Fixes a bug in i18n 0.6.11
|
11
8
|
|
12
|
-
Dir.glob(File.join(
|
13
|
-
|
14
|
-
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
|
15
|
-
I18n.reload! if I18n.backend.initialized?
|
9
|
+
Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }
|
16
10
|
|
17
11
|
module Faker
|
18
|
-
|
12
|
+
@i18n_loaded = nil
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def load_i18n
|
16
|
+
return if @i18n_loaded
|
17
|
+
|
18
|
+
if I18n.available_locales&.any?
|
19
|
+
# We expect all locale .yml files to have the locale name in its filename
|
20
|
+
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}.yml")]
|
21
|
+
# Or to be located in a directory with the locale name
|
22
|
+
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', "{#{I18n.available_locales.join(',')}}/*.yml")]
|
23
|
+
else
|
24
|
+
I18n.load_path += ::Dir[::File.join(__dir__, 'locales', '**/*.yml')]
|
25
|
+
end
|
26
|
+
|
27
|
+
I18n.reload! if I18n.backend.initialized?
|
28
|
+
@i18n_loaded = true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Config
|
19
33
|
@locale = nil
|
20
34
|
@random = nil
|
21
35
|
|
22
36
|
class << self
|
23
|
-
attr_writer :locale
|
24
|
-
attr_writer :random
|
37
|
+
attr_writer :locale, :random
|
25
38
|
|
26
39
|
def locale
|
27
|
-
|
40
|
+
Faker.load_i18n
|
41
|
+
|
42
|
+
# Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen
|
43
|
+
@locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
|
28
44
|
end
|
29
45
|
|
30
46
|
def own_locale
|
@@ -83,13 +99,13 @@ module Faker
|
|
83
99
|
def regexify(reg)
|
84
100
|
reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp
|
85
101
|
reg
|
86
|
-
.gsub(%r{
|
102
|
+
.gsub(%r{^/?\^?}, '').gsub(%r{\$?/?$}, '') # Ditch the anchors
|
87
103
|
.gsub(/\{(\d+)\}/, '{\1,\1}').gsub(/\?/, '{0,1}') # All {2} become {2,2} and ? become {0,1}
|
88
104
|
.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]
|
89
|
-
.gsub(/(\([
|
105
|
+
.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)
|
90
106
|
.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
|
91
|
-
.gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[
|
92
|
-
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w
|
107
|
+
.gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[()]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
|
108
|
+
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
|
93
109
|
.gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).split('')) } # All [ABC] become B (or A or C)
|
94
110
|
.gsub('\d') { |_match| sample(Numbers) }
|
95
111
|
.gsub('\w') { |_match| sample(Letters) }
|
@@ -99,7 +115,7 @@ module Faker
|
|
99
115
|
# with an array of values and selecting one of them.
|
100
116
|
def fetch(key)
|
101
117
|
fetched = sample(translate("faker.#{key}"))
|
102
|
-
if fetched&.match(%r{
|
118
|
+
if fetched&.match(%r{^/}) && fetched&.match(%r{/$}) # A regex
|
103
119
|
regexify(fetched)
|
104
120
|
else
|
105
121
|
fetched
|
@@ -111,7 +127,7 @@ module Faker
|
|
111
127
|
def fetch_all(key)
|
112
128
|
fetched = translate("faker.#{key}")
|
113
129
|
fetched = fetched.last if fetched.size <= 1
|
114
|
-
if !fetched.respond_to?(:sample) && fetched.match(%r{
|
130
|
+
if !fetched.respond_to?(:sample) && fetched.match(%r{^/}) && fetched.match(%r{/$}) # A regex
|
115
131
|
regexify(fetched)
|
116
132
|
else
|
117
133
|
fetched
|
@@ -123,7 +139,7 @@ module Faker
|
|
123
139
|
# formatted translation: e.g., "#{first_name} #{last_name}".
|
124
140
|
def parse(key)
|
125
141
|
fetched = fetch(key)
|
126
|
-
parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([
|
142
|
+
parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc|
|
127
143
|
# If the token had a class Prefix (e.g., Name.first_name)
|
128
144
|
# grab the constant, otherwise use self
|
129
145
|
cls = kls ? Faker.const_get(kls.chop) : self
|
@@ -132,7 +148,7 @@ module Faker
|
|
132
148
|
# In either case the information will be retained for reconstruction of the string.
|
133
149
|
text = prefix
|
134
150
|
|
135
|
-
# If the class has the method, call it, otherwise fetch the
|
151
|
+
# If the class has the method, call it, otherwise fetch the translation
|
136
152
|
# (e.g., faker.phone_number.area_code)
|
137
153
|
text += if cls.respond_to?(meth)
|
138
154
|
cls.send(meth)
|
@@ -152,6 +168,8 @@ module Faker
|
|
152
168
|
# Call I18n.translate with our configured locale if no
|
153
169
|
# locale is specified
|
154
170
|
def translate(*args, **opts)
|
171
|
+
Faker.load_i18n
|
172
|
+
|
155
173
|
opts[:locale] ||= Faker::Config.locale
|
156
174
|
opts[:raise] = true
|
157
175
|
I18n.translate(*args, **opts)
|
@@ -167,12 +185,14 @@ module Faker
|
|
167
185
|
end
|
168
186
|
|
169
187
|
# Executes block with given locale set.
|
170
|
-
def with_locale(tmp_locale = nil)
|
188
|
+
def with_locale(tmp_locale = nil, &block)
|
189
|
+
Faker.load_i18n
|
190
|
+
|
171
191
|
current_locale = Faker::Config.own_locale
|
172
192
|
Faker::Config.locale = tmp_locale
|
173
193
|
|
174
194
|
disable_enforce_available_locales do
|
175
|
-
I18n.with_locale(tmp_locale)
|
195
|
+
I18n.with_locale(tmp_locale, &block)
|
176
196
|
end
|
177
197
|
ensure
|
178
198
|
Faker::Config.locale = current_locale
|
@@ -217,12 +237,24 @@ module Faker
|
|
217
237
|
end
|
218
238
|
end
|
219
239
|
|
240
|
+
# Return unique values from the generator every time.
|
241
|
+
#
|
242
|
+
# @param max_retries [Integer] The max number of retries that should be done before giving up.
|
243
|
+
# @return [self]
|
220
244
|
def unique(max_retries = 10_000)
|
221
245
|
@unique ||= UniqueGenerator.new(self, max_retries)
|
222
246
|
end
|
223
247
|
|
224
|
-
def sample(list)
|
225
|
-
list.respond_to?(:sample)
|
248
|
+
def sample(list, num = nil)
|
249
|
+
if list.respond_to?(:sample)
|
250
|
+
if num
|
251
|
+
list.sample(num, random: Faker::Config.random)
|
252
|
+
else
|
253
|
+
list.sample(random: Faker::Config.random)
|
254
|
+
end
|
255
|
+
else
|
256
|
+
list
|
257
|
+
end
|
226
258
|
end
|
227
259
|
|
228
260
|
def shuffle(list)
|
@@ -303,4 +335,4 @@ module Faker
|
|
303
335
|
end
|
304
336
|
|
305
337
|
# require faker objects
|
306
|
-
Dir.glob(File.join(
|
338
|
+
Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).sort.each { |file| require file }
|
@@ -14,7 +14,7 @@ module Faker
|
|
14
14
|
# #=> "ak_zvU8YQLagjcfng7Tg8yCdiZ1rpiWNp1PBn3vtUs44utSvbJVR"
|
15
15
|
#
|
16
16
|
def address
|
17
|
-
|
17
|
+
"ak_#{rand_strings}"
|
18
18
|
end
|
19
19
|
|
20
20
|
##
|
@@ -27,7 +27,7 @@ module Faker
|
|
27
27
|
# #=> "th_147nDP22h3pHrLt2qykTH4txUwQh1ccaXp"
|
28
28
|
#
|
29
29
|
def transaction
|
30
|
-
|
30
|
+
"th_#{rand_strings(51)}"
|
31
31
|
end
|
32
32
|
|
33
33
|
##
|
@@ -40,7 +40,7 @@ module Faker
|
|
40
40
|
# #=> "ct_Hk2JsNeWGEYQEHHQCfcBeGrwbhtYSwFTPdDhW2SvjFYVojyhW"
|
41
41
|
#
|
42
42
|
def contract
|
43
|
-
|
43
|
+
"ct_#{rand_strings}"
|
44
44
|
end
|
45
45
|
|
46
46
|
##
|
@@ -53,7 +53,7 @@ module Faker
|
|
53
53
|
# #=> "ok_28QDg7fkF5qiKueSdUvUBtCYPJdmMEoS73CztzXCRAwMGKHKZh"
|
54
54
|
#
|
55
55
|
def oracle
|
56
|
-
|
56
|
+
"ok_#{rand_strings(51)}"
|
57
57
|
end
|
58
58
|
|
59
59
|
protected
|
data/lib/faker/books/dune.rb
CHANGED
@@ -30,6 +30,19 @@ module Faker
|
|
30
30
|
fetch('dune.titles')
|
31
31
|
end
|
32
32
|
|
33
|
+
##
|
34
|
+
# Produces the name of a city from Dune
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# Faker::Books::Dune.city #=> "Arrakeen"
|
40
|
+
#
|
41
|
+
# @faker.version next
|
42
|
+
def city
|
43
|
+
fetch('dune.cities')
|
44
|
+
end
|
45
|
+
|
33
46
|
##
|
34
47
|
# Produces the name of a planet from Dune
|
35
48
|
#
|
@@ -76,7 +89,7 @@ module Faker
|
|
76
89
|
end
|
77
90
|
end
|
78
91
|
|
79
|
-
fetch(
|
92
|
+
fetch("dune.quotes.#{character}")
|
80
93
|
end
|
81
94
|
|
82
95
|
##
|
@@ -111,7 +124,7 @@ module Faker
|
|
111
124
|
end
|
112
125
|
end
|
113
126
|
|
114
|
-
fetch(
|
127
|
+
fetch("dune.sayings.#{source}")
|
115
128
|
end
|
116
129
|
end
|
117
130
|
end
|
@@ -68,6 +68,7 @@ module Faker
|
|
68
68
|
#
|
69
69
|
# @param word_count [Integer] The number of words to have in the sentence
|
70
70
|
# @param random_words_to_add [Integer]
|
71
|
+
# @param open_compounds_allowed [Boolean] If true, generated sentence can contain words having additional spaces
|
71
72
|
#
|
72
73
|
# @return [String]
|
73
74
|
#
|
@@ -80,15 +81,18 @@ module Faker
|
|
80
81
|
# @example
|
81
82
|
# Faker::Books::Lovecraft.sentence(word_count: 3, random_words_to_add: 1)
|
82
83
|
# #=> "Amorphous indescribable tenebrous."
|
84
|
+
# @example
|
85
|
+
# Faker::Books::Lovecraft.sentence(word_count: 3, random_words_to_add: 0, open_compounds_allowed: true)
|
86
|
+
# #=> "Effulgence unmentionable gambrel."
|
83
87
|
#
|
84
88
|
# @faker.version 1.9.3
|
85
|
-
def sentence(legacy_word_count = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, random_words_to_add: 6)
|
89
|
+
def sentence(legacy_word_count = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, random_words_to_add: 6, open_compounds_allowed: true)
|
86
90
|
warn_for_deprecated_arguments do |keywords|
|
87
91
|
keywords << :word_count if legacy_word_count != NOT_GIVEN
|
88
92
|
keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN
|
89
93
|
end
|
90
94
|
|
91
|
-
words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed:
|
95
|
+
"#{words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: open_compounds_allowed).join(' ').capitalize}."
|
92
96
|
end
|
93
97
|
|
94
98
|
##
|
@@ -266,9 +270,9 @@ module Faker
|
|
266
270
|
|
267
271
|
paragraph = paragraph(sentence_count: 3)
|
268
272
|
|
269
|
-
paragraph +=
|
273
|
+
paragraph += " #{paragraph(sentence_count: 3)}" while paragraph.length < characters
|
270
274
|
|
271
|
-
paragraph[0...characters - 1]
|
275
|
+
"#{paragraph[0...characters - 1]}."
|
272
276
|
end
|
273
277
|
end
|
274
278
|
end
|
@@ -54,7 +54,7 @@ module Faker
|
|
54
54
|
keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN
|
55
55
|
end
|
56
56
|
|
57
|
-
numerify(parse('address.street_address') + (include_secondary ?
|
57
|
+
numerify(parse('address.street_address') + (include_secondary ? " #{secondary_address}" : ''))
|
58
58
|
end
|
59
59
|
|
60
60
|
##
|
@@ -102,7 +102,7 @@ module Faker
|
|
102
102
|
# @return [String]
|
103
103
|
#
|
104
104
|
# @example
|
105
|
-
#
|
105
|
+
# Faker::Address.mail_box #=> "PO Box 123"
|
106
106
|
#
|
107
107
|
# @faker.version 2.9.1
|
108
108
|
def mail_box
|
@@ -133,7 +133,7 @@ module Faker
|
|
133
133
|
|
134
134
|
# provide a zip code that is valid for the state provided
|
135
135
|
# see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf
|
136
|
-
bothify(fetch(
|
136
|
+
bothify(fetch("address.postcode_by_state.#{state_abbreviation}"))
|
137
137
|
end
|
138
138
|
|
139
139
|
##
|
@@ -247,7 +247,7 @@ module Faker
|
|
247
247
|
keywords << :code if legacy_code != NOT_GIVEN
|
248
248
|
end
|
249
249
|
|
250
|
-
fetch(
|
250
|
+
fetch("address.country_by_code.#{code}")
|
251
251
|
end
|
252
252
|
|
253
253
|
##
|
@@ -265,7 +265,7 @@ module Faker
|
|
265
265
|
keywords << :name if legacy_name != NOT_GIVEN
|
266
266
|
end
|
267
267
|
|
268
|
-
fetch(
|
268
|
+
fetch("address.country_by_name.#{name}")
|
269
269
|
end
|
270
270
|
|
271
271
|
##
|
@@ -333,6 +333,36 @@ module Faker
|
|
333
333
|
def full_address
|
334
334
|
parse('address.full_address')
|
335
335
|
end
|
336
|
+
|
337
|
+
##
|
338
|
+
# Produces Address hash of required fields
|
339
|
+
#
|
340
|
+
# @return [Hash]
|
341
|
+
#
|
342
|
+
# @example
|
343
|
+
# Faker::Address.full_address_as_hash(:longitude,
|
344
|
+
# :latitude,
|
345
|
+
# :country_name_to_code,
|
346
|
+
# country_name_to_code: {name: 'united_states'})
|
347
|
+
# #=> {:longitude=>-101.74428917174603, :latitude=>-37.40056749089944, :country_name_to_code=>"US"}
|
348
|
+
#
|
349
|
+
# Faker::Address.full_address_as_hash(:full_address)
|
350
|
+
# #=> {:full_address=>"87635 Rice Street, Lake Brentonton, OR 61896-5968"}
|
351
|
+
#
|
352
|
+
# Faker::Address.full_address_as_hash(:city, :time_zone)
|
353
|
+
# #=> {:city=>"East Faustina", :time_zone=>"America/Mexico_City"}
|
354
|
+
#
|
355
|
+
# Faker::Address.full_address_as_hash(:street_address, street_address: {include_secondary: true})
|
356
|
+
# #=> {:street_address=>"29423 Kenneth Causeway Suite 563"}
|
357
|
+
#
|
358
|
+
# @faker.version 2.13.0
|
359
|
+
def full_address_as_hash(*attrs, **attrs_params)
|
360
|
+
attrs.map!(&:to_sym)
|
361
|
+
attrs_params.transform_keys!(&:to_sym)
|
362
|
+
attrs.map do |attr|
|
363
|
+
{ "#{attr}": attrs_params[attr] ? send(attr, **attrs_params[attr]) : send(attr) }
|
364
|
+
end.reduce({}, :merge)
|
365
|
+
end
|
336
366
|
end
|
337
367
|
end
|
338
368
|
end
|
data/lib/faker/default/bank.rb
CHANGED
@@ -5,6 +5,17 @@ module Faker
|
|
5
5
|
flexible :bank
|
6
6
|
|
7
7
|
class << self
|
8
|
+
##
|
9
|
+
# Produces a bank account number.
|
10
|
+
#
|
11
|
+
# @param digits [Integer] Number of digits that the generated account number should have.
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Faker::Bank.account_number #=> 6738582379
|
16
|
+
# Faker::Bank.account_number(digits: 13) #=> 673858237902
|
17
|
+
#
|
18
|
+
# @faker.version 1.9.1
|
8
19
|
def account_number(legacy_digits = NOT_GIVEN, digits: 10)
|
9
20
|
warn_for_deprecated_arguments do |keywords|
|
10
21
|
keywords << :digits if legacy_digits != NOT_GIVEN
|
@@ -17,6 +28,17 @@ module Faker
|
|
17
28
|
output[0...digits]
|
18
29
|
end
|
19
30
|
|
31
|
+
##
|
32
|
+
# Produces a bank iban number.
|
33
|
+
#
|
34
|
+
# @param country_code [String] Specifies what country prefix is used to generate the iban code.
|
35
|
+
# @return [String]
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Faker::Bank.iban #=> "GB76DZJM33188515981979"
|
39
|
+
# Faker::Bank.iban(country_code: "be") #=> "BE6375388567752043"
|
40
|
+
#
|
41
|
+
# @faker.version 1.7.0
|
20
42
|
def iban(legacy_country_code = NOT_GIVEN, country_code: 'GB')
|
21
43
|
# Each country has its own format for bank accounts
|
22
44
|
# Many of them use letters in certain parts of the account
|
@@ -38,22 +60,72 @@ module Faker
|
|
38
60
|
country_code.upcase + iban_checksum(country_code, account) + account
|
39
61
|
end
|
40
62
|
|
63
|
+
##
|
64
|
+
# Produces a bank name.
|
65
|
+
#
|
66
|
+
# @return [String]
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# Faker::Bank.name #=> "ABN AMRO CORPORATE FINANCE LIMITED"
|
70
|
+
#
|
71
|
+
# @faker.version 1.7.0
|
41
72
|
def name
|
42
73
|
fetch('bank.name')
|
43
74
|
end
|
44
75
|
|
76
|
+
##
|
77
|
+
# Produces a routing number.
|
78
|
+
#
|
79
|
+
# @return [String]
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# Faker::Bank.routing_number #=> "729343831"
|
83
|
+
#
|
84
|
+
# @faker.version 1.9.1
|
45
85
|
def routing_number
|
46
86
|
valid_routing_number
|
47
87
|
end
|
48
88
|
|
89
|
+
##
|
90
|
+
# Produces a valid routing number.
|
91
|
+
#
|
92
|
+
# @return [String]
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# Faker::Bank.routing_number #=> "729343831"
|
96
|
+
#
|
97
|
+
# @faker.version 1.9.1
|
49
98
|
def routing_number_with_format
|
50
99
|
compile_fraction(valid_routing_number)
|
51
100
|
end
|
52
101
|
|
102
|
+
##
|
103
|
+
# Produces a swift / bic number.
|
104
|
+
#
|
105
|
+
# @return [String]
|
106
|
+
#
|
107
|
+
# @example
|
108
|
+
# Faker::Bank.swift_bic #=> "AAFMGB21"
|
109
|
+
#
|
110
|
+
# @faker.version 1.7.0
|
53
111
|
def swift_bic
|
54
112
|
fetch('bank.swift_bic')
|
55
113
|
end
|
56
114
|
|
115
|
+
##
|
116
|
+
# Produces an Australian BSB (Bank-State-Branch) number
|
117
|
+
#
|
118
|
+
# @return [String]
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# Faker::Bank.bsb_number
|
122
|
+
# #=> "036616"
|
123
|
+
#
|
124
|
+
# @faker.version 2.13.0
|
125
|
+
def bsb_number
|
126
|
+
compile_bsb_number
|
127
|
+
end
|
128
|
+
|
57
129
|
private
|
58
130
|
|
59
131
|
def checksum(num_string)
|
@@ -68,8 +140,13 @@ module Faker
|
|
68
140
|
def compile_routing_number
|
69
141
|
digit_one_two = %w[00 01 02 03 04 05 06 07 08 09 10 11 12]
|
70
142
|
((21..32).to_a + (61..72).to_a + [80]).each { |x| digit_one_two << x.to_s }
|
71
|
-
|
72
|
-
|
143
|
+
digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring
|
144
|
+
end
|
145
|
+
|
146
|
+
def compile_bsb_number
|
147
|
+
digit_one_two = %w[01 03 06 08 11 12 73 76 78 30]
|
148
|
+
state = (2..7).to_a.map(&:to_s).sample
|
149
|
+
digit_one_two.sample + state + rand_numstring + rand_numstring + rand_numstring
|
73
150
|
end
|
74
151
|
|
75
152
|
# Calculates the mandatory checksum in 3rd and 4th characters in IBAN format
|
@@ -103,7 +180,7 @@ module Faker
|
|
103
180
|
prefix = (1..50).to_a.map(&:to_s).sample
|
104
181
|
numerator = routing_num.split('')[5..8].join.to_i.to_s
|
105
182
|
denominator = routing_num.split('')[0..4].join.to_i.to_s
|
106
|
-
prefix
|
183
|
+
"#{prefix}-#{numerator}/#{denominator}"
|
107
184
|
end
|
108
185
|
|
109
186
|
def rand_numstring
|