faker 1.7.3 → 1.8.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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +90 -3
  3. data/README.md +45 -0
  4. data/lib/faker.rb +37 -75
  5. data/lib/faker/address.rb +12 -7
  6. data/lib/faker/app.rb +1 -5
  7. data/lib/faker/bank.rb +1 -0
  8. data/lib/faker/bitcoin.rb +1 -1
  9. data/lib/faker/code.rb +1 -1
  10. data/lib/faker/coffee.rb +29 -0
  11. data/lib/faker/color.rb +2 -2
  12. data/lib/faker/commerce.rb +1 -2
  13. data/lib/faker/company.rb +38 -6
  14. data/lib/faker/compass.rb +65 -0
  15. data/lib/faker/dessert.rb +19 -0
  16. data/lib/faker/dr_who.rb +34 -0
  17. data/lib/faker/dragon_ball.rb +9 -0
  18. data/lib/faker/family_guy.rb +17 -0
  19. data/lib/faker/fillmurray.rb +2 -2
  20. data/lib/faker/finance.rb +1 -1
  21. data/lib/faker/food.rb +4 -0
  22. data/lib/faker/funny_name.rb +43 -0
  23. data/lib/faker/hacker.rb +1 -1
  24. data/lib/faker/hey_arnold.rb +17 -0
  25. data/lib/faker/hipster.rb +3 -3
  26. data/lib/faker/hitchhikers_guide_to_the_galaxy.rb +33 -0
  27. data/lib/faker/hobbit.rb +21 -0
  28. data/lib/faker/how_i_met_your_mother.rb +21 -0
  29. data/lib/faker/id_number.rb +3 -7
  30. data/lib/faker/internet.rb +20 -14
  31. data/lib/faker/league_of_legends.rb +29 -0
  32. data/lib/faker/lorem.rb +5 -5
  33. data/lib/faker/lovecraft.rb +73 -0
  34. data/lib/faker/markdown.rb +66 -0
  35. data/lib/faker/matz.rb +9 -0
  36. data/lib/faker/music.rb +2 -2
  37. data/lib/faker/number.rb +6 -6
  38. data/lib/faker/omniauth.rb +77 -29
  39. data/lib/faker/overwatch.rb +17 -0
  40. data/lib/faker/phone_number.rb +2 -10
  41. data/lib/faker/pokemon.rb +5 -1
  42. data/lib/faker/rick_and_morty.rb +17 -0
  43. data/lib/faker/robin.rb +9 -0
  44. data/lib/faker/rupaul.rb +11 -0
  45. data/lib/faker/shakespeare.rb +4 -4
  46. data/lib/faker/simpsons.rb +22 -0
  47. data/lib/faker/star_trek.rb +21 -0
  48. data/lib/faker/star_wars.rb +9 -9
  49. data/lib/faker/time.rb +2 -2
  50. data/lib/faker/twitter.rb +114 -43
  51. data/lib/faker/vehicle.rb +3 -3
  52. data/lib/faker/version.rb +1 -1
  53. data/lib/faker/zelda.rb +4 -0
  54. data/lib/locales/bg.yml +41 -0
  55. data/lib/locales/de.yml +45 -1
  56. data/lib/locales/en-IND.yml +2 -2
  57. data/lib/locales/en-MS.yml +39 -0
  58. data/lib/locales/en.yml +301 -38
  59. data/lib/locales/en/README.md +13 -0
  60. data/lib/locales/en/address.yml +37 -0
  61. data/lib/locales/en/dr_who.yml +74 -0
  62. data/lib/locales/en/family_guy.yml +7 -0
  63. data/lib/locales/en/internet.yml +21 -0
  64. data/lib/locales/en/lovecraft.yml +9 -0
  65. data/lib/locales/en/rick_and_morty.yml +6 -0
  66. data/lib/locales/fr.yml +5 -1
  67. data/lib/locales/nl.yml +26 -26
  68. data/lib/locales/pt-BR.yml +1 -1
  69. metadata +33 -3
