faker 1.8.7 → 1.9.1

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 (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
@@ -26,11 +26,11 @@ module Faker
26
26
 
27
27
  unless quoted_characters.include?(character.to_sym)
28
28
  raise ArgumentError,
29
- "Characters quoted can be left blank or #{quoted_characters.join(', ')}"
29
+ "Characters quoted can be left blank or #{quoted_characters.join(', ')}"
30
30
  end
31
31
  end
32
32
 
33
- return fetch('dune.quotes.' + character)
33
+ fetch('dune.quotes.' + character)
34
34
  end
35
35
 
36
36
  def saying(source = nil)
@@ -43,11 +43,11 @@ module Faker
43
43
 
44
44
  unless sourced_sayings.include?(source.to_sym)
45
45
  raise ArgumentError,
46
- "Sources quoted in sayings can be left blank or #{sourced_sayings.join(', ')}"
46
+ "Sources quoted in sayings can be left blank or #{sourced_sayings.join(', ')}"
47
47
  end
48
48
  end
49
49
 
50
- return fetch('dune.sayings.' + source)
50
+ fetch('dune.sayings.' + source)
51
51
  end
52
52
  end
53
53
  end
@@ -5,6 +5,10 @@ module Faker
5
5
  fetch('elder_scrolls.race')
6
6
  end
7
7
 
8
+ def city
9
+ fetch('elder_scrolls.city')
10
+ end
11
+
8
12
  def creature
9
13
  fetch('elder_scrolls.creature')
10
14
  end
@@ -16,6 +20,18 @@ module Faker
16
20
  def dragon
17
21
  fetch('elder_scrolls.dragon')
18
22
  end
23
+
24
+ def name
25
+ "#{fetch('elder_scrolls.first_name')} #{fetch('elder_scrolls.last_name')}"
26
+ end
27
+
28
+ def first_name
29
+ fetch('elder_scrolls.first_name')
30
+ end
31
+
32
+ def last_name
33
+ fetch('elder_scrolls.last_name')
34
+ end
19
35
  end
20
36
  end
21
37
  end
@@ -0,0 +1,19 @@
1
+ module Faker
2
+ class ElectricalComponents < Base
3
+ flexible :electrical_components
4
+
5
+ class << self
6
+ def active
7
+ fetch('electrical_components.active')
8
+ end
9
+
10
+ def passive
11
+ fetch('electrical_components.passive')
12
+ end
13
+
14
+ def electromechanical
15
+ fetch('electrical_components.electromechanical')
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Faker
2
+ class Ethereum < Base
3
+ class << self
4
+ def address
5
+ hex_alphabet = '0123456789abcdef'
6
+ var = '0x'
7
+ 40.times { var << sample(shuffle(hex_alphabet.split(''))) }
8
+ var
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Faker
2
+ class FamousLastWords < Base
3
+ flexible :famous_last_words
4
+
5
+ class << self
6
+ def last_words
7
+ fetch('famous_last_words.last_words')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,6 @@
1
1
  module Faker
2
2
  class File < Base
3
3
  class << self
4
-
5
4
  def extension
6
5
  fetch('file.extension')
7
6
  end
@@ -11,14 +10,12 @@ module Faker
11
10
  end
12
11
 
13
12
  def file_name(dir = nil, name = nil, ext = nil, directory_separator = '/')
14
-
15
- dir = Faker::Internet::slug unless dir
16
- name = Faker::Lorem::word.downcase unless name
13
+ dir ||= Faker::Internet.slug
14
+ name ||= Faker::Lorem.word.downcase
17
15
  ext ||= extension
18
16
 
19
17
  [dir, name].join(directory_separator) + ".#{ext}"
20
18
  end
21
-
22
19
  end
23
20
  end
24
21
  end
@@ -1,11 +1,10 @@
1
1
  module Faker
2
2
  class Fillmurray < Base
3
3
  class << self
4
-
5
4
  def image(grayscale = false, width = 200, height = 200)
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
- raise ArgumentError, "Grayscale should be a boolean" unless [true, false].include?(grayscale)
5
+ raise ArgumentError, 'Width should be a number' unless width.to_s =~ /^\d+$/
6
+ raise ArgumentError, 'Height should be a number' unless height.to_s =~ /^\d+$/
7
+ raise ArgumentError, 'Grayscale should be a boolean' unless [true, false].include?(grayscale)
9
8
 
10
9
  grayscale == true ? "https://fillmurray.com/g/#{width}/#{height}" : "https://fillmurray.com/#{width}/#{height}"
11
10
  end
@@ -1,9 +1,8 @@
1
1
  module Faker
2
2
  class Finance < Base
3
-
4
- CREDIT_CARD_TYPES = [:visa, :mastercard, :discover, :american_express,
5
- :diners_club, :jcb, :switch, :solo, :dankort,
6
- :maestro, :forbrugsforeningen, :laser].freeze
3
+ CREDIT_CARD_TYPES = %i[visa mastercard discover american_express
4
+ diners_club jcb switch solo dankort
5
+ maestro forbrugsforeningen laser].freeze
7
6
 
8
7
  class << self
9
8
  def credit_card(*types)
@@ -1,22 +1,42 @@
1
1
  module Faker
2
2
  class Food < Base
3
3
  class << self
4
+ # Retrieves a typical dish from each country
4
5
  def dish
5
6
  fetch('food.dish')
6
7
  end
7
8
 
9
+ # Retrieves a description about some dish
10
+ def description
11
+ fetch('food.descriptions')
12
+ end
13
+
14
+ # Retrieves an ingredient
8
15
  def ingredient
9
16
  fetch('food.ingredients')
10
17
  end
11
18
 
19
+ # Retrieves a fruit
20
+ def fruits
21
+ fetch('food.fruits')
22
+ end
23
+
24
+ # Retrieves a vegetable
25
+ def vegetables
26
+ fetch('food.vegetables')
27
+ end
28
+
29
+ # Retrieves some random spice
12
30
  def spice
13
31
  fetch('food.spices')
14
32
  end
15
33
 
34
+ # Retrieves cooking measures
16
35
  def measurement
17
36
  fetch('food.measurement_sizes') + ' ' + fetch('food.measurements')
18
37
  end
19
-
38
+
39
+ # Retrieves metric mesurements
20
40
  def metric_measurement
21
41
  fetch('food.metric_measurements')
22
42
  end
@@ -0,0 +1,21 @@
1
+ module Faker
2
+ class Football < Base
3
+ class << self
4
+ def team
5
+ fetch('football.teams')
6
+ end
7
+
8
+ def player
9
+ fetch('football.players')
10
+ end
11
+
12
+ def coach
13
+ fetch('football.coaches')
14
+ end
15
+
16
+ def competition
17
+ fetch('football.competitions')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Faker
2
+ class Gender < Base
3
+ class << self
4
+ def type
5
+ fetch('gender.types')
6
+ end
7
+
8
+ def binary_type
9
+ fetch('gender.binary_types')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Faker
2
+ class GreekPhilosophers < Base
3
+ class << self
4
+ def name
5
+ fetch('greek_philosophers.names')
6
+ end
7
+
8
+ def quote
9
+ fetch('greek_philosophers.quotes')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- #Port of http://shinytoylabs.com/jargon/
1
+ # Port of http://shinytoylabs.com/jargon/
2
2
  module Faker
3
3
  class Hacker < Base
4
4
  flexible :hacker
@@ -29,17 +29,15 @@ module Faker
29
29
  end
30
30
 
31
31
  def phrases
32
- [ "If we #{verb} the #{noun}, we can get to the #{abbreviation} #{noun} through the #{adjective} #{abbreviation} #{noun}!",
33
- "We need to #{verb} the #{adjective} #{abbreviation} #{noun}!",
34
- "Try to #{verb} the #{abbreviation} #{noun}, maybe it will #{verb} the #{adjective} #{noun}!",
35
- "You can't #{verb} the #{noun} without #{ingverb} the #{adjective} #{abbreviation} #{noun}!",
36
- "Use the #{adjective} #{abbreviation} #{noun}, then you can #{verb} the #{adjective} #{noun}!",
37
- "The #{abbreviation} #{noun} is down, #{verb} the #{adjective} #{noun} so we can #{verb} the #{abbreviation} #{noun}!",
38
- "#{ingverb} the #{noun} won't do anything, we need to #{verb} the #{adjective} #{abbreviation} #{noun}!".capitalize,
39
- "I'll #{verb} the #{adjective} #{abbreviation} #{noun}, that should #{noun} the #{abbreviation} #{noun}!"
40
- ]
32
+ ["If we #{verb} the #{noun}, we can get to the #{abbreviation} #{noun} through the #{adjective} #{abbreviation} #{noun}!",
33
+ "We need to #{verb} the #{adjective} #{abbreviation} #{noun}!",
34
+ "Try to #{verb} the #{abbreviation} #{noun}, maybe it will #{verb} the #{adjective} #{noun}!",
35
+ "You can't #{verb} the #{noun} without #{ingverb} the #{adjective} #{abbreviation} #{noun}!",
36
+ "Use the #{adjective} #{abbreviation} #{noun}, then you can #{verb} the #{adjective} #{noun}!",
37
+ "The #{abbreviation} #{noun} is down, #{verb} the #{adjective} #{noun} so we can #{verb} the #{abbreviation} #{noun}!",
38
+ "#{ingverb} the #{noun} won't do anything, we need to #{verb} the #{adjective} #{abbreviation} #{noun}!".capitalize,
39
+ "I'll #{verb} the #{adjective} #{abbreviation} #{noun}, that should #{noun} the #{abbreviation} #{noun}!"]
41
40
  end
42
41
  end
43
-
44
42
  end
45
43
  end
@@ -20,6 +20,10 @@ module Faker
20
20
  def house
21
21
  fetch('harry_potter.houses')
22
22
  end
23
+
24
+ def spell
25
+ fetch('harry_potter.spells')
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -3,7 +3,7 @@ module Faker
3
3
  class << self
4
4
  def word
5
5
  random_word = sample(translate('faker.hipster.words'))
6
- random_word.match(/\s/) ? word : random_word
6
+ random_word =~ /\s/ ? word : random_word
7
7
  end
8
8
 
9
9
  def words(num = 3, supplemental = false, spaces_allowed = false)
@@ -12,11 +12,11 @@ module Faker
12
12
  translate('faker.hipster.words') +
13
13
  (supplemental ? translate('faker.lorem.words') : [])
14
14
  )
