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
@@ -39,7 +39,7 @@ module Faker
39
39
 
40
40
  def address_for(network)
41
41
  version = PROTOCOL_VERSIONS.fetch(network)
42
- packed = version.chr + Random::DEFAULT.bytes(20)
42
+ packed = version.chr + Faker::Config.random.bytes(20)
43
43
  checksum = Digest::SHA2.digest(Digest::SHA2.digest(packed))[0..3]
44
44
  base58(packed + checksum)
45
45
  end
@@ -64,7 +64,7 @@ module Faker
64
64
 
65
65
  # Fill in the first two values of the string based with the specified prefix.
66
66
  # Reporting Body Identifier list: http://en.wikipedia.org/wiki/Reporting_Body_Identifier
67
- arr = RBI.sample
67
+ arr = sample(RBI)
68
68
  str[0] = arr[0].to_i
69
69
  str[1] = arr[1].to_i
70
70
  pos = 2
@@ -0,0 +1,29 @@
1
+ module Faker
2
+ class Coffee < Base
3
+ class << self
4
+ def blend_name
5
+ parse('coffee.blend_name')
6
+ end
7
+
8
+ def origin
9
+ country = fetch('coffee.country')
10
+ region = fetch("coffee.regions.#{search_format(country)}")
11
+ "#{region}, #{country}"
12
+ end
13
+
14
+ def variety
15
+ fetch('coffee.variety')
16
+ end
17
+
18
+ def notes
19
+ parse('coffee.notes')
20
+ end
21
+
22
+ private
23
+
24
+ def search_format(key)
25
+ key.split.length > 1 ? key.split.join('_').downcase : key.downcase
26
+ end
27
+ end
28
+ end
29
+ end
@@ -10,7 +10,7 @@ module Faker
10
10
  end
11
11
 
12
12
  def single_rgb_color
13
- (0..255).to_a.sample
13
+ sample((0..255).to_a)
14
14
  end
15
15
 
16
16
  def rgb_color
@@ -19,7 +19,7 @@ module Faker
19
19
 
20
20
  # returns [hue, saturation, lightness]
21
21
  def hsl_color
22
- [(0..360).to_a.sample, rand.round(2), rand.round(2)]
22
+ [sample((0..360).to_a), rand.round(2), rand.round(2)]
23
23
  end
24
24
 
25
25
  def hsla_color
@@ -33,8 +33,7 @@ module Faker
33
33
  end
34
34
 
35
35
  def price(range=0..100.0, as_string=false)
36
- random = Random::DEFAULT
37
- price = (random.rand(range) * 100).floor/100.0
36
+ price = (rand(range) * 100).floor/100.0
38
37
  if as_string
39
38
  price_parts = price.to_s.split('.')
40
39
  price = price_parts[0] + price_parts[-1].ljust(2, "0")
@@ -17,16 +17,16 @@ module Faker
17
17
 
18
18
  # Generate a buzzword-laden catch phrase.
19
19
  def catch_phrase
20
- translate('faker.company.buzzwords').collect {|list| list.sample }.join(' ')
20
+ translate('faker.company.buzzwords').collect {|list| sample(list) }.join(' ')
21
21
  end
22
22
 
23
23
  def buzzword
24
- translate('faker.company.buzzwords').flatten.sample
24
+ sample(translate('faker.company.buzzwords').flatten)
25
25
  end
26
26
 
27
27
  # When a straight answer won't do, BS to the rescue!
28
28
  def bs
29
- translate('faker.company.bs').collect {|list| list.sample }.join(' ')
29
+ translate('faker.company.bs').collect {|list| sample(list) }.join(' ')
30
30
  end
31
31
 
32
32
  def ein
@@ -39,7 +39,7 @@ module Faker
39
39
 
40
40
  # Get a random company logo url in PNG format.
41
41
  def logo
42
- rand_num = Random.rand(13) + 1
42
+ rand_num = rand(13) + 1
43
43
  "https://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
44
44
  end
45
45
 
@@ -48,13 +48,24 @@ module Faker
48
48
  # Valid leading digit: 1, 2, 3, 5, 6, 7, 8, 9
49
49
  # Valid third digit: >= 2
50
50
  # Last digit is a control digit
51
- base = [[1, 2, 3, 5, 6, 7, 8, 9].sample, (0..9).to_a.sample, (2..9).to_a.sample, ('%06d' % rand(10 ** 6))].join
51
+ base = [sample([1, 2, 3, 5, 6, 7, 8, 9]), sample((0..9).to_a), sample((2..9).to_a), ('%06d' % rand(10 ** 6))].join
52
52
  base + luhn_algorithm(base).to_s
53
53
  end
54
54
 
55
+ # Get a random Norwegian organization number. Info: https://www.brreg.no/om-oss/samfunnsoppdraget-vart/registera-vare/einingsregisteret/organisasjonsnummeret/
56
+ def norwegian_organisation_number
57
+ # Valid leading digit: 8, 9
58
+ mod11_check = nil
59
+ while mod11_check.nil?
60
+ base = [sample([8, 9]), ('%07d' % rand(10 ** 7))].join
61
+ mod11_check = mod11(base)
62
+ end
63
+ base + mod11_check.to_s
64
+ end
65
+
55
66
  def australian_business_number