@@ -0,0 +1,21 @@
1
+ module Faker
2
+ class Hobbit < Base
3
+ class << self
4
+ def character
5
+ fetch('hobbit.character')
6
+ end
7
+
8
+ def thorins_company
9
+ fetch('hobbit.thorins_company')
10
+ end
11
+
12
+ def quote
13
+ fetch('hobbit.quote')
14
+ end
15
+
16
+ def location
17
+ fetch('hobbit.location')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Faker
2
+ class HowIMetYourMother < Base
3
+ class << self
4
+ def character
5
+ fetch('how_i_met_your_mother.character')
6
+ end
7
+
8
+ def catch_phrase
9
+ fetch('how_i_met_your_mother.catch_phrase')
10
+ end
11
+
12
+ def high_five
13
+ fetch('how_i_met_your_mother.high_five')
14
+ end
15
+
16
+ def quote
17
+ fetch('how_i_met_your_mother.quote')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  module Faker
2
2
  class IDNumber < Base
3
-
3
+
4
4
  INVALID_SSN = [
5
5
  /0{3}-\d{2}-\d{4}/,
6
6
  /\d{3}-0{2}-\d{4}/,
@@ -28,13 +28,9 @@ module Faker
28
28
  private
29
29
 
30
30
  def _translate(key)
31
- if parse("id_number.#{key}") == ''
32
- numerify(fetch("id_number.#{key}"))
33
- else
34
- parse("id_number.#{key}")
35
- end
31
+ parse("id_number.#{key}")
36
32
  end
37
33
  end
38
34
 
39
35
  end
40
- end
36
+ end
@@ -11,15 +11,15 @@ module Faker
11
11
  end
12
12
 
13
13
  def safe_email(name = nil)
14
- [user_name(name), 'example.'+ %w[org com net].sample].join('@')
14
+ [user_name(name), 'example.'+ sample(%w[org com net])].join('@')
15
15
  end
16
16
 
17
17
  def user_name(specifier = nil, separators = %w(. _))
18
18
  with_locale(:en) do
19
19
  if specifier.respond_to?(:scan)
20
- return specifier.scan(/\w+/).shuffle.join(separators.sample).downcase
20
+ return specifier.scan(/\w+/).shuffle.join(sample(separators)).downcase
21
21
  elsif specifier.kind_of?(Integer)
22
- # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
22
+ # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
23
23
  raise ArgumentError, "Given argument is too large" if specifier > 10**6
24
24
  tries = 0 # Don't try forever in case we get something like 1_000_000.
25
25
  begin
@@ -36,12 +36,12 @@ module Faker
36
36
  return result[0...specifier.max]
37
37
  end
38
38
 
39
- [
39
+ sample([
40
40
  Char.prepare(Name.first_name),
41
41
  [Name.first_name, Name.last_name].map{ |name|
42
42
  Char.prepare(name)
43
- }.join(separators.sample)
44
- ].sample
43
+ }.join(sample(separators))
44
+ ])
45
45
  end
46
46
  end
47
47
 
@@ -61,8 +61,8 @@ module Faker
61
61
 
62
62
  if special_chars