15
- word_list = word_list * ((resolved_num / word_list.length) + 1)
15
+ word_list *= ((resolved_num / word_list.length) + 1)
16
16
 
17
17
  return shuffle(word_list)[0, resolved_num] if spaces_allowed
18
18
  words = shuffle(word_list)[0, resolved_num]
19
- words.each_with_index { |w, i| words[i] = word if w.match(/\s/) }
19
+ words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
20
20
  end
21
21
 
22
22
  def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
@@ -43,7 +43,15 @@ module Faker
43
43
  end
44
44
  end
45
45
 
46
- private
46
+ def paragraph_by_chars(chars = 256, supplemental = false)
47
+ paragraph = paragraph(3, supplemental)
48
+
49
+ paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars
50
+
51
+ paragraph[0...chars - 1] + '.'
52
+ end
53
+
54
+ private
47
55
 
48
56
  # If an array or range is passed, a random value will be selected.
49
57
  # All other values are simply returned.
@@ -1,16 +1,15 @@
1
1
  module Faker
2
2
  class IDNumber < Base
3
-
3
+ CHECKS = 'TRWAGMYFPDXBNJZSQVHLCKE'.freeze
4
4
  INVALID_SSN = [
5
- /0{3}-\d{2}-\d{4}/,
6
- /\d{3}-0{2}-\d{4}/,
7
- /\d{3}-\d{2}-0{4}/,
8
- /666-\d{2}-\d{4}/,
9
- /9\d{2}-\d{2}-\d{4}/
10
- ]
5
+ /0{3}-\d{2}-\d{4}/,
6
+ /\d{3}-0{2}-\d{4}/,
7
+ /\d{3}-\d{2}-0{4}/,
8
+ /666-\d{2}-\d{4}/,
9
+ /9\d{2}-\d{2}-\d{4}/
10
+ ].freeze
11
11
 
