faker 2.12.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +240 -0
  3. data/History.md +4 -4
  4. data/README.md +18 -1
  5. data/lib/faker.rb +14 -14
  6. data/lib/faker/blockchain/aeternity.rb +4 -4
  7. data/lib/faker/blockchain/tezos.rb +28 -0
  8. data/lib/faker/books/dune.rb +15 -2
  9. data/lib/faker/books/lovecraft.rb +8 -4
  10. data/lib/faker/default/address.rb +34 -4
  11. data/lib/faker/default/app.rb +1 -1
  12. data/lib/faker/default/avatar.rb +1 -1
  13. data/lib/faker/default/bank.rb +4 -6
  14. data/lib/faker/default/barcode.rb +165 -0
  15. data/lib/faker/default/beer.rb +3 -3
  16. data/lib/faker/default/blood.rb +3 -3
  17. data/lib/faker/default/camera.rb +46 -0
  18. data/lib/faker/default/cannabis.rb +10 -0
  19. data/lib/faker/default/chile_rut.rb +47 -3
  20. data/lib/faker/default/chuck_norris.rb +1 -0
  21. data/lib/faker/default/code.rb +98 -17
  22. data/lib/faker/default/commerce.rb +1 -1
  23. data/lib/faker/default/company.rb +57 -11
  24. data/lib/faker/default/computer.rb +4 -4
  25. data/lib/faker/default/date.rb +16 -12
  26. data/lib/faker/default/driving_licence.rb +26 -2
  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 +6 -4
  30. data/lib/faker/default/finance.rb +21 -0
  31. data/lib/faker/default/food.rb +1 -1
  32. data/lib/faker/default/gender.rb +1 -1
  33. data/lib/faker/default/hipster.rb +14 -11
  34. data/lib/faker/default/id_number.rb +88 -2
  35. data/lib/faker/default/internet.rb +266 -12
  36. data/lib/faker/default/internet_http.rb +48 -0
  37. data/lib/faker/default/invoice.rb +1 -1
  38. data/lib/faker/default/json.rb +7 -6
  39. data/lib/faker/default/lorem.rb +160 -5
  40. data/lib/faker/default/lorem_flickr.rb +67 -7
  41. data/lib/faker/default/lorem_pixel.rb +23 -0
  42. data/lib/faker/default/markdown.rb +91 -0
  43. data/lib/faker/default/measurement.rb +3 -2
  44. data/lib/faker/default/military.rb +26 -0
  45. data/lib/faker/default/mountain.rb +33 -0
  46. data/lib/faker/default/name.rb +15 -0
  47. data/lib/faker/default/nhs.rb +19 -0
  48. data/lib/faker/default/number.rb +6 -8
  49. data/lib/faker/default/omniauth.rb +62 -14
  50. data/lib/faker/default/placeholdit.rb +3 -2
  51. data/lib/faker/default/relationship.rb +1 -1
  52. data/lib/faker/default/space.rb +1 -1
  53. data/lib/faker/default/string.rb +3 -2
  54. data/lib/faker/default/stripe.rb +3 -3
  55. data/lib/faker/default/vehicle.rb +1 -1
  56. data/lib/faker/default/world_cup.rb +4 -4
  57. data/lib/faker/fantasy/tolkien.rb +67 -0
  58. data/lib/faker/games/clash_of_clans.rb +48 -0
  59. data/lib/faker/games/control.rb +9 -9
  60. data/lib/faker/games/dnd.rb +91 -16
  61. data/lib/faker/games/elder_scrolls.rb +26 -0
  62. data/lib/faker/games/heroes.rb +13 -0
  63. data/lib/faker/games/heroes_of_the_storm.rb +16 -5
  64. data/lib/faker/games/minecraft.rb +113 -0
  65. data/lib/faker/games/street_fighter.rb +61 -0
  66. data/lib/faker/games/super_mario.rb +48 -0
  67. data/lib/faker/games/touhou.rb +75 -0
  68. data/lib/faker/games/warhammer_fantasy.rb +5 -5
  69. data/lib/faker/games/world_of_warcraft.rb +26 -1
  70. data/lib/faker/japanese_media/conan.rb +48 -0
  71. data/lib/faker/japanese_media/doraemon.rb +48 -0
  72. data/lib/faker/japanese_media/dragon_ball.rb +26 -0
  73. data/lib/faker/japanese_media/naruto.rb +61 -0
  74. data/lib/faker/japanese_media/studio_ghibli.rb +48 -0
  75. data/lib/faker/movies/departed.rb +3 -3
  76. data/lib/faker/movies/hobbit.rb +4 -4
  77. data/lib/faker/movies/how_to_train_your_dragon.rb +48 -0
  78. data/lib/faker/movies/lord_of_the_rings.rb +3 -3
  79. data/lib/faker/movies/movie.rb +13 -0
  80. data/lib/faker/movies/room.rb +63 -0
  81. data/lib/faker/movies/star_wars.rb +74 -2
  82. data/lib/faker/music/hiphop.rb +48 -0
  83. data/lib/faker/music/opera.rb +237 -1
  84. data/lib/faker/music/pearl_jam.rb +3 -3
  85. data/lib/faker/music/phish.rb +2 -2
  86. data/lib/faker/music/prince.rb +64 -0
  87. data/lib/faker/music/rock_band.rb +12 -0
  88. data/lib/faker/music/rush.rb +37 -0
  89. data/lib/faker/music/show.rb +3 -3
  90. data/lib/faker/quotes/quote.rb +26 -0
  91. data/lib/faker/quotes/rajnikanth.rb +1 -0
  92. data/lib/faker/quotes/shakespeare.rb +34 -0
  93. data/lib/faker/sports/volleyball.rb +74 -0
  94. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
  95. data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
  96. data/lib/faker/tv_shows/buffy.rb +17 -4
  97. data/lib/faker/tv_shows/dr_who.rb +1 -1
  98. data/lib/faker/tv_shows/final_space.rb +51 -0
  99. data/lib/faker/tv_shows/futurama.rb +65 -0
  100. data/lib/faker/tv_shows/simpsons.rb +14 -0
  101. data/lib/faker/tv_shows/suits.rb +3 -3
  102. data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +17 -4
  103. data/lib/faker/version.rb +1 -1
  104. data/lib/helpers/base58.rb +1 -1
  105. data/lib/helpers/char.rb +20 -26
  106. data/lib/helpers/unique_generator.rb +3 -2
  107. data/lib/locales/de-AT.yml +4 -2
  108. data/lib/locales/de-CH.yml +3 -1
  109. data/lib/locales/de.yml +4 -2
  110. data/lib/locales/en-AU.yml +8 -2
  111. data/lib/locales/en-GB.yml +1 -1
  112. data/lib/locales/en-IND.yml +2 -1
  113. data/lib/locales/en-MS.yml +2 -1
  114. data/lib/locales/en-NEP.yml +4 -1
  115. data/lib/locales/en-NZ.yml +3 -1
  116. data/lib/locales/en-PAK.yml +2 -1
  117. data/lib/locales/en-SG.yml +2 -1
  118. data/lib/locales/en-US.yml +10 -10
  119. data/lib/locales/en-au-ocker.yml +2 -1
  120. data/lib/locales/en.yml +0 -3
  121. data/lib/locales/en/adjective.yml +179 -0
  122. data/lib/locales/en/animal.yml +1 -1
  123. data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
  124. data/lib/locales/en/bank.yml +1 -1
  125. data/lib/locales/en/barcode.yml +24 -0
  126. data/lib/locales/en/big_bang_theory.yml +38 -0
  127. data/lib/locales/en/buffy.yml +1 -1
  128. data/lib/locales/en/camera.yml +611 -0
  129. data/lib/locales/en/clash_of_clan.yml +101 -0
  130. data/lib/locales/en/company.yml +2 -2
  131. data/lib/locales/en/conan.yml +171 -0
  132. data/lib/locales/en/demographic.yml +218 -5
  133. data/lib/locales/en/dnd.yml +430 -33
  134. data/lib/locales/en/doraemon.yml +286 -0
  135. data/lib/locales/en/dota.yml +531 -63
  136. data/lib/locales/en/dragon_ball.yml +243 -1
  137. data/lib/locales/en/driving_license.yml +181 -0
  138. data/lib/locales/en/drone.yml +95 -0
  139. data/lib/locales/en/dune.yml +401 -131
  140. data/lib/locales/en/elder_scrolls.yml +583 -9
  141. data/lib/locales/en/fallout.yml +311 -133
  142. data/lib/locales/en/final_space.yml +37 -0
  143. data/lib/locales/en/finance.yml +53 -0
  144. data/lib/locales/en/football.yml +3 -3
  145. data/lib/locales/en/fresh_prince_of_bel_air.yml +1 -1
  146. data/lib/locales/en/futurama.yml +344 -0
  147. data/lib/locales/en/half_life.yml +84 -3
  148. data/lib/locales/en/heroes.yml +408 -3
  149. data/lib/locales/en/heroes_of_the_storm.yml +131 -4
  150. data/lib/locales/en/how_to_train_your_dragon.yml +174 -0
  151. data/lib/locales/en/jack_handey.yml +54 -0
  152. data/lib/locales/en/league_of_legends.yml +285 -6
  153. data/lib/locales/en/lebowski.yml +1 -1
  154. data/lib/locales/en/military.yml +179 -5
  155. data/lib/locales/en/minecraft.yml +663 -0
  156. data/lib/locales/en/mountain.yml +158 -0
  157. data/lib/locales/en/movie.yml +192 -1
  158. data/lib/locales/en/music.yml +451 -29
  159. data/lib/locales/en/myst.yml +87 -31
  160. data/lib/locales/en/name.yml +5 -4
  161. data/lib/locales/en/naruto.yml +231 -0
  162. data/lib/locales/en/opera.yml +168 -0
  163. data/lib/locales/en/overwatch.yml +2650 -2622
  164. data/lib/locales/en/pokemon.yml +417 -4
  165. data/lib/locales/en/prince.yml +227 -0
  166. data/lib/locales/en/quote.yml +692 -163
  167. data/lib/locales/en/rock_band.yml +1 -0
  168. data/lib/locales/en/room.yml +68 -0
  169. data/lib/locales/en/rush.yml +32 -0
  170. data/lib/locales/en/simpsons.yml +668 -0
  171. data/lib/locales/en/source.yml +30 -0
  172. data/lib/locales/en/star_trek.yml +1 -1
  173. data/lib/locales/en/star_wars.yml +1 -0
  174. data/lib/locales/en/street_fighter.yml +1524 -0
  175. data/lib/locales/en/studio_ghibli.yml +107 -0
  176. data/lib/locales/en/super_mario.yml +58 -0
  177. data/lib/locales/en/super_smash_bros.yml +18 -4
  178. data/lib/locales/en/tolkien.yml +2453 -0
  179. data/lib/locales/en/touhou.yml +839 -0
  180. data/lib/locales/en/volleyball.yml +501 -0
  181. data/lib/locales/en/witcher.yml +389 -7
  182. data/lib/locales/en/world_of_warcraft.yml +122 -4
  183. data/lib/locales/en/zelda.yml +962 -4
  184. data/lib/locales/es.yml +56 -0
  185. data/lib/locales/fi-FI.yml +1 -1
  186. data/lib/locales/fr-CA.yml +19 -5
  187. data/lib/locales/fr-CH.yml +2 -2
  188. data/lib/locales/fr.yml +12 -6
  189. data/lib/locales/id.yml +3 -1
  190. data/lib/locales/it.yml +2 -1
  191. data/lib/locales/ja.yml +10 -1
  192. data/lib/locales/ko.yml +34 -24
  193. data/lib/locales/nb-NO.yml +4 -2
  194. data/lib/locales/pt-BR.yml +1 -1
  195. data/lib/locales/pt.yml +3 -1
  196. data/lib/locales/ru.yml +3 -1
  197. data/lib/locales/sk.yml +4 -2
  198. data/lib/locales/uk.yml +2 -0
  199. metadata +66 -18
  200. data/lib/locales/en/hobbit.yml +0 -19
  201. data/lib/locales/en/lord_of_the_rings.yml +0 -6
