faker 2.10.2 → 2.15.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 (219) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +323 -0
  3. data/README.md +27 -2
  4. data/lib/faker.rb +57 -25
  5. data/lib/faker/blockchain/aeternity.rb +4 -4
  6. data/lib/faker/books/dune.rb +15 -2
  7. data/lib/faker/books/lovecraft.rb +8 -4
  8. data/lib/faker/default/address.rb +35 -5
  9. data/lib/faker/default/bank.rb +80 -3
  10. data/lib/faker/default/barcode.rb +154 -0
  11. data/lib/faker/default/beer.rb +3 -3
  12. data/lib/faker/default/blood.rb +48 -0
  13. data/lib/faker/default/business.rb +1 -1
  14. data/lib/faker/default/camera.rb +46 -0
  15. data/lib/faker/default/cannabis.rb +80 -0
  16. data/lib/faker/default/chile_rut.rb +47 -3
  17. data/lib/faker/default/code.rb +98 -17
  18. data/lib/faker/default/commerce.rb +74 -11
  19. data/lib/faker/default/company.rb +78 -11
  20. data/lib/faker/default/compass.rb +135 -0
  21. data/lib/faker/default/computer.rb +63 -0
  22. data/lib/faker/default/construction.rb +54 -0
  23. data/lib/faker/default/cosmere.rb +90 -0
  24. data/lib/faker/default/crypto_coin.rb +45 -0
  25. data/lib/faker/default/date.rb +16 -12
  26. data/lib/faker/default/driving_licence.rb +65 -0
  27. data/lib/faker/default/drone.rb +332 -0
  28. data/lib/faker/default/faker_adjective.rb +35 -0
  29. data/lib/faker/default/file.rb +49 -0
  30. data/lib/faker/default/finance.rb +45 -0
  31. data/lib/faker/default/food.rb +1 -1
  32. data/lib/faker/default/funny_name.rb +45 -0
  33. data/lib/faker/default/gender.rb +1 -1
  34. data/lib/faker/default/hipster.rb +101 -4
  35. data/lib/faker/default/id_number.rb +88 -2
  36. data/lib/faker/default/internet.rb +68 -10
  37. data/lib/faker/default/internet_http.rb +48 -0
  38. data/lib/faker/default/invoice.rb +33 -6
  39. data/lib/faker/default/json.rb +59 -4
  40. data/lib/faker/default/lorem.rb +2 -2
  41. data/lib/faker/default/lorem_flickr.rb +65 -0
  42. data/lib/faker/default/lorem_pixel.rb +22 -0
  43. data/lib/faker/default/markdown.rb +89 -0
  44. data/lib/faker/default/measurement.rb +93 -2
  45. data/lib/faker/default/military.rb +26 -0
  46. data/lib/faker/default/mountain.rb +33 -0
  47. data/lib/faker/default/name.rb +98 -0
  48. data/lib/faker/default/nhs.rb +19 -0
  49. data/lib/faker/default/number.rb +6 -8
  50. data/lib/faker/default/omniauth.rb +107 -52
  51. data/lib/faker/default/phone_number.rb +88 -5
  52. data/lib/faker/default/placeholdit.rb +21 -0
  53. data/lib/faker/default/relationship.rb +1 -1
  54. data/lib/faker/default/slack_emoji.rb +81 -0
  55. data/lib/faker/default/south_africa.rb +90 -0
  56. data/lib/faker/default/space.rb +1 -1
  57. data/lib/faker/default/string.rb +19 -3
  58. data/lib/faker/default/stripe.rb +64 -3
  59. data/lib/faker/default/twitter.rb +35 -0
  60. data/lib/faker/default/types.rb +80 -0
  61. data/lib/faker/default/university.rb +45 -0
  62. data/lib/faker/default/vehicle.rb +184 -4
  63. data/lib/faker/default/verb.rb +45 -0
  64. data/lib/faker/default/world_cup.rb +4 -4
  65. data/lib/faker/fantasy/tolkien.rb +67 -0
  66. data/lib/faker/games/clash_of_clans.rb +48 -0
  67. data/lib/faker/games/control.rb +113 -0
  68. data/lib/faker/games/dnd.rb +136 -0
  69. data/lib/faker/games/elder_scrolls.rb +26 -0
  70. data/lib/faker/games/heroes.rb +13 -0
  71. data/lib/faker/games/heroes_of_the_storm.rb +16 -5
  72. data/lib/faker/games/minecraft.rb +113 -0
  73. data/lib/faker/games/street_fighter.rb +61 -0
  74. data/lib/faker/games/super_mario.rb +48 -0
  75. data/lib/faker/games/warhammer_fantasy.rb +74 -0
  76. data/lib/faker/games/world_of_warcraft.rb +26 -1
  77. data/lib/faker/japanese_media/conan.rb +48 -0
  78. data/lib/faker/japanese_media/doraemon.rb +48 -0
  79. data/lib/faker/japanese_media/dragon_ball.rb +26 -0
  80. data/lib/faker/japanese_media/naruto.rb +61 -0
  81. data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
  82. data/lib/faker/movies/departed.rb +49 -0
  83. data/lib/faker/movies/hobbit.rb +4 -4
  84. data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
  85. data/lib/faker/movies/lord_of_the_rings.rb +3 -3
  86. data/lib/faker/movies/movie.rb +13 -0
  87. data/lib/faker/movies/room.rb +63 -0
  88. data/lib/faker/movies/star_wars.rb +2 -2
  89. data/lib/faker/music/hiphop.rb +48 -0
  90. data/lib/faker/music/opera.rb +237 -1
  91. data/lib/faker/music/pearl_jam.rb +50 -0
  92. data/lib/faker/music/phish.rb +27 -1
  93. data/lib/faker/music/prince.rb +64 -0
  94. data/lib/faker/music/rush.rb +37 -0
  95. data/lib/faker/music/show.rb +49 -0
  96. data/lib/faker/quotes/chiquito.rb +80 -0
  97. data/lib/faker/quotes/quote.rb +80 -1
  98. data/lib/faker/quotes/rajnikanth.rb +26 -0
  99. data/lib/faker/quotes/shakespeare.rb +36 -0
  100. data/lib/faker/sports/volleyball.rb +74 -0
  101. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
  102. data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
  103. data/lib/faker/tv_shows/buffy.rb +17 -4
  104. data/lib/faker/tv_shows/dr_who.rb +1 -1
  105. data/lib/faker/tv_shows/final_space.rb +51 -0
  106. data/lib/faker/tv_shows/futurama.rb +65 -0
  107. data/lib/faker/tv_shows/simpsons.rb +14 -0
  108. data/lib/faker/tv_shows/suits.rb +37 -0
  109. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
  110. data/lib/faker/version.rb +1 -1
  111. data/lib/helpers/base58.rb +1 -1
  112. data/lib/helpers/char.rb +22 -27
  113. data/lib/helpers/unique_generator.rb +3 -2
  114. data/lib/locales/de-AT.yml +4 -2
  115. data/lib/locales/de-CH.yml +1696 -1
  116. data/lib/locales/de.yml +4 -2
  117. data/lib/locales/en-AU.yml +50 -10
  118. data/lib/locales/en-CA.yml +2 -0
  119. data/lib/locales/en-GB.yml +1 -1
  120. data/lib/locales/en-IND.yml +2 -1
  121. data/lib/locales/en-MS.yml +2 -1
  122. data/lib/locales/en-NEP.yml +4 -1
  123. data/lib/locales/en-NZ.yml +3 -1
  124. data/lib/locales/en-PAK.yml +2 -1
  125. data/lib/locales/en-SG.yml +2 -1
  126. data/lib/locales/en-US.yml +36 -10
  127. data/lib/locales/en-au-ocker.yml +2 -1
  128. data/lib/locales/en.yml +0 -3
  129. data/lib/locales/en/address.yml +2 -0
  130. data/lib/locales/en/adjective.yml +179 -0
  131. data/lib/locales/en/animal.yml +1 -1
  132. data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
  133. data/lib/locales/en/bank.yml +1 -1
  134. data/lib/locales/en/barcode.yml +24 -0
  135. data/lib/locales/en/big_bang_theory.yml +38 -0
  136. data/lib/locales/en/blood.yml +13 -0
  137. data/lib/locales/en/buffy.yml +1 -1
  138. data/lib/locales/en/camera.yml +611 -0
  139. data/lib/locales/en/chiquito.yml +64 -0
  140. data/lib/locales/en/clash_of_clan.yml +101 -0
  141. data/lib/locales/en/company.yml +2 -2
  142. data/lib/locales/en/computer.yml +36 -0
  143. data/lib/locales/en/conan.yml +171 -0
  144. data/lib/locales/en/control.yml +247 -0
  145. data/lib/locales/en/demographic.yml +218 -5
  146. data/lib/locales/en/departed.yml +50 -0
  147. data/lib/locales/en/dnd.yml +451 -0
  148. data/lib/locales/en/doraemon.yml +286 -0
  149. data/lib/locales/en/dota.yml +531 -63
  150. data/lib/locales/en/dragon_ball.yml +243 -1
  151. data/lib/locales/en/driving_license.yml +181 -0
  152. data/lib/locales/en/drone.yml +95 -0
  153. data/lib/locales/en/dune.yml +401 -131
  154. data/lib/locales/en/elder_scrolls.yml +583 -9
  155. data/lib/locales/en/fallout.yml +311 -133
  156. data/lib/locales/en/final_space.yml +37 -0
  157. data/lib/locales/en/finance.yml +53 -0
  158. data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
  159. data/lib/locales/en/futurama.yml +344 -0
  160. data/lib/locales/en/half_life.yml +84 -3
  161. data/lib/locales/en/heroes.yml +408 -3
  162. data/lib/locales/en/heroes_of_the_storm.yml +131 -4
  163. data/lib/locales/en/house.yml +1 -1
  164. data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
  165. data/lib/locales/en/jack_handey.yml +54 -0
  166. data/lib/locales/en/league_of_legends.yml +285 -6
  167. data/lib/locales/en/military.yml +179 -5
  168. data/lib/locales/en/minecraft.yml +663 -0
  169. data/lib/locales/en/mountain.yml +158 -0
  170. data/lib/locales/en/movie.yml +192 -1
  171. data/lib/locales/en/music.yml +451 -29
  172. data/lib/locales/en/myst.yml +87 -31
  173. data/lib/locales/en/name.yml +6 -5
  174. data/lib/locales/en/naruto.yml +231 -0
  175. data/lib/locales/en/one_piece.yml +2 -2
  176. data/lib/locales/en/opera.yml +168 -0
  177. data/lib/locales/en/overwatch.yml +2650 -2622
  178. data/lib/locales/en/pearl_jam.yml +213 -0
  179. data/lib/locales/en/phish.yml +392 -1
  180. data/lib/locales/en/pokemon.yml +417 -4
  181. data/lib/locales/en/prince.yml +227 -0
  182. data/lib/locales/en/quote.yml +692 -163
  183. data/lib/locales/en/rajnikanth.yml +77 -0
  184. data/lib/locales/en/room.yml +68 -0
  185. data/lib/locales/en/rush.yml +32 -0
  186. data/lib/locales/en/show.yml +597 -0
  187. data/lib/locales/en/simpsons.yml +668 -0
  188. data/lib/locales/en/source.yml +30 -0
  189. data/lib/locales/en/star_trek.yml +1 -1
  190. data/lib/locales/en/star_wars.yml +568 -220
  191. data/lib/locales/en/street_fighter.yml +1524 -0
  192. data/lib/locales/en/studio_ghibli.yml +107 -0
  193. data/lib/locales/en/suits.yml +45 -0
  194. data/lib/locales/en/super_mario.yml +58 -0
  195. data/lib/locales/en/super_smash_bros.yml +16 -4
  196. data/lib/locales/en/tolkien.yml +2453 -0
  197. data/lib/locales/en/volleyball.yml +501 -0
  198. data/lib/locales/en/warhammer_fantasy.yml +582 -0
  199. data/lib/locales/en/witcher.yml +389 -7
  200. data/lib/locales/en/world_of_warcraft.yml +122 -4
  201. data/lib/locales/en/zelda.yml +962 -4
  202. data/lib/locales/es.yml +56 -0
  203. data/lib/locales/fi-FI.yml +1 -1
  204. data/lib/locales/fr-CA.yml +21 -5
  205. data/lib/locales/fr-CH.yml +2 -2
  206. data/lib/locales/fr.yml +8 -2
  207. data/lib/locales/id.yml +2 -1
  208. data/lib/locales/it.yml +2 -1
  209. data/lib/locales/ja.yml +5 -1
  210. data/lib/locales/ko.yml +94 -2
  211. data/lib/locales/nb-NO.yml +4 -2
  212. data/lib/locales/pt-BR.yml +2 -1
  213. data/lib/locales/pt.yml +3 -1
  214. data/lib/locales/ru.yml +3 -1
  215. data/lib/locales/sk.yml +4 -2
  216. data/lib/locales/uk.yml +2 -0
  217. metadata +89 -21
  218. data/lib/locales/en/hobbit.yml +0 -19
  219. data/lib/locales/en/lord_of_the_rings.yml +0 -6