12
12
  class << self
13
-
14
13
  def valid
15
14
  _translate('valid')
16
15
  end
@@ -25,12 +24,28 @@ module Faker
25
24
  INVALID_SSN.any? { |regex| regex =~ ssn } ? ssn_valid : ssn
26
25
  end
27
26
 
27
+ def spanish_citizen_number
28
+ num = Faker::Number.number(8)
29
+ mod = num.to_i % 23
30
+ check = CHECKS[mod]
31
+ "#{num}-#{check}"
32
+ end
33
+
34
+ def spanish_foreign_citizen_number
35
+ code = 'XYZ'
36
+ digits = Faker::Number.number(7)
37
+ prefix = code[rand(code.length)]
38
+ prefix_val = 'XYZ'.index(prefix).to_s
39
+ mod = "#{prefix_val}#{digits}".to_i % 23
40
+ check = CHECKS[mod]
41
+ "#{prefix}-#{digits}-#{check}"
42
+ end
43
+
28
44
  private
29
45
 
30
46
  def _translate(key)
31
47
  parse("id_number.#{key}")
32
48
  end
33
49
  end
34
-
35
50
  end
36
51
  end
@@ -1,47 +1,53 @@
1
1
  module Faker
2
2
  class Internet < Base
3
3
  class << self
