faker 1.8.7 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +146 -6
  3. data/README.md +44 -4
  4. data/lib/extensions/array.rb +10 -10
  5. data/lib/extensions/symbol.rb +0 -1
  6. data/lib/faker.rb +42 -35
  7. data/lib/faker/address.rb +39 -13
  8. data/lib/faker/app.rb +1 -3
  9. data/lib/faker/appliance.rb +13 -0
  10. data/lib/faker/avatar.rb +2 -2
  11. data/lib/faker/bank.rb +72 -15
  12. data/lib/faker/beer.rb +0 -1
  13. data/lib/faker/bitcoin.rb +4 -5
  14. data/lib/faker/bojack_horseman.rb +17 -0
  15. data/lib/faker/breaking_bad.rb +0 -3
  16. data/lib/faker/business.rb +1 -2
  17. data/lib/faker/cannabis.rb +42 -0
  18. data/lib/faker/chuck_norris.rb +3 -2
  19. data/lib/faker/code.rb +59 -20
  20. data/lib/faker/coffee.rb +4 -0
  21. data/lib/faker/color.rb +2 -2
  22. data/lib/faker/commerce.rb +3 -4
  23. data/lib/faker/community.rb +13 -0
  24. data/lib/faker/company.rb +80 -24
  25. data/lib/faker/currency.rb +17 -0
  26. data/lib/faker/date.rb +13 -27
  27. data/lib/faker/demographic.rb +2 -2
  28. data/lib/faker/device.rb +29 -0
  29. data/lib/faker/dota.rb +25 -0
  30. data/lib/faker/dr_who.rb +7 -8
  31. data/lib/faker/dumb_and_dumber.rb +1 -1
  32. data/lib/faker/dune.rb +4 -4
  33. data/lib/faker/elder_scrolls.rb +16 -0
  34. data/lib/faker/electrical_components.rb +19 -0
  35. data/lib/faker/ethereum.rb +12 -0
  36. data/lib/faker/famous_last_words.rb +11 -0
  37. data/lib/faker/file.rb +2 -5
  38. data/lib/faker/fillmurray.rb +3 -4
  39. data/lib/faker/finance.rb +3 -4
  40. data/lib/faker/food.rb +21 -1
  41. data/lib/faker/football.rb +21 -0
  42. data/lib/faker/gender.rb +13 -0
  43. data/lib/faker/greek_philosophers.rb +13 -0
  44. data/lib/faker/hacker.rb +9 -11
  45. data/lib/faker/harry_potter.rb +4 -0
  46. data/lib/faker/hipster.rb +12 -4
  47. data/lib/faker/id_number.rb +24 -9
  48. data/lib/faker/internet.rb +69 -57
  49. data/lib/faker/invoice.rb +94 -0
  50. data/lib/faker/job.rb +10 -3
  51. data/lib/faker/lebowski.rb +2 -2
  52. data/lib/faker/lord_of_the_rings.rb +5 -1
  53. data/lib/faker/lorem.rb +32 -8
  54. data/lib/faker/lorem_flickr.rb +43 -0
  55. data/lib/faker/lorem_pixel.rb +20 -5
  56. data/lib/faker/lovecraft.rb +12 -5
  57. data/lib/faker/markdown.rb +12 -4
  58. data/lib/faker/measurement.rb +35 -80
  59. data/lib/faker/michael_scott.rb +9 -0
  60. data/lib/faker/military.rb +25 -0
  61. data/lib/faker/music.rb +13 -1
  62. data/lib/faker/myst.rb +25 -0
  63. data/lib/faker/name.rb +22 -8
  64. data/lib/faker/nation.rb +24 -0
  65. data/lib/faker/nato_phonetic_alphabet.rb +9 -0
  66. data/lib/faker/new_girl.rb +13 -0
  67. data/lib/faker/number.rb +12 -12
  68. data/lib/faker/omniauth.rb +110 -122
  69. data/lib/faker/parks_and_rec.rb +13 -0
  70. data/lib/faker/phone_number.rb +11 -19
  71. data/lib/faker/placeholdit.rb +11 -2
  72. data/lib/faker/princess_bride.rb +13 -0
  73. data/lib/faker/rick_and_morty.rb +1 -1
  74. data/lib/faker/science.rb +4 -2
  75. data/lib/faker/seinfeld.rb +1 -1
  76. data/lib/faker/shakespeare.rb +0 -3
  77. data/lib/faker/silicon_valley.rb +4 -0
  78. data/lib/faker/simpsons.rb +3 -8
  79. data/lib/faker/singular_siegler.rb +9 -0
  80. data/lib/faker/slack_emoji.rb +0 -2
  81. data/lib/faker/source.rb +18 -0
  82. data/lib/faker/space.rb +4 -0
  83. data/lib/faker/star_trek.rb +2 -2
  84. data/lib/faker/star_wars.rb +5 -6
  85. data/lib/faker/stranger_thing.rb +13 -0
  86. data/lib/faker/string.rb +45 -0
  87. data/lib/faker/stripe.rb +63 -0
  88. data/lib/faker/sword_art_online.rb +21 -0
  89. data/lib/faker/team.rb +4 -1
  90. data/lib/faker/the_it_crowd.rb +21 -0
  91. data/lib/faker/time.rb +10 -10
  92. data/lib/faker/twin_peaks.rb +2 -2
  93. data/lib/faker/twitter.rb +1 -1
  94. data/lib/faker/types.rb +36 -40
  95. data/lib/faker/university.rb +3 -3
  96. data/lib/faker/vehicle.rb +72 -10
  97. data/lib/faker/verb.rb +25 -0
  98. data/lib/faker/version.rb +1 -1
  99. data/lib/faker/world_cup.rb +25 -0
  100. data/lib/helpers/char.rb +19 -20
  101. data/lib/helpers/unique_generator.rb +7 -1
  102. data/lib/locales/ca-CAT.yml +1 -1
  103. data/lib/locales/da-DK.yml +1 -0
  104. data/lib/locales/de-AT.yml +3 -2
  105. data/lib/locales/de.yml +6 -5
  106. data/lib/locales/ee.yml +59 -0
  107. data/lib/locales/en-CA.yml +23 -1
  108. data/lib/locales/en-GB.yml +1 -0
  109. data/lib/locales/en-NZ.yml +4 -3
  110. data/lib/locales/en-US.yml +2 -0
  111. data/lib/locales/en.yml +2 -2
  112. data/lib/locales/en/appliance.yml +5 -0
  113. data/lib/locales/en/bank.yml +274 -59
  114. data/lib/locales/en/bojack_horseman.yml +6 -0
  115. data/lib/locales/en/cannabis.yml +12 -0
  116. data/lib/locales/en/community.yml +33 -0
  117. data/lib/locales/en/currency.yml +6 -0
  118. data/lib/locales/en/dessert.yml +3 -3
  119. data/lib/locales/en/device.yml +7 -0
  120. data/lib/locales/en/dota.yml +102 -0
  121. data/lib/locales/en/dr_who.yml +5 -1
  122. data/lib/locales/en/dumb_and_dumber.yml +1 -1
  123. data/lib/locales/en/elder_scrolls.yml +8 -5
  124. data/lib/locales/en/electrical_components.yml +6 -0
  125. data/lib/locales/en/famous_last_words.yml +4 -0
  126. data/lib/locales/en/food.yml +6 -3
  127. data/lib/locales/en/football.yml +7 -0
  128. data/lib/locales/en/gender.yml +5 -0
  129. data/lib/locales/en/greek_philosophers.yml +26 -0
  130. data/lib/locales/en/harry_potter.yml +2 -1
  131. data/lib/locales/en/invoice.yml +6 -0
  132. data/lib/locales/en/job.yml +2 -2
  133. data/lib/locales/en/lord_of_the_rings.yml +1 -0
  134. data/lib/locales/en/lorem.yml +4 -0
  135. data/lib/locales/en/michael_scott.yml +45 -0
  136. data/lib/locales/en/military.yml +8 -0
  137. data/lib/locales/en/music.yml +29 -1
  138. data/lib/locales/en/myst.yml +47 -0
  139. data/lib/locales/en/name.yml +13 -12
  140. data/lib/locales/en/nation.yml +8 -0
  141. data/lib/locales/en/nato_phonetic_alphabet.yml +4 -0
  142. data/lib/locales/en/new_girl.yml +40 -0
  143. data/lib/locales/en/overwatch.yml +3 -2
  144. data/lib/locales/en/parks_and_rec.yml +7 -0
  145. data/lib/locales/en/princess_bride.yml +5 -0
  146. data/lib/locales/en/programming_language.yml +2 -1
  147. data/lib/locales/en/science.yml +1 -0
  148. data/lib/locales/en/silicon_valley.yml +1 -0
  149. data/lib/locales/en/singular_siegler.yml +37 -0
  150. data/lib/locales/en/source.yml +16 -0
  151. data/lib/locales/en/space.yml +2 -1
  152. data/lib/locales/en/star_wars.yml +10 -0
  153. data/lib/locales/en/stranger_thing.yml +36 -0
  154. data/lib/locales/en/stripe.yml +42 -0
  155. data/lib/locales/en/sword_art_online.yml +334 -0
  156. data/lib/locales/en/team.yml +1 -1
  157. data/lib/locales/en/the_it_crowd.yml +155 -0
  158. data/lib/locales/en/vehicle.yml +24 -0
  159. data/lib/locales/en/verbs.yml +8 -0
  160. data/lib/locales/en/world_cup.yml +271 -0
  161. data/lib/locales/es.yml +6 -1
  162. data/lib/locales/fi-FI.yml +9 -4
  163. data/lib/locales/fr-CA.yml +90 -0
  164. data/lib/locales/fr-CH.yml +73 -0
  165. data/lib/locales/fr.yml +4 -2
  166. data/lib/locales/it.yml +1 -1
  167. data/lib/locales/ja.yml +11 -0
  168. data/lib/locales/lv.yml +53 -0
  169. data/lib/locales/nl.yml +1 -1
  170. data/lib/locales/no.yml +7 -0
  171. data/lib/locales/pl.yml +1 -0
  172. data/lib/locales/pt-BR.yml +21 -13
  173. data/lib/locales/pt.yml +1 -0
  174. data/lib/locales/sv.yml +4 -4
  175. data/lib/locales/tr.yml +8 -0
  176. data/lib/locales/uk.yml +9 -0
  177. metadata +167 -3