63
63
  chars = %w(! @ # $ % ^ & *)
64
- Random.rand(min_length).times do |i|
65
- temp[i] = chars[Random.rand(chars.length)]
64
+ rand(min_length).times do |i|
65
+ temp[i] = chars[rand(chars.length)]
66
66
  end
67
67
  end
68
68
 
@@ -73,13 +73,12 @@ module Faker
73
73
  with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
74
74
  end
75
75
 
76
- def fix_umlauts(string)
76
+ def fix_umlauts(string='')
77
77
  Char.fix_umlauts(string)
78
78
  end
79
79
 
80
80
  def domain_word
81
- return Char.prepare(Company.name.split(' ')[1]) if Config.locale == 'uk'
82
- Char.prepare(Company.name.split(' ').first)
81
+ with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
83
82
  end
84
83
 
85
84
  def domain_suffix
@@ -93,7 +92,8 @@ module Faker
93
92
  end
94
93
 
95
94
  def ip_v4_address
96
- (1..4).map { rand(2..254) }.join('.')
95
+ ary = (2..254).to_a
96
+ [ sample(ary), sample(ary), sample(ary), sample(ary) ].join('.')
97
97
  end
98
98
 
99
99
  def private_ip_v4_address
@@ -160,12 +160,18 @@ module Faker
160
160
  end
161
161
 
162
162
  def slug(words = nil, glue = nil)
163
- glue ||= %w[- _ .].sample
163
+ glue ||= sample(%w[- _ .])
164
164
  (words || Faker::Lorem::words(2).join(' ')).gsub(' ', glue).downcase
165
165
  end
166
166
 
167
167
  def device_token
168
- rand(16 ** 64).to_s(16).rjust(64, '0').chars.to_a.shuffle.join
168
+ shuffle(rand(16 ** 64).to_s(16).rjust(64, '0').chars.to_a).join
169
+ end
170
+
171
+ def user_agent(vendor = nil)
172
+ agent_hash = translate('faker.internet.user_agent')
173
+ agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
174
+ sample(agents)
169
175
  end
170
176
  end
171
177
  end
@@ -0,0 +1,29 @@
1
+ module Faker
2
+ class LeagueOfLegends < Base
3
+ class << self
4
+ def champion
5
+ fetch('league_of_legends.champion')
6
+ end
7
+
8
+ def location
9
+ fetch('league_of_legends.location')
10
+ end
11
+
12
+ def quote
13
+ fetch('league_of_legends.quote')
14
+ end
15
+
16
+ def summoner_spell
17
+ fetch('league_of_legends.summoner_spell')
18
+ end
19
+
20
+ def masteries
21
+ fetch('league_of_legends.masteries')
22
+ end
23
+
24
+ def rank
25
+ fetch('league_of_legends.rank')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -5,7 +5,7 @@ module Faker
5
5
 
6
6
  class << self
7
7
  def word
8
- translate('faker.lorem.words').sample
8
+ sample(translate('faker.lorem.words'))
9
9
  end
10
10
 
11
11
  def words(num = 3, supplemental = false)
@@ -15,17 +15,17 @@ module Faker
15
15
  (supplemental ? translate('faker.lorem.supplemental') : [])
16
16
  )
17
17
  word_list = word_list * ((resolved_num / word_list.length) + 1)
18
- word_list.shuffle[0, resolved_num]
18
+ shuffle(word_list)[0, resolved_num]
19
19
  end
20
20
 
21
21
  def character
22
- CHARACTERS.sample
22
+ sample(CHARACTERS)
23
23
  end
24
24
 
25
25
  def characters(char_count = 255)
26
26
  char_count = resolve(char_count)
27
27
  return '' if char_count.to_i < 1
28
- Array.new(char_count) { CHARACTERS.sample }.join
28
+ Array.new(char_count) { sample(CHARACTERS) }.join
29
29
  end
30
30
 
31
31
  def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
@@ -58,7 +58,7 @@ module Faker
58
58
  # All other values are simply returned.
59
59
  def resolve(value)
60
60
  case value
61
- when Array then value.sample
61
+ when Array then sample(value)
62
62
  when Range then rand value
63
63
  else value
64
64
  end