4
-
5
- def email(name = nil)
6
- [user_name(name), domain_name].join('@')
4
+ def email(name = nil, *separators)
5
+ if separators
6
+ [username(name, separators), domain_name].join('@')
7
+ else
8
+ [username(name), domain_name].join('@')
9
+ end
7
10
  end
8
11
 
9
12
  def free_email(name = nil)
10
- [user_name(name), fetch('internet.free_email')].join('@')
13
+ [username(name), fetch('internet.free_email')].join('@')
11
14
  end
12
15
 
13
16
  def safe_email(name = nil)
14
- [user_name(name), 'example.'+ sample(%w[org com net])].join('@')
17
+ [username(name), 'example.' + sample(%w[org com net])].join('@')
15
18
  end
16
19
 
17
- def user_name(specifier = nil, separators = %w(. _))
20
+ def username(specifier = nil, separators = %w[. _])
18
21
  with_locale(:en) do
19
- if specifier.respond_to?(:scan)
20
- return specifier.scan(/\w+/).shuffle.join(sample(separators)).downcase
21
- elsif specifier.kind_of?(Integer)
22
+ return shuffle(specifier.scan(/\w+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
23
+ if specifier.is_a?(Integer)
22
24
  # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
23
- raise ArgumentError, "Given argument is too large" if specifier > 10**6
25
+ raise ArgumentError, 'Given argument is too large' if specifier > 10**6
24
26
  tries = 0 # Don't try forever in case we get something like 1_000_000.
25
- begin
26
- result = user_name(nil, separators)
27
+ result = nil
28
+ loop do
29
+ result = username(nil, separators)
27
30
  tries += 1
28
- end while result.length < specifier && tries < 7
29
- return result * (specifier/result.length + 1) if specifier > 0
30
- elsif specifier.kind_of?(Range)
31
+ break unless result.length < specifier && tries < 7
32
+ end
33
+ return result * (specifier / result.length + 1) if specifier > 0
34
+ elsif specifier.is_a?(Range)
31
35
  tries = 0
32
- begin
33
- result = user_name(specifier.min, separators)
36
+ result = nil
37
+ loop do
38
+ result = username(specifier.min, separators)
34
39
  tries += 1
35
- end while !specifier.include?(result.length) && tries < 7
40
+ break unless !specifier.include?(result.length) && tries < 7
41
+ end
36
42
  return result[0...specifier.max]
37
43
  end
38
44
 
39
45
  sample([
40
- Char.prepare(Name.first_name),
41
- [Name.first_name, Name.last_name].map{ |name|
42
- Char.prepare(name)
43
- }.join(sample(separators))
44
- ])
46
+ Char.prepare(Name.first_name),
47
+ [Name.first_name, Name.last_name].map do |name|
48
+ Char.prepare(name)
49
+ end.join(sample(separators))
50
+ ])
45
51
  end