56
67
  base = ('%09d' % rand(10 ** 9))
57
- abn = "00#{base}"
68
+ abn = "00#{base}"
58
69
 
59
70
  (99 - (abn_checksum(abn) % 89)).to_s + base
60
71
  end
@@ -65,6 +76,27 @@ module Faker
65
76
 
66
77
  private
67
78
 
79
+ # Mod11 functionality from https://github.com/badmanski/mod11/blob/master/lib/mod11.rb
80
+ def mod11(number)
81
+ weight = [2, 3, 4, 5, 6, 7,
82
+ 2, 3, 4, 5, 6, 7,
83
+ 2, 3, 4, 5, 6, 7]
84
+
85
+ sum = 0
86
+
87
+ number.to_s.reverse.chars.each_with_index do |char, i|
88
+ sum += char.to_i * weight[i]
89
+ end
90
+
91
+ remainder = sum % 11
92
+
93
+ case remainder
94
+ when 0 then remainder
95
+ when 1 then nil
96
+ else 11 - remainder
97
+ end
98
+ end
99
+
68
100
  def luhn_algorithm(number)
69
101
  multiplications = []
70
102
 
@@ -0,0 +1,65 @@
1
+ module Faker
2
+ class Compass < Base
3
+ class << self
4
+ def cardinal
5
+ fetch('compass.cardinal.word')
6
+ end
7
+
8
+ def ordinal
9
+ fetch('compass.ordinal.word')
10
+ end
11
+
12
+ def half_wind
13
+ fetch('compass.half-wind.word')
14
+ end
15
+
16
+ def quarter_wind
17
+ fetch('compass.quarter-wind.word')
18
+ end
19
+
20
+ def direction
21
+ parse('compass.direction')
22
+ end
23
+
24
+ def abbreviation
25
+ parse('compass.abbreviation')
26
+ end
27
+
28
+ def azimuth
29
+ parse('compass.azimuth')
30
+ end
31
+
32
+ def cardinal_abbreviation
33
+ fetch('compass.cardinal.abbreviation')
34
+ end
35
+
36
+ def ordinal_abbreviation
37
+ fetch('compass.ordinal.abbreviation')
38
+ end
39
+
40
+ def half_wind_abbreviation
41
+ fetch('compass.half-wind.abbreviation')
42
+ end
43
+
44
+ def quarter_wind_abbreviation
45
+ fetch('compass.quarter-wind.abbreviation')
46
+ end
47
+
48
+ def cardinal_azimuth
49
+ fetch('compass.cardinal.azimuth')
50
+ end
51
+
52
+ def ordinal_azimuth
53
+ fetch('compass.ordinal.azimuth')
54
+ end
55
+
56
+ def half_wind_azimuth
57
+ fetch('compass.half-wind.azimuth')
58
+ end
59
+
60
+ def quarter_wind_azimuth
61
+ fetch('compass.quarter-wind.azimuth')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ module Faker
2
+ class Dessert < Base
3
+ flexible :dessert
4
+
5
+ class << self
6
+ def variety
7
+ fetch('dessert.variety')
8
+ end
9
+
10
+ def topping
11
+ fetch('dessert.topping')
12
+ end
13
+
14
+ def flavor
15
+ fetch('dessert.flavor')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ #encoding: utf-8
2
+ #frozen_string_literal: true
3
+
4
+ module Faker
5
+
6
+ class DrWho < Base
7
+
8
+ def self.character
9
+ fetch('dr_who.character')
10
+ end
11
+
12
+ def self.the_doctor
13
+ fetch('dr_who.the_doctors')
14
+ end
15
+
16
+ def self.catch_phrase
17
+ fetch('dr_who.catch_phrases')
18
+ end
19
+
20
+ def self.quote
21
+ fetch('dr_who.quotes')
22
+ end
23
+
24
+ def self.villian
25
+ fetch('dr_who.villians')
26
+ end
27
+
28
+ def self.specie
29
+ fetch('dr_who.species')
30
+ end
31
+
32
+ end #class DrWho
33
+
34
+ end #module Faker
@@ -0,0 +1,9 @@
1
+ module Faker
2
+ class DragonBall < Base
3
+ class << self
4
+ def character
5
+ fetch('dragon_ball.characters')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Faker
2
+ class FamilyGuy < Base
3
+ class << self
4
+ def character
5
+ fetch('family_guy.character')
6
+ end
7
+
8
+ def location
9
+ fetch('family_guy.location')
10
+ end
11
+
12
+ def quote
13
+ fetch('family_guy.quote')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,8 +3,8 @@ module Faker
3
3
  class << self
4
4
 
5
5
  def image(grayscale = false, width = 200, height = 200)