@@ -0,0 +1,13 @@
1
+ module Faker
2
+ class ParksAndRec < Base
3
+ class << self
4
+ def character
5
+ fetch('parks_and_rec.characters')
6
+ end
7
+
8
+ def city
9
+ fetch('parks_and_rec.cities')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,36 +9,28 @@ module Faker
9
9
  parse('cell_phone.formats')
10
10
  end
11
11
 
12
- # US only
12
+ # US and Canada only
13
13
  def area_code
14
- begin
15
- fetch('phone_number.area_code')
16
- rescue I18n::MissingTranslationData
17
- nil
18
- end
14
+ fetch('phone_number.area_code')
15
+ rescue I18n::MissingTranslationData
16
+ nil
19
17
  end
20
18
 
21
- # US only
19
+ # US and Canada only
22
20
  def exchange_code
23
- begin
24
- fetch('phone_number.exchange_code')
25
- rescue I18n::MissingTranslationData
26
- nil
27
- end
21
+ fetch('phone_number.exchange_code')
22
+ rescue I18n::MissingTranslationData
23
+ nil
28
24
  end
29
25
 
30
- # US only
26
+ # US and Canada only
31
27
  # Can be used for both extensions and last four digits of phone number.
32
28
  # Since extensions can be of variable length, this method taks a length parameter