@@ -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
@@ -88,6 +88,34 @@ module Faker
88
88
  encode_tz(:edsig, 64)
89
89
  end
90
90
 
91
+ ##
92
+ # Produces a random Tezos public key
93
+ #
94
+ # @return [String]
95
+ #
96
+ # @example
97
+ # Faker::Blockchain::Tezos.public_key
98
+ # #=> "edpkuib9x8QXRc5nWwHUg7U1dXsVmaUrUNU5sX9pVEEvwbMVdfMCeq"
99
+ #
100
+ # @faker.version 2.15.2
101
+ def public_key
102
+ encode_tz(:edpk, 32)
103
+ end
104
+
105
+ ##
106
+ # Produces a random Tezos public key
107
+ #
108
+ # @return [String]
109
+ #
110
+ # @example
111
+ # Faker::Blockchain::Tezos.secret_key
112
+ # #=> "edsk3HZCAGEGpzQPnQUwQeFY4ESanFhQCgLpKriQw8GHyhKCrjHawv"
113
+ #
114
+ # @faker.version 2.15.2
115
+ def secret_key
116
+ encode_tz(:edsk, 32)
117
+ end
118
+
91
119
  protected
92
120
 
93
121
  ##
@@ -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
  ##
@@ -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
@@ -63,7 +63,6 @@ module Faker
63
63
  #