@@ -0,0 +1,73 @@
1
+ module Faker
2
+ class Lovecraft < Base
3
+ class << self
4
+ def location
5
+ fetch('lovecraft.location')
6
+ end
7
+
8
+ def fhtagn(number_of = 1)
9
+ number_of.times.collect { fetch('lovecraft.fhtagn') }.join(". ")
10
+ end
11
+
12
+ def deity
13
+ fetch('lovecraft.deity')
14
+ end
15
+
16
+ def tome
17
+ fetch('lovecraft.tome')
18
+ end
19
+
20
+ def sentence(word_count = 4, random_words_to_add = 6)
21
+ words(word_count + rand(random_words_to_add.to_i).to_i, true).join(' ').capitalize + '.'
22
+ end
23
+
24
+ def word
25
+ random_word = sample(translate('faker.lovecraft.words'))
26
+ random_word.match(/\s/) ? word : random_word
27
+ end
28
+
29
+ def words(num = 3, spaces_allowed = false)
30
+ resolved_num = resolve(num)
31
+ word_list = translate('faker.lovecraft.words')
32
+ word_list = word_list * ((resolved_num / word_list.length) + 1)
33
+
34
+ return shuffle(word_list)[0, resolved_num] if spaces_allowed
35
+ words = shuffle(word_list)[0, resolved_num]
36
+ words.each_with_index { |w, i| words[i] = word if w.match(/\s/) }
37
+ end
38
+
39
+
40
+ def sentences(sentence_count = 3)
41
+ [].tap do |sentences|
42
+ 1.upto(resolve(sentence_count)) do
43
+ sentences << sentence(3)
44
+ end
45
+ end
46
+ end
47
+
48
+ def paragraph(sentence_count = 3, random_sentences_to_add = 3)
49
+ sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ')
50
+ end
51
+
52
+ def paragraphs(paragraph_count = 3)
53
+ [].tap do |paragraphs|
54
+ 1.upto(resolve(paragraph_count)) do
55
+ paragraphs << paragraph(3)
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ # If an array or range is passed, a random value will be selected.
63
+ # All other values are simply returned.
64
+ def resolve(value)
65
+ case value
66
+ when Array then sample(value)
67
+ when Range then rand value
68
+ else value
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,66 @@
1
+ module Faker
2
+ class Markdown < Base
3
+ class << self
4
+
5
+ def headers
6
+ "#{fetch('markdown.headers')} #{Lorem.word.capitalize}"
7
+ end
8
+
9
+ def emphasis
10
+ paragraph = Faker::Lorem.paragraph(3)
11
+ words = paragraph.split(' ')
12
+ position = rand(0..words.length - 1)
13
+ formatting = fetch('markdown.emphasis')
14
+ words[position] = "#{formatting}#{words[position]}#{formatting}"
15
+ words.join(' ')
16
+ end
17
+
18
+ def ordered_list
19
+ number = rand(1..10)
20
+
21
+ result = []
22
+ number.times do |i|
23
+ result << "#{i.to_s}. #{Faker::Lorem.sentence(1)} \n"
24
+ end
25
+ result.join('')
26
+ end
27
+
28
+ def unordered_list
29
+ number = rand(1..10)
30
+
31
+ result = []
32
+ number.times do |i|
33
+ result << "* #{Faker::Lorem.sentence(1)} \n"
34
+ end
35
+ result.join('')
36
+ end
37
+
38
+ def inline_code
39
+ "`#{Faker::Lorem.sentence(1)}`"
40
+ end
41
+
42
+ def block_code
43
+ "```ruby\n#{Lorem.sentence(1)}\n```"
44
+ end
45
+
46
+ def table
47
+ table = []
48
+ 3.times do
49
+ table << "#{Lorem.word} | #{Lorem.word} | #{Lorem.word}"
50
+ end
51
+ table.join("\n")
52
+ end
53
+
54
+ def random
55
+ send(available_methods[rand(0..available_methods.length - 1)])
56
+ end
57
+
58
+ private
59
+
60
+ def available_methods
61
+ Markdown.public_methods(false) - Base.methods
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,9 @@
1
+ module Faker
2
+ class Matz < Base
3
+ class << self
4
+ def quote
5
+ fetch('matz.quotes')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,11 +2,11 @@ module Faker
2
2
  class Music < Base
3
3
  class << self
4
4
  def key
5
- keys.sample + key_variants.sample
5
+ sample(keys) + sample(key_variants)
6
6
  end
7
7
 
8
8
  def chord
9
- key + chord_types.sample
9
+ key + sample(chord_types)
10
10
  end
11
11
 
12
12
  def instrument
@@ -1,7 +1,7 @@
1
1
  module Faker
2
2
  class Number < Base
3
3
  class << self
4
- def number(digits)
4
+ def number(digits=10)
5
5
  num = ''