33
29
  def subscriber_number(length = 4)
34
- begin
35
- rand.to_s[2..(1 + length)]
36
- rescue I18n::MissingTranslationData
37
- nil
38
- end
30
+ rand.to_s[2..(1 + length)]
39
31
  end
40
32
 
41
- alias_method :extension, :subscriber_number
33
+ alias extension subscriber_number
42
34
  end
43
35
  end
44
36
  end
@@ -1,10 +1,13 @@
1
1
  module Faker
2
2
  class Placeholdit < Base
3
3
  class << self
4
- SUPPORTED_FORMATS = %w(png jpg gif jpeg)
4
+ SUPPORTED_FORMATS = %w[png jpg gif jpeg].freeze
5
5
 
6
6
  def image(size = '300x300', format = 'png', background_color = nil, text_color = nil, text = nil)
7
- raise ArgumentError, "Size should be specified in format 300x300" unless size.match(/^[0-9]+x[0-9]+$/)
7
+ background_color = generate_color if background_color == :random
8
+ text_color = generate_color if text_color == :random
9
+
10
+ raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
8
11
  raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
9
12
  raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
10
13
  raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
@@ -15,6 +18,12 @@ module Faker
15
18
  image_url += "?text=#{text}" if text
16
19
  image_url
17
20
  end
21
+
22
+ private
23
+
24
+ def generate_color
25
+ format('%06x', (rand * 0xffffff))
26
+ end
18
27
  end
19
28
  end
20
29
  end
@@ -0,0 +1,13 @@
1
+ module Faker
2
+ class PrincessBride < Base
3
+ class << self
4
+ def character
5
+ fetch('princess_bride.characters')
6
+ end
7
+
8
+ def quote
9
+ fetch('princess_bride.quotes')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -14,4 +14,4 @@ module Faker
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -1,15 +1,17 @@
1
1
  module Faker
2
2
  class Science < Base
3
3
  class << self