@@ -2,29 +2,45 @@
2
2
 
3
3
  mydir = __dir__
4
4
 
5
- begin
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(File.dirname(__FILE__), 'helpers', '*.rb')).sort.each { |file| require file }
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
- class Config
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
- @locale || I18n.locale
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{^\/?\^?}, '').gsub(%r{\$?\/?$}, '') # Ditch the anchors
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(/(\([^\)]+\))\{(\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)
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(/[\(\)]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
92
- .gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
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{^\/}) && fetched&.match(%r{\/$}) # A regex
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{^\/}) && fetched.match(%r{\/$}) # A regex
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]+\.)?([^\}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc|
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 transation
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) { yield }
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) ? list.sample(random: Faker::Config.random) : list
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(File.dirname(__FILE__), 'faker', '/**/*.rb')).sort.each { |file| require file }
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
- 'ak_' + rand_strings
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
- 'th_' + rand_strings(51)
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
- 'ct_' + rand_strings
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
- 'ok_' + rand_strings(51)
56
+ "ok_#{rand_strings(51)}"
57
57
  end
58
58
 
59
59
  protected
@@ -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('dune.quotes.' + character)
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('dune.sayings.' + source)
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: true).join(' ').capitalize + '.'
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 += ' ' + paragraph(sentence_count: 3) while paragraph.length < characters
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 ? ' ' + secondary_address : ''))
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
- # Faker::Address.mail_box #=> "PO Box 123"
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('address.postcode_by_state.' + state_abbreviation))
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('address.country_by_code.' + code)
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('address.country_by_name.' + name)
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
@@ -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
- routing_num = digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring
72
- routing_num
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 + '-' + numerator + '/' + denominator
183
+ "#{prefix}-#{numerator}/#{denominator}"
107
184
  end
108
185
 
109
186
  def rand_numstring