6
6
  if digits > 1
7
7
  num = non_zero_digit
@@ -10,11 +10,11 @@ module Faker
10
10
  num + leading_zero_number(digits)
11
11
  end
12
12
 
13
- def leading_zero_number(digits)
13
+ def leading_zero_number(digits=10)
14
14
  (1..digits).collect {digit}.join
15
15
  end
16
16
 
17
- def decimal_part(digits)
17
+ def decimal_part(digits=10)
18
18
  num = ''
19
19
  if digits > 1
20
20
  num = non_zero_digit
@@ -23,7 +23,7 @@ module Faker
23
23
  leading_zero_number(digits) + num
24
24
  end
25
25
 
26
- def decimal(l_digits, r_digits = 2)
26
+ def decimal(l_digits=5, r_digits=2)
27
27
  l_d = self.number(l_digits)
28
28
  r_d = self.decimal_part(r_digits)
29
29
  "#{l_d}.#{r_d}"
@@ -37,13 +37,13 @@ module Faker
37
37
  rand(10).to_s
38
38
  end
39
39
 
40
- def hexadecimal(digits)
40
+ def hexadecimal(digits=6)
41
41
  hex = ""
42
42
  digits.times { hex += rand(15).to_s(16) }
43
43
  hex
44
44
  end
45
45
 
46
- def normal(mean, standard_deviation)
46
+ def normal(mean=1, standard_deviation=1)
47
47
  theta = 2 * Math::PI * rand
48
48
  rho = Math.sqrt(-2 * Math.log(1 - rand))
49
49
  scale = standard_deviation * rho
@@ -29,7 +29,7 @@ module Faker
29
29
  credentials: {
30
30
  token: Crypto.md5,
31
31
  refresh_token: Crypto.md5,
32
- expires_at: one_hour_from_now.to_i,
32
+ expires_at: Time.forward.to_i,
33
33
  expires: true
34
34
  },
35
35
  extra: {
@@ -42,7 +42,7 @@ module Faker
42
42
  family_name: auth.last_name,
43
43
  profile: "https://plus.google.com/#{uid}",
44
44
  picture: image,
45
- gender: ["male", "female"].shuffle.pop,
45
+ gender: gender,
46
46
  birthday: Date.backward(36400).strftime("%Y-%m-%d"),
47
47
  local: "en",
48
48
  hd: "#{Company.name.downcase}.com"
@@ -57,7 +57,7 @@ module Faker
57
57
  "email" => email,
58
58
  "aud" => "APP_ID",
59
59
  "iat" => Number.number(10),
60
- "exp" => one_hour_from_now.to_i.to_s,
60
+ "exp" => Time.forward.to_i.to_s,
61
61
  "openid_id" => "https://www.google.com/accounts/o8/id?id=#{uid}"
62
62
  }
63
63
  }
@@ -81,7 +81,7 @@ module Faker
81
81
  },
82
82
  credentials: {
83
83
  token: Crypto.md5,
84
- expires_at: one_hour_from_now.to_i,
84
+ expires_at: Time.forward.to_i,
85
85
  expires: true
86
86
  },
87
87
  extra: {
@@ -101,7 +101,7 @@ module Faker
101
101
  timezone: timezone,
102
102
  locale: 'en_US',
103
103
  verified: random_boolean,
104
- updated_time: updated_time
104
+ updated_time: Time.backward.iso8601
105
105
  }
106
106
  }
107
107
  }
@@ -163,7 +163,7 @@ module Faker
163
163
  protected: random_boolean,
164
164
  description: description,
165
165
  profile_link_color: Color.hex_color,
166
- created_at: created_at,
166
+ created_at: Time.backward.strftime("%a %b %d %H:%M:%S %z %Y"),
167
167
  id_str: uid,
168
168
  profile_image_url_https: image,
169
169
  default_profile: random_boolean,