4
-
5
4
  def element
6
5
  fetch('science.element')
7
6
  end
8
7
 
8
+ def element_symbol
9
+ fetch('science.element_symbol')
10
+ end
11
+
9
12
  def scientist
10
13
  fetch('science.scientist')
11
14
  end
12
-
13
15
  end
14
16
  end
15
17
  end
@@ -8,6 +8,6 @@ module Faker
8
8
  def quote
9
9
  fetch('seinfeld.quote')
10
10
  end
11
- end
11
+ end
12
12
  end
13
13
  end
@@ -1,7 +1,6 @@
1
1
  module Faker
2
2
  class Shakespeare < Base
3
3
  class << self
4
-
5
4
  def hamlet_quote
6
5
  sample(hamlet)
7
6
  end
@@ -26,7 +25,6 @@ module Faker
26
25
  fetch('shakespeare.as_you_like_it')
27
26
  end
28
27
 
29
-
30
28
  def king_richard_iii
31
29
  fetch('shakespeare.king_richard_iii')
32
30
  end
@@ -34,7 +32,6 @@ module Faker
34
32
  def romeo_and_juliet
35
33
  fetch('shakespeare.romeo_and_juliet')
36
34
  end
37
-
38
35
  end
39
36
  end
40
37
  end
@@ -28,6 +28,10 @@ module Faker
28
28
  def url
29
29
  fetch('silicon_valley.urls')
30
30
  end
31
+
32
+ def email
33
+ fetch('silicon_valley.email')
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -1,10 +1,7 @@
1
- #encoding: utf-8
2
- #frozen_string_literal: true
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Faker
5
-
6
4
  class Simpsons < Base
7
-
8
5
  def self.character
9
6
  fetch('simpsons.characters')
10
7
  end
@@ -16,7 +13,5 @@ module Faker
16
13
  def self.quote
17
14
  fetch('simpsons.quotes')
18
15
  end
19
-
20
- end #class Simpsons
21
-
22
- end #module Faker
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Faker
2
+ class SingularSiegler < Base
3
+ class << self
4
+ def quote
5
+ fetch('singular_siegler.quotes')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,6 @@
1
1
  module Faker
2
2
  class SlackEmoji < Base
3
3
  class << self
4
-
5
4
  def people
6
5
  fetch('slack_emoji.people')
7
6
  end
@@ -37,7 +36,6 @@ module Faker
37
36
  def emoji
38
37
  parse('slack_emoji.emoji')
39
38
  end
40
-
41
39
  end
42
40
  end
43
41
  end