6
- raise ArgumentError, "Width should be a number" unless width.match(/^\d+$/)
7
- raise ArgumentError, "Height should be a number" unless height.match(/^\d+$/)
6
+ raise ArgumentError, "Width should be a number" unless width.to_s.match(/^\d+$/)
7
+ raise ArgumentError, "Height should be a number" unless height.to_s.match(/^\d+$/)
8
8
  raise ArgumentError, "Grayscale should be a boolean" unless [true, false].include?(grayscale)
9
9
 
10
10
  grayscale == true ? "https://fillmurray.com/g/#{width}/#{height}" : "https://fillmurray.com/#{width}/#{height}"
@@ -8,7 +8,7 @@ module Faker
8
8
  class << self
9
9
  def credit_card(*types)
10
10
  types = CREDIT_CARD_TYPES if types.empty?
11
- type = types.sample
11
+ type = sample(types)
12
12
  template = numerify(fetch("credit_card.#{type}"))
13
13
 
14
14
  # calculate the luhn checksum digit
@@ -1,6 +1,10 @@
1
1
  module Faker
2
2
  class Food < Base
3
3
  class << self
4
+ def dish
5
+ fetch('food.dish')
6
+ end
7
+
4
8
  def ingredient
5
9
  fetch('food.ingredients')
6
10
  end
@@ -0,0 +1,43 @@
1
+ module Faker
2
+ class FunnyName < Base
3
+ flexible :funny_name
4
+
5
+ class << self
6
+ def name
7
+ fetch('funny_name.name')
8
+ end
9
+
10
+ def two_word_name
11
+ two_word_names = fetch_all('funny_name.name').select do |name|
12
+ name.count(' ') == 1
13
+ end
14
+
15
+ sample(two_word_names)
16
+ end
17
+
18
+ def three_word_name
19
+ three_word_names = fetch_all('funny_name.name').select do |name|
20
+ name.count(' ') == 2
21
+ end
22
+
23
+ sample(three_word_names)
24
+ end
25
+
26
+ def four_word_name
27
+ four_word_names = fetch_all('funny_name.name').select do |name|
28
+ name.count(' ') == 3
29
+ end
30
+
31
+ sample(four_word_names)
32
+ end
33
+
34
+ def name_with_initial
35
+ names_with_initials = fetch_all('funny_name.name').select do |name|
36
+ name.count('.') > 0
37
+ end
38
+
39
+ sample(names_with_initials)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -5,7 +5,7 @@ module Faker
5
5
 
6
6
  class << self
7
7
  def say_something_smart
8
- phrases.sample
8
+ sample(phrases)
9
9
  end
10
10
 
11
11
  def abbreviation
@@ -0,0 +1,17 @@
1
+ module Faker
2
+ class HeyArnold < Base
3
+ class << self
4
+ def character
5
+ fetch('hey_arnold.characters')
6
+ end
7
+
8
+ def location
9
+ fetch('hey_arnold.locations')
10
+ end
11
+
12
+ def quote
13
+ fetch('hey_arnold.quotes')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,7 +2,7 @@ module Faker
2
2
  class Hipster < Base
3
3
  class << self
4
4
  def word
5
- random_word = translate('faker.hipster.words').sample
5
+ random_word = sample(translate('faker.hipster.words'))
6
6
  random_word.match(/\s/) ? word : random_word
7
7
  end
8
8
 
@@ -14,8 +14,8 @@ module Faker
14
14
  )
15
15
  word_list = word_list * ((resolved_num / word_list.length) + 1)
16
16
 
17
- return word_list.shuffle[0, resolved_num] if spaces_allowed
18
- words = word_list.shuffle[0, resolved_num]
17
+ return shuffle(word_list)[0, resolved_num] if spaces_allowed
18
+ words = shuffle(word_list)[0, resolved_num]
19
19
  words.each_with_index { |w, i| words[i] = word if w.match(/\s/) }
20
20
  end
21
21
 
@@ -0,0 +1,33 @@
1
+ module Faker
2
+ class HitchhikersGuideToTheGalaxy < Base
3
+ class << self
4
+ def character
5
+ fetch('hitchhikers_guide_to_the_galaxy.characters')
6
+ end
7
+
8
+ def location
9
+ fetch('hitchhikers_guide_to_the_galaxy.locations')
10
+ end
11
+
12
+ def marvin_quote
13
+ fetch('hitchhikers_guide_to_the_galaxy.marvin_quote')
14
+ end
15
+
16
+ def planet
17
+ fetch('hitchhikers_guide_to_the_galaxy.planets')
18
+ end
19
+
20
+ def quote
21
+ fetch('hitchhikers_guide_to_the_galaxy.quotes')
22
+ end
23
+
24
+ def specie
25
+ fetch('hitchhikers_guide_to_the_galaxy.species')
26
+ end
27
+
28
+ def starship
29
+ fetch('hitchhikers_guide_to_the_galaxy.starships')
30
+ end
31
+ end
32
+ end
33
+ end