@@ -223,8 +223,8 @@ module Faker
223
223
  "params" => {
224
224
  oauth_token: token,
225
225
  oauth_token_secret: secret,
226
- oauth_expires_in: one_hour_from_now.to_i,
227
- oauth_authorization_expires_in: one_hour_from_now.to_i,
226
+ oauth_expires_in: Time.forward.to_i,
227
+ oauth_authorization_expires_in: Time.forward.to_i,
228
228
  },
229
229
  "response" => nil
230
230
  },
@@ -245,30 +245,78 @@ module Faker
245
245
  }
246
246
  end
247
247
 
248
- private
249
-
250
- def one_hour_from_now
251
- Object::Time.now + (60 * 60)
252
- end
248
+ def github
249
+ uid = Number.number(8)
250
+ auth = Omniauth.new()
251
+ first_name = auth.first_name.downcase
252
+ last_name = auth.last_name.downcase
253
+ login = "#{first_name}-#{last_name}"
254
+ html_url = "https://github.com/#{login}"
255
+ api_url = "https://api.github.com/users/#{login}"
256
+ email = "#{first_name}@example.com"
253
257
 
254
- def gender
255
- ["male", "female"].shuffle.pop
256
- end
258
+ {
259
+ provider: "github",
260
+ uid: uid,
261
+ info: {
262
+ nickname: login,
263
+ email: email,
264
+ name: auth.name,
265
+ image: image,
266
+ urls:{
267
+ GitHub: html_url
268
+ }
269
+ },
270
+ credentials: {
271
+ token: Crypto.md5,
272
+ expires: false
273
+ },
274
+ extra: {
275
+ raw_info: {
276
+ login: login,
277
+ id: uid,
278
+ avatar_url: image,
279
+ gravatar_id: "",
280
+ url: api_url,
281
+ html_url: html_url,
282
+ followers_url: "#{api_url}/followers",
283
+ following_url: "#{api_url}/following{/other_user}",
284
+ gists_url: "#{api_url}/gists{/gist_id}",
285
+ starred_url: "#{api_url}/starred{/owner}{/repo}",
286
+ subscriptions_url: "#{api_url}/subscriptions",
287
+ organizations_url: "#{api_url}/orgs",
288
+ repos_url: "#{api_url}/repos",
289
+ events_url: "#{api_url}/events{/privacy}",
290
+ received_events_url: "#{api_url}/received_events",
291
+ type: "User",
292
+ site_admin: random_boolean,
293
+ name: auth.name,
294
+ company: nil,
295
+ blog: nil,
296
+ location: city_state,
297
+ email: email,
298
+ hireable: nil,
299
+ bio: nil,
300
+ public_repos: random_number_from_range(1..1000),
301
+ public_gists: random_number_from_range(1..1000),
302
+ followers: random_number_from_range(1..1000),
303
+ following: random_number_from_range(1..1000),
304
+ created_at: Time.backward(36400).iso8601,
305
+ updated_at: Time.backward(2).iso8601
306
+ }
307
+ }
308
+ }
257
309
 
258
- def timezone
259
- (-12..12).to_a.shuffle.pop
260
- end
310
+ end
261
311
 
262
- def time_now
263
- Object::Time.now.to_s.split(' ')
264
- end
312
+ private
265
313
 
266
- def updated_time
267
- "#{Date.backward(365).to_s}T#{time_now[1..2].join('')}"
314
+ def gender
315
+ shuffle(["male", "female"]).pop
268
316
  end
269
317
 
270
- def created_at
271
- Date.backward(3650).strftime("%a %b %d #{time_now[1..2].join(' ')} %Y")
318
+ def timezone
319
+ shuffle((-12..12).to_a).pop
272
320
  end
273
321
 
274
322
  def image
@@ -280,13 +328,13 @@ module Faker
280
328
  end
281
329
 
282
330
  def random_number_from_range(range)
283
- range.to_a.shuffle.pop
331
+ shuffle(range.to_a).pop
284
332
  end
285
333
 
286
334
  def random_boolean
287
- [true, false].shuffle.pop
335
+ shuffle([true, false]).pop
288
336
  end
289
337
 
290
- end
338
+ end
291
339
  end
292
340
  end