@@ -0,0 +1,18 @@
1
+ module Faker
2
+ class Source < Base
3
+ class << self
4
+ def hello_world(lang = :ruby)
5
+ fetch("source.hello_world.#{lang}")
6
+ end
7
+
8
+ def print(str: 'some string', lang: :ruby)
9
+ code = fetch("source.print.#{lang}")
10
+ code.gsub('faker_string_to_print', str)
11
+ end
12
+
13
+ def print_1_to_10(lang = :ruby)
14
+ fetch("source.print_1_to_10.#{lang}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -53,6 +53,10 @@ module Faker
53
53
  def meteorite
54
54
  fetch('space.meteorite')
55
55
  end
56
+
57
+ def launch_vehicule
58
+ fetch('space.launch_vehicule')
59
+ end
56
60
  end
57
61
  end
58
62
  end
@@ -12,10 +12,10 @@ module Faker
12
12
  def specie
13
13
  fetch('star_trek.specie')
14
14
  end
15
-
15
+
16
16
  def villain
17
17
  fetch('star_trek.villain')
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -36,9 +36,9 @@ module Faker
36
36
  def wookiee_sentence
37
37
  sentence = sample(wookiee_words).capitalize
38
38
 
39
- rand(0..10).times { sentence += " " + sample(wookiee_words)}
39
+ rand(0..10).times { sentence += ' ' + sample(wookiee_words) }
40
40
 
41
- sentence + sample(['.','?','!'])
41
+ sentence + sample(['.', '?', '!'])
42
42
  end
43
43
 
44
44
  def call_numbers
@@ -74,7 +74,7 @@ module Faker
74
74
  character = k.to_s if v.include?(character)
75
75
  end
76
76
 
77
- unless quoted_characters.keys.include?(character.to_sym)
77
+ unless quoted_characters.key?(character.to_sym)
78
78
  raise ArgumentError, "Character for quotes can be left blank or #{quoted_characters.keys.join(', ')}"
79
79
  end
80
80
  end
@@ -94,9 +94,8 @@ module Faker
94
94
  fetch_all('star_wars.wookiee_words')
95
95
  end
96
96
 
97
- alias_method :wookie_sentence, :wookiee_sentence
98
- alias_method :wookie_words, :wookiee_words
99
-
97
+ alias wookie_sentence wookiee_sentence
98
+ alias wookie_words wookiee_words
100
99
  end
101
100
  end
102
101
  end
@@ -0,0 +1,13 @@
1
+ module Faker
2
+ class StrangerThings < Base
3
+ class << self
4
+ def quote
5
+ fetch('stranger_things.quote')
6
+ end
7
+
8
+ def character
9
+ fetch('stranger_things.character')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class String < Base
5
+ class << self
6
+ def random(length = 32)
7
+ utf8string select_a length
8
+ end
9
+
10
+ private
11
+
12
+ def select_a(length)
13
+ if length.class.included_modules.include? Enumerable
14
+ select_a sample(length.to_enum.to_a)
15
+ else
16
+ length # recursive base case
17
+ end
18
+ end
19
+
20
+ def utf8string(length)
21
+ ratio = char_space_ratio
22
+ (1..length.to_i).map do
23
+ space_or_utf8_char ratio
24
+ end.join
25
+ end
26
+
27
+ def space_or_utf8_char(ratio)
28
+ sample [32.chr(Encoding::UTF_8), [utf8character] * ratio].flatten
29
+ end
30
+
31
+ def char_space_ratio
32
+ sample [2, [3] * 5, [5] * 17, [7] * 11, 11, 191].flatten
33
+ end
34
+
35
+ def utf8character
36
+ sample([
37
+ rand(32..90), # latin alphabet
38
+ rand(128), # 7-bit ASCII
39
+ rand(0xd800), # utf-8 codepoints below utf-16 surrogate halves
40
+ rand(57_344..1_114_111) # utf-8 codepoints above utf-16 surrogate halves
41
+ ]).chr(Encoding::UTF_8)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,63 @@
1
+ module Faker
2
+ class Stripe < Base
3
+ class << self
4
+ def valid_card(card_type = nil)
5
+ valid_cards = translate('faker.stripe.valid_cards').keys
6
+
7
+ if card_type.nil?
8
+ card_type = sample(valid_cards).to_s
9
+ else
10
+ unless valid_cards.include?(card_type.to_sym)
11
+ raise ArgumentError,
12
+ "Valid credit cards argument can be left blank or include #{valid_cards.join(', ')}"
13
+ end
14
+ end
15
+
16
+ fetch('stripe.valid_cards.' + card_type)
17
+ end
18
+
19
+ def valid_token(card_type = nil)
20
+ valid_tokens = translate('faker.stripe.valid_tokens').keys
21
+
22
+ if card_type.nil?
23
+ card_type = sample(valid_tokens).to_s
24
+ else
25
+ unless valid_tokens.include?(card_type.to_sym)
26
+ raise ArgumentError,
27
+ "Valid credit cards argument can be left blank or include #{valid_tokens.join(', ')}"
28
+ end
29
+ end
30
+
31
+ fetch('stripe.valid_tokens.' + card_type)
32
+ end
33
+
34
+ def invalid_card(card_error = nil)
35
+ invalid_cards = translate('faker.stripe.invalid_cards').keys
36
+
37
+ if card_error.nil?
38
+ card_error = sample(invalid_cards).to_s
39
+ else
40
+ unless invalid_cards.include?(card_error.to_sym)
41
+ raise ArgumentError,
42
+ "Invalid credit cards argument can be left blank or include #{invalid_cards.join(', ')}"
43
+ end
44
+ end
45
+
46
+ fetch('stripe.invalid_cards.' + card_error)
47
+ end
48
+
49
+ def month
50
+ format('%02d', rand_in_range(1, 12))
51
+ end
52
+
53
+ def year
54
+ start_year = ::Time.new.year + 1
55
+ rand_in_range(start_year, start_year + 5).to_s
56
+ end
57
+
58
+ def ccv(card_type = nil)
59
+ (card_type.to_s == 'amex' ? rand_in_range(1000, 9999) : rand_in_range(100, 999)).to_s
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,21 @@
1
+ module Faker
2
+ class SwordArtOnline < Base
3
+ class << self
4
+ def real_name
5
+ fetch('sword_art_online.real_name')
6
+ end
7
+
8
+ def game_name
9
+ fetch('sword_art_online.game_name')
10
+ end
11
+
12
+ def location
13
+ fetch('sword_art_online.location')
14
+ end
15
+
16
+ def item
17
+ fetch('sword_art_online.item')
18
+ end
19
+ end
20
+ end
21
+ end