64
64
  # @faker.version 1.4.3
65
65
  def semantic_version(legacy_major = NOT_GIVEN, legacy_minor = NOT_GIVEN, legacy_patch = NOT_GIVEN, major: 0..9, minor: 0..9, patch: 1..9)
66
- # rubocop:enable Metrics/ParameterLists
67
66
  warn_for_deprecated_arguments do |keywords|
68
67
  keywords << :major if legacy_major != NOT_GIVEN
69
68
  keywords << :minor if legacy_minor != NOT_GIVEN
@@ -72,6 +71,7 @@ module Faker
72
71
 
73
72
  [major, minor, patch].map { |chunk| sample(Array(chunk)) }.join('.')
74
73
  end
74
+ # rubocop:enable Metrics/ParameterLists
75
75
  end
76
76
  end
77
77
  end
@@ -39,7 +39,6 @@ module Faker
39
39
  #
40
40
  # @faker.version 1.4.3
41
41
  def image(legacy_slug = NOT_GIVEN, legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_set = NOT_GIVEN, legacy_bgset = NOT_GIVEN, slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
42
- # rubocop:enable Metrics/ParameterLists
43
42
  warn_for_deprecated_arguments do |keywords|
44
43
  keywords << :slug if legacy_slug != NOT_GIVEN
45
44
  keywords << :size if legacy_size != NOT_GIVEN
@@ -55,6 +54,7 @@ module Faker
55
54
  bgset_query = "&bgset=#{bgset}" if bgset
56
55
  "https://robohash.org/#{slug}.#{format}?size=#{size}&set=#{set}#{bgset_query}"
57
56
  end
57
+ # rubocop:enable Metrics/ParameterLists
58
58
  end
59
59
  end
60
60
  end
@@ -121,7 +121,7 @@ module Faker
121
121
  # Faker::Bank.bsb_number
122
122
  # #=> "036616"
123
123
  #
124
- # @faker.version next
124
+ # @faker.version 2.13.0
125
125
  def bsb_number
126
126
  compile_bsb_number
127
127
  end
@@ -140,15 +140,13 @@ module Faker
140
140
  def compile_routing_number
141
141
  digit_one_two = %w[00 01 02 03 04 05 06 07 08 09 10 11 12]
142
142
  ((21..32).to_a + (61..72).to_a + [80]).each { |x| digit_one_two << x.to_s }
143
- routing_num = digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring
144
- routing_num
143
+ digit_one_two.sample + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring + rand_numstring
145
144
  end
146
145
 
147
146
  def compile_bsb_number
148
147
  digit_one_two = %w[01 03 06 08 11 12 73 76 78 30]
149
148
  state = (2..7).to_a.map(&:to_s).sample
150
- bsb_num = digit_one_two.sample + state + rand_numstring + rand_numstring + rand_numstring
151
- bsb_num
149
+ digit_one_two.sample + state + rand_numstring + rand_numstring + rand_numstring
152
150
  end
153
151
 
154
152
  # Calculates the mandatory checksum in 3rd and 4th characters in IBAN format
@@ -182,7 +180,7 @@ module Faker
182
180
  prefix = (1..50).to_a.map(&:to_s).sample
183
181
  numerator = routing_num.split('')[5..8].join.to_i.to_s
184
182
  denominator = routing_num.split('')[0..4].join.to_i.to_s
185
- prefix + '-' + numerator + '/' + denominator
183
+ "#{prefix}-#{numerator}/#{denominator}"
186
184
  end
187
185
 
188
186
  def rand_numstring
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Barcode < Base
5
+ class << self
6
+ ##
7
+ # Returns a EAN 8 or 13 digit format barcode number with check digit
8
+ # @return [String]
9
+ #
10
+ # @example
11
+ # Faker::Barcode.ean => "85657526"
12
+ # Faker::Barcode.ean(8) => "30152700"
13
+ # Faker::Barcode.ean(13) => "2115190480285"
14
+ #
15
+ # @faker.version 2.14.0
16
+ def ean(length = 8)
17
+ generate_barcode("barcode.ean_#{Integer(length)}")
18
+ end
19
+
20
+ ##
21
+ # Returns a EAN 8 or 13 digit format barcode number with composite string attached with check digit
22
+ # @return [String]
23
+ #
24
+ # @example
25
+ # Faker::Barcode.ean_with_composite_sumbology => "41007624|JHOC6649"
26
+ # Faker::Barcode.ean_with_composite_sumbology(8) => "38357961|XUYJ3266"
27
+ # Faker::Barcode.ean_with_composite_sumbology(13) => "9530722443911|CKHWQHID"
28
+ #
29
+ # @faker.version 2.14.0
30
+ def ean_with_composite_symbology(length = 8)
31
+ "#{ean(length)}|#{bothify(parse('barcode.composite_symbol'))}"
32
+ end
33
+
34
+ ##
35
+ # Returns a UPC_A format barcode number with check digit
36
+ # @return [String]
37
+ #
38
+ # @example
39
+ # Faker::Barcode.upc_a => "766807541831"
40
+ #
41
+ # @faker.version 2.14.0
42
+ def upc_a
43
+ generate_barcode('barcode.upc_a')
44
+ end
45
+
46
+ ##
47
+ # Returns a UPC_E format barcode number with check digit
48
+ # @return [String]
49
+ #
50
+ # @example
51
+ # Faker::Barcode.upc_e => "03746820"
52
+ #
53
+ # @faker.version 2.14.0
54
+ def upc_e
55
+ generate_barcode('barcode.upc_e')
56
+ end
57
+
58
+ ##
59
+ # Returns a UPC_A format barcode number with composite string attached with check digit
60
+ # @return [String]
61
+ #
62
+ # @example
63
+ # Faker::Barcode.upc_a_with_composite_symbology => "790670155765|JOVG6208"
64
+ #
65
+ # @faker.version 2.14.0
66
+ def upc_a_with_composite_symbology
67
+ "#{upc_a}|#{bothify(parse('barcode.composite_symbol'))}"
68
+ end
69
+
70
+ ##
71
+ # Returns a UPC_E format barcode number with composite string attached with check digit
72
+ # @return [String]
73
+ #
74
+ # @example
75
+ # Faker::Barcode.upc_e_with_composite_symbology => "05149247|BKZX9722"
76
+ #
77
+ # @faker.version 2.14.0
78
+ def upc_e_with_composite_symbology
79
+ "#{upc_e}|#{bothify(parse('barcode.composite_symbol'))}"
80
+ end
81
+
82
+ ##
83
+ # Returns a ISBN format barcode number with check digit
84
+ # @return [String]
85
+ #
86
+ # @example
87
+ # Faker::Barcode.isbn => "9798363807732"
88
+ #
89
+ # @faker.version 2.14.0
90
+ def isbn
91
+ generate_barcode('barcode.isbn')
92
+ end
93
+
94
+ ##
95
+ # Returns a ISMN format barcode number with check digit
96
+ # @return [String]
97
+ #
98
+ # @example
99
+ # Faker::Barcode.ismn => "9790527672897"
100
+ #
101
+ # @faker.version 2.14.0
102
+ def ismn
103
+ generate_barcode('barcode.ismn')
104
+ end
105
+
106
+ ##
107
+ # Returns a ISSN format barcode number with check digit
108
+ # @return [String]
109
+ #
110
+ # @example
111
+ # Faker::Barcode.issn => "9775541703338"
112
+ #
113
+ # @faker.version 2.14.0
114
+ def issn
115
+ generate_barcode('barcode.issn')
116
+ end
117
+
118
+ private
119
+
120
+ def generate_barcode(key)
121
+ barcode = parse(key)
122
+ check_digit = generate_check_digit(*sum_even_odd(barcode))
123
+ "#{barcode}#{check_digit}"
124
+ end
125
+
126
+ ##
127
+ # Returns the sum of even and odd numbers from value passed
128
+ #
129
+ # @return [Array]
130
+ #
131
+ # @example
132
+ # Faker::Barcode.send(:sum_even_odd, 12345) => [9, 5]
133
+ # Faker::Barcode.send(:sum_even_odd, 87465) => [17, 13]
134
+ #
135
+ # @faker.version 2.14.0
136
+ def sum_even_odd(fake_num)
137
+ number = fake_num.to_i
138
+ sum_even, sum_odd = 0, 0, index = 1
139
+
140
+ while number != 0
141
+ index.even? ? sum_even += number % 10 : sum_odd += number % 10
142
+
143
+ number /= 10
144
+ index += 1
145
+ end
146
+
147
+ [sum_odd, sum_even]
148
+ end
149
+
150
+ ##
151
+ # Generates the check digits from sum passed
152
+ #
153
+ # @return [Integer]
154
+ #
155
+ # @example
156
+ # Faker::Barcode.send(:generate_check_digit, 12, 4) => 0
157
+ # Faker::Barcode.send(:generate_check_digit, 23, 5) => 6
158
+ #
159
+ # @faker.version 2.14.0
160
+ def generate_check_digit(odd_sum, even_sum)
161
+ (10 - (odd_sum * 3 + even_sum) % 10) % 10
162
+ end
163
+ end
164
+ end
165
+ end