46
52
  end
47
53
 
@@ -60,7 +66,7 @@ module Faker
60
66
  end
61
67
 
62
68
  if special_chars
63
- chars = %w(! @ # $ % ^ & *)
69
+ chars = %w[! @ # $ % ^ & *]
64
70
  rand(1..min_length).times do |i|
65
71
  temp[i] = chars[rand(chars.length)]
66
72
  end
@@ -73,7 +79,7 @@ module Faker
73
79
  with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
74
80
  end
75
81
 
76
- def fix_umlauts(string='')
82
+ def fix_umlauts(string = '')
77
83
  Char.fix_umlauts(string)
78
84
  end
79
85
 
@@ -85,87 +91,91 @@ module Faker
85
91
  fetch('internet.domain_suffix')
86
92
  end
87
93
 
88
- def mac_address(prefix='')
89
- prefix_digits = prefix.split(':').map{ |d| d.to_i(16) }
90
- address_digits = (6 - prefix_digits.size).times.map{ rand(256) }
91
- (prefix_digits + address_digits).map{ |d| '%02x' % d }.join(':')
94
+ def mac_address(prefix = '')
95
+ prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
96
+ address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
97
+ (prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
92
98
  end
93
99
 
94
100
  def ip_v4_address
95
101
  ary = (2..254).to_a
96
- [ sample(ary), sample(ary), sample(ary), sample(ary) ].join('.')
102
+ [sample(ary), sample(ary), sample(ary), sample(ary)].join('.')
97
103
  end
98
104
 
99
105
  def private_ip_v4_address
100
- begin
106
+ addr = nil
107
+ loop do
101
108
  addr = ip_v4_address
102
- end while !private_net_checker[addr]
109
+ break if private_net_checker[addr]
110
+ end
103
111
  addr
104
112
  end
105
113
 
106
114
  def public_ip_v4_address
107
- begin
115
+ addr = nil
116
+ loop do
108
117
  addr = ip_v4_address
109
- end while reserved_net_checker[addr]
118
+ break unless reserved_net_checker[addr]
119
+ end
110
120
  addr
111
121
  end
112
122
 
113
123
  def private_nets_regex
114
124
  [
115
- /^10\./, # 10.0.0.0 10.255.255.255
116
- /^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./, # 100.64.0.0 100.127.255.255
117
- /^127\./, # 127.0.0.0 127.255.255.255
118
- /^169\.254\./, # 169.254.0.0 169.254.255.255
119
- /^172\.(1[6-9]|2\d|3[0-1])\./, # 172.16.0.0 172.31.255.255
120
- /^192\.0\.0\./, # 192.0.0.0 192.0.0.255
121
- /^192\.168\./, # 192.168.0.0 192.168.255.255
122
- /^198\.(1[8-9])\./ # 198.18.0.0 198.19.255.255
125
+ /^10\./, # 10.0.0.0 - 10.255.255.255
126
+ /^100\.(6[4-9]|[7-9]\d|1[0-1]\d|12[0-7])\./, # 100.64.0.0 - 100.127.255.255
127
+ /^127\./, # 127.0.0.0 - 127.255.255.255
128
+ /^169\.254\./, # 169.254.0.0 - 169.254.255.255
129
+ /^172\.(1[6-9]|2\d|3[0-1])\./, # 172.16.0.0 - 172.31.255.255
130
+ /^192\.0\.0\./, # 192.0.0.0 - 192.0.0.255
131
+ /^192\.168\./, # 192.168.0.0 - 192.168.255.255
132
+ /^198\.(1[8-9])\./ # 198.18.0.0 - 198.19.255.255
123
133
  ]
124
134
  end
125
135
 
126
136
  def private_net_checker
127
- lambda { |addr| private_nets_regex.any? { |net| net =~ addr } }
137
+ ->(addr) { private_nets_regex.any? { |net| net =~ addr } }
128
138
  end
129
139
 
130
140
  def reserved_nets_regex
131
141
  [
132
- /^0\./, # 0.0.0.0 0.255.255.255
133
- /^192\.0\.2\./, # 192.0.2.0 192.0.2.255
134
- /^192\.88\.99\./, # 192.88.99.0 192.88.99.255
135
- /^198\.51\.100\./, # 198.51.100.0 198.51.100.255
136
- /^203\.0\.113\./, # 203.0.113.0 203.0.113.255
137
- /^(22[4-9]|23\d)\./, # 224.0.0.0 239.255.255.255
138
- /^(24\d|25[0-5])\./ # 240.0.0.0 255.255.255.254 and 255.255.255.255
142
+ /^0\./, # 0.0.0.0 - 0.255.255.255
143
+ /^192\.0\.2\./, # 192.0.2.0 - 192.0.2.255
144
+ /^192\.88\.99\./, # 192.88.99.0 - 192.88.99.255
145
+ /^198\.51\.100\./, # 198.51.100.0 - 198.51.100.255
146
+ /^203\.0\.113\./, # 203.0.113.0 - 203.0.113.255
147
+ /^(22[4-9]|23\d)\./, # 224.0.0.0 - 239.255.255.255
148
+ /^(24\d|25[0-5])\./ # 240.0.0.0 - 255.255.255.254 and 255.255.255.255
139
149
  ]
140
150
  end
141
151
 
142
152
  def reserved_net_checker
143
- ->(addr){ (private_nets_regex + reserved_nets_regex).any? { |net| net =~ addr } }
153
+ ->(addr) { (private_nets_regex + reserved_nets_regex).any? { |net| net =~ addr } }
144
154
  end
145
155
 
146
156
  def ip_v4_cidr
147
- "#{ip_v4_address}/#{1 + rand(31)}"
157
+ "#{ip_v4_address}/#{rand(1..31)}"
148
158
  end
149
159
 
150
160
  def ip_v6_address
151
- (1..8).map { rand(65536).to_s(16) }.join(':')
161
+ (1..8).map { rand(65_536).to_s(16) }.join(':')
152
162
  end
153
163
 
154
164
  def ip_v6_cidr
155
- "#{ip_v6_address}/#{1 + rand(127)}"
165
+ "#{ip_v6_address}/#{rand(1..127)}"
156
166
  end
157
167
 
158
- def url(host = domain_name, path = "/#{user_name}", scheme = 'http')
168
+ def url(host = domain_name, path = "/#{username}", scheme = 'http')
159
169
  "#{scheme}://#{host}#{path}"
160
170
  end
161
171
 
162
172
  def slug(words = nil, glue = nil)
163
173
  glue ||= sample(%w[- _ .])
164
- (words || Faker::Lorem::words(2).join(' ')).gsub(' ', glue).downcase
174
+ (words || Faker::Lorem.words(2).join(' ')).delete(',.').gsub(' ', glue).downcase
165
175
  end
166
176
 
167
177
  def device_token
168
- shuffle(rand(16 ** 64).to_s(16).rjust(64, '0').chars.to_a).join
178
+ shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
169
179
  end
170
180
 
171
181
  def user_agent(vendor = nil)
@@ -173,6 +183,8 @@ module Faker
173
183
  agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
174
184
  sample(agents)
175
185
  end
186
+
187
+ alias user_name username
176
188
  end
177
189
  end
178
190
  end