faker 2.11.0 → 2.13.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 (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +160 -0
  3. data/README.md +11 -2
  4. data/lib/faker.rb +16 -10
  5. data/lib/faker/default/address.rb +31 -1
  6. data/lib/faker/default/bank.rb +79 -0
  7. data/lib/faker/default/blood.rb +48 -0
  8. data/lib/faker/default/business.rb +1 -1
  9. data/lib/faker/default/chile_rut.rb +44 -1
  10. data/lib/faker/default/commerce.rb +73 -10
  11. data/lib/faker/default/company.rb +40 -3
  12. data/lib/faker/default/compass.rb +135 -0
  13. data/lib/faker/default/computer.rb +63 -0
  14. data/lib/faker/default/construction.rb +54 -0
  15. data/lib/faker/default/cosmere.rb +90 -0
  16. data/lib/faker/default/crypto_coin.rb +45 -0
  17. data/lib/faker/default/date.rb +16 -12
  18. data/lib/faker/default/driving_licence.rb +42 -0
  19. data/lib/faker/default/file.rb +49 -0
  20. data/lib/faker/default/finance.rb +24 -0
  21. data/lib/faker/default/gender.rb +1 -1
  22. data/lib/faker/default/hipster.rb +94 -0
  23. data/lib/faker/default/id_number.rb +86 -0
  24. data/lib/faker/default/internet.rb +35 -7
  25. data/lib/faker/default/internet_http.rb +48 -0
  26. data/lib/faker/default/invoice.rb +32 -5
  27. data/lib/faker/default/json.rb +55 -0
  28. data/lib/faker/default/lorem_flickr.rb +65 -0
  29. data/lib/faker/default/lorem_pixel.rb +22 -0
  30. data/lib/faker/default/markdown.rb +89 -0
  31. data/lib/faker/default/measurement.rb +90 -0
  32. data/lib/faker/default/name.rb +98 -0
  33. data/lib/faker/default/nhs.rb +19 -0
  34. data/lib/faker/default/number.rb +5 -7
  35. data/lib/faker/default/omniauth.rb +58 -5
  36. data/lib/faker/default/phone_number.rb +88 -5
  37. data/lib/faker/default/placeholdit.rb +21 -0
  38. data/lib/faker/default/slack_emoji.rb +81 -0
  39. data/lib/faker/default/south_africa.rb +90 -0
  40. data/lib/faker/default/string.rb +19 -3
  41. data/lib/faker/default/stripe.rb +61 -0
  42. data/lib/faker/default/twitter.rb +35 -0
  43. data/lib/faker/default/types.rb +80 -0
  44. data/lib/faker/default/university.rb +45 -0
  45. data/lib/faker/default/vehicle.rb +184 -4
  46. data/lib/faker/default/verb.rb +45 -0
  47. data/lib/faker/default/world_cup.rb +4 -4
  48. data/lib/faker/games/control.rb +113 -0
  49. data/lib/faker/games/dnd.rb +61 -0
  50. data/lib/faker/games/heroes_of_the_storm.rb +16 -5
  51. data/lib/faker/games/minecraft.rb +48 -0
  52. data/lib/faker/games/warhammer_fantasy.rb +74 -0
  53. data/lib/faker/movies/departed.rb +49 -0
  54. data/lib/faker/movies/movie.rb +13 -0
  55. data/lib/faker/music/pearl_jam.rb +50 -0
  56. data/lib/faker/music/phish.rb +27 -1
  57. data/lib/faker/music/prince.rb +64 -0
  58. data/lib/faker/music/rush.rb +37 -0
  59. data/lib/faker/music/show.rb +49 -0
  60. data/lib/faker/quotes/quote.rb +54 -1
  61. data/lib/faker/quotes/shakespeare.rb +36 -0
  62. data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +13 -0
  63. data/lib/faker/tv_shows/big_bang_theory.rb +37 -0
  64. data/lib/faker/tv_shows/dr_who.rb +1 -1
  65. data/lib/faker/tv_shows/futurama.rb +65 -0
  66. data/lib/faker/tv_shows/simpsons.rb +14 -0
  67. data/lib/faker/tv_shows/suits.rb +37 -0
  68. data/lib/faker/version.rb +1 -1
  69. data/lib/helpers/base58.rb +1 -1
  70. data/lib/helpers/char.rb +22 -27
  71. data/lib/locales/de-CH.yml +1693 -0
  72. data/lib/locales/en-AU.yml +44 -10
  73. data/lib/locales/en-CA.yml +2 -0
  74. data/lib/locales/en-US.yml +29 -3
  75. data/lib/locales/en/address.yml +2 -0
  76. data/lib/locales/en/aqua_teen_hunger_force.yml +33 -1
  77. data/lib/locales/en/bank.yml +1 -1
  78. data/lib/locales/en/big_bang_theory.yml +38 -0
  79. data/lib/locales/en/blood.yml +13 -0
  80. data/lib/locales/en/computer.yml +36 -0
  81. data/lib/locales/en/control.yml +247 -0
  82. data/lib/locales/en/departed.yml +50 -0
  83. data/lib/locales/en/dnd.yml +54 -0
  84. data/lib/locales/en/futurama.yml +344 -0
  85. data/lib/locales/en/heroes_of_the_storm.yml +2 -2
  86. data/lib/locales/en/house.yml +1 -1
  87. data/lib/locales/en/minecraft.yml +390 -0
  88. data/lib/locales/en/movie.yml +192 -1
  89. data/lib/locales/en/name.yml +3 -2
  90. data/lib/locales/en/one_piece.yml +2 -2
  91. data/lib/locales/en/pearl_jam.yml +213 -0
  92. data/lib/locales/en/phish.yml +392 -1
  93. data/lib/locales/en/prince.yml +227 -0
  94. data/lib/locales/en/rush.yml +32 -0
  95. data/lib/locales/en/show.yml +597 -0
  96. data/lib/locales/en/simpsons.yml +668 -0
  97. data/lib/locales/en/star_wars.yml +568 -220
  98. data/lib/locales/en/suits.yml +45 -0
  99. data/lib/locales/en/warhammer_fantasy.yml +582 -0
  100. data/lib/locales/fr-CA.yml +2 -0
  101. data/lib/locales/ko.yml +82 -0
  102. data/lib/locales/pt-BR.yml +1 -0
  103. metadata +46 -17
@@ -3,6 +3,21 @@
3
3
  module Faker
4
4
  class File < Base
5
5
  class << self
6
+ ##
7
+ # Produces a random directory name.
8
+ #
9
+ # @param segment_count [Integer] Specifies the number of nested folders in the generated string.
10
+ # @param root [String] Specifies the root of the generated string.
11
+ # @param directory_separator [String] Specifies the separator between the segments.
12
+ # @return [String]
13
+ #
14
+ # @example
15
+ # Faker::File.dir #=> "et_error/sint_voluptas/quas_veritatis"
16
+ # Faker::File.dir(segment_count: 2) #=> "ea-suscipit/ut-deleniti"
17
+ # Faker::File.dir(segment_count: 3, root: nil, directory_separator: '/') #=> "est_porro/fugit_eveniet/incidunt-autem"
18
+ # Faker::File.dir(segment_count: 3, root: nil, directory_separator: '\\') #=> "aut-ullam\\quia_quisquam\\ut-eos"
19
+ #
20
+ # @faker.version 1.6.4
6
21
  # rubocop:disable Metrics/ParameterLists
7
22
  def dir(legacy_segment_count = NOT_GIVEN, legacy_root = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, segment_count: 3, root: nil, directory_separator: ::File::Separator)
8
23
  # rubocop:enable Metrics/ParameterLists
@@ -20,14 +35,48 @@ module Faker
20
35
  .squeeze(directory_separator)
21
36
  end
22
37
 
38
+ ##
39
+ # Produces a random file extension.
40
+ #
41
+ # @return [String]
42
+ #
43
+ # @example
44
+ # Faker::File.extension #=> "mp3"
45
+ #
46
+ # @faker.version 1.6.4
23
47
  def extension
24
48
  fetch('file.extension')
25
49
  end
26
50
 
51
+ ##
52
+ # Produces a random mime type.
53
+ #
54
+ # @return [String]
55
+ #
56
+ # @example
57
+ # Faker::File.mime_type #=> "application/pdf"
58
+ #
59
+ # @faker.version 1.6.4
27
60
  def mime_type
28
61
  fetch('file.mime_type')
29
62
  end
30
63
 
64
+ ##
65
+ # Produces a random file name.
66
+ #
67
+ # @param dir [String] Specifies the path used for the generated file.
68
+ # @param name [String] Specifies the filename used for the generated file.
69
+ # @param ext [String] Specifies the extension used the generated file.
70
+ # @param directory_separator [String] Specifies the separator between the directory and name elements.
71
+ # @return [String]
72
+ #
73
+ # @example
74
+ # Faker::File.file_name(dir: 'path/to') #=> "path/to/something_random.jpg"
75
+ # Faker::File.file_name(dir: 'foo/bar', name: 'baz') #=> "foo/bar/baz.zip"
76
+ # Faker::File.file_name(dir: 'foo/bar', name: 'baz', ext: 'doc') #=> "foo/bar/baz.doc"
77
+ # Faker::File.file_name(dir: 'foo/bar', name: 'baz', ext: 'mp3', directory_separator: '\\') #=> "foo/bar\\baz.mp3"
78
+ #
79
+ # @faker.version 1.6.4
31
80
  # rubocop:disable Metrics/ParameterLists
32
81
  def file_name(legacy_dir = NOT_GIVEN, legacy_name = NOT_GIVEN, legacy_ext = NOT_GIVEN, legacy_directory_separator = NOT_GIVEN, dir: nil, name: nil, ext: nil, directory_separator: ::File::Separator)
33
82
  # rubocop:enable Metrics/ParameterLists
@@ -7,6 +7,18 @@ module Faker
7
7
  maestro forbrugsforeningen laser].freeze
8
8
 
9
9
  class << self
10
+ ##
11
+ # Produces a random credit card number.
12
+ #
13
+ # @param types [String] Specific credit card type.
14
+ # @return [String]
15
+ #
16
+ # @example
17
+ # Faker::Finance.credit_card #=> "3018-348979-1853"
18
+ # Faker::Finance.credit_card(:mastercard) #=> "6771-8921-2291-6236"
19
+ # Faker::Finance.credit_card(:mastercard, :visa) #=> "4448-8934-1277-7195"
20
+ #
21
+ # @faker.version 1.2.0
10
22
  def credit_card(*types)
11
23
  types = CREDIT_CARD_TYPES if types.empty?
12
24
  type = sample(types)
@@ -26,6 +38,18 @@ module Faker
26
38
  template.gsub('L', luhn_digit.to_s)
27
39
  end
28
40
 
41
+ ##
42
+ # Produces a random vat number.
43
+ #
44
+ # @param country [String] Two capital letter country code to use for the vat number.
45
+ # @return [String]
46
+ #
47
+ # @example
48
+ # Faker::Finance.vat_number #=> "BR38.395.329/2471-83"
49
+ # Faker::Finance.vat_number('DE') #=> "DE593306671"
50
+ # Faker::Finance.vat_number('ZA') #=> "ZA79494416181"
51
+ #
52
+ # @faker.version 1.9.2
29
53
  def vat_number(legacy_country = NOT_GIVEN, country: 'BR')
30
54
  warn_for_deprecated_arguments do |keywords|
31
55
  keywords << :country if legacy_country != NOT_GIVEN
@@ -37,7 +37,7 @@ module Faker
37
37
  # @example
38
38
  # Faker::Gender.short_binary_type #=> "f"
39
39
  #
40
- # @faker.version next
40
+ # @faker.version 2.13.0
41
41
  def short_binary_type
42
42
  fetch('gender.short_binary_types')
43
43
  end
@@ -3,11 +3,35 @@
3
3
  module Faker
4
4
  class Hipster < Base
5
5
  class << self
6
+ ##
7
+ # Produces a random hipster word.
8
+ #
9
+ # @return [String]
10
+ #
11
+ # @example
12
+ # Faker::Hipster.word #=> "irony"
13
+ #
14
+ # @faker.version 1.6.0
6
15
  def word
7
16
  random_word = sample(translate('faker.hipster.words'))
8
17
  random_word =~ /\s/ ? word : random_word
9
18
  end
10
19
 
20
+ ##
21
+ # Produces a random hipster word.
22
+ #
23
+ # @param number [Integer] Specifies the number of words returned
24
+ # @param supplemental [Boolean] Specifies if the words are supplemental
25
+ # @param spaces_allowed [Boolean] Specifies if the words may contain spaces
26
+ # @return [Array<String>]
27
+ #
28
+ # @example
29
+ # Faker::Hipster.words #=> ["pug", "pitchfork", "chia"]
30
+ # Faker::Hipster.words(number: 4) #=> ["ugh", "cardigan", "poutine", "stumptown"]
31
+ # Faker::Hipster.words(number: 4, supplemental: true) #=> ["iste", "seitan", "normcore", "provident"]
32
+ # Faker::Hipster.words(number: 4, supplemental: true, spaces_allowed: true) #=> ["qui", "magni", "craft beer", "est"]
33
+ #
34
+ # @faker.version 1.6.0
11
35
  # rubocop:disable Metrics/ParameterLists
12
36
  def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false)
13
37
  # rubocop:enable Metrics/ParameterLists
@@ -30,6 +54,22 @@ module Faker
30
54
  words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
31
55
  end
32
56
 
57
+ ##
58
+ # Produces a random hipster sentence.
59
+ #
60
+ # @param word_count [Integer] Specifies the number of words in the sentence
61
+ # @param supplemental [Boolean] Specifies if the words are supplemental
62
+ # @param random_words_to_add [Boolean] Specifies the number of random words to add
63
+ # @return [String]
64
+ #
65
+ # @example
66
+ # Faker::Hipster.sentence #=> "Park iphone leggings put a bird on it."
67
+ # Faker::Hipster.sentence(word_count: 3) #=> "Pour-over swag godard."
68
+ # Faker::Hipster.sentence(word_count: 3, supplemental: true) #=> "Beard laboriosam sequi celiac."
69
+ # Faker::Hipster.sentence(word_count: 3, supplemental: false, random_words_to_add: 4) #=> "Bitters retro mustache aesthetic biodiesel 8-bit."
70
+ # Faker::Hipster.sentence(word_count: 3, supplemental: true, random_words_to_add: 4) #=> "Occaecati deleniti messenger bag meh crucifix autem."
71
+ #
72
+ # @faker.version 1.6.0
33
73
  # rubocop:disable Metrics/ParameterLists
34
74
  def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 6)
35
75
  # rubocop:enable Metrics/ParameterLists
@@ -42,6 +82,19 @@ module Faker
42
82
  words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.'
43
83
  end
44
84
 
85
+ ##
86
+ # Produces random hipster sentences.
87
+ #
88
+ # @param number [Integer] Specifies the number of sentences returned
89
+ # @param supplemental [Boolean] Specifies if the words are supplemental
90
+ # @return [Array<String>]
91
+ #
92
+ # @example
93
+ # Faker::Hipster.sentences #=> ["Godard pitchfork vinegar chillwave everyday 90's whatever.", "Pour-over artisan distillery street waistcoat.", "Salvia yr leggings franzen blue bottle."]
94
+ # Faker::Hipster.sentences(number: 1) #=> ["Before they sold out pinterest venmo umami try-hard ugh hoodie artisan."]
95
+ # Faker::Hipster.sentences(number: 1, supplemental: true) #=> ["Et sustainable optio aesthetic et."]
96
+ #
97
+ # @faker.version 1.6.0
45
98
  def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
46
99
  warn_for_deprecated_arguments do |keywords|
47
100
  keywords << :number if legacy_number != NOT_GIVEN
@@ -55,6 +108,22 @@ module Faker
55
108
  end
56
109
  end
57
110
 
111
+ ##
112
+ # Produces a random hipster paragraph.
113
+ #
114
+ # @param sentence_count [Integer] Specifies the number of sentences in the paragraph
115
+ # @param supplemental [Boolean] Specifies if the words are supplemental
116
+ # @param random_sentences_to_add [Boolean] Specifies the number of random sentences to add
117
+ # @return [String]
118
+ #
119
+ # @example
120
+ # Faker::Hipster.paragraph #=> "Migas fingerstache pbr&b tofu. Polaroid distillery typewriter echo tofu actually. Slow-carb fanny pack pickled direct trade scenester mlkshk plaid. Banjo venmo chambray cold-pressed typewriter. Fap skateboard intelligentsia."
121
+ # Faker::Hipster.paragraph(sentence_count: 2) #=> "Yolo tilde farm-to-table hashtag. Lomo kitsch disrupt forage +1."
122
+ # Faker::Hipster.paragraph(sentence_count: 2, supplemental: true) #=> "Typewriter iste ut viral kombucha voluptatem. Sint voluptates saepe. Direct trade irony chia excepturi yuccie. Biodiesel esse listicle et quam suscipit."
123
+ # Faker::Hipster.paragraph(sentence_count: 2, supplemental: false, random_sentences_to_add: 4) #=> "Selvage vhs chartreuse narwhal vinegar. Authentic vinyl truffaut carry vhs pop-up. Hammock everyday iphone locavore thundercats bitters vegan goth. Fashion axe banh mi shoreditch whatever artisan."
124
+ # Faker::Hipster.paragraph(sentence_count: 2, supplemental: true, random_sentences_to_add: 4) #=> "Deep v gluten-free unde waistcoat aperiam migas voluptas dolorum. Aut drinking illo sustainable sapiente. Direct trade fanny pack kale chips ennui semiotics."
125
+ #
126
+ # @faker.version 1.6.0
58
127
  # rubocop:disable Metrics/ParameterLists
59
128
  def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
60
129
  # rubocop:enable Metrics/ParameterLists
@@ -67,6 +136,19 @@ module Faker
67
136
  sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
68
137
  end
69
138
 
139
+ ##
140
+ # Produces random hipster paragraphs.
141
+ #
142
+ # @param number [Integer] Specifies the number of paragraphs
143
+ # @param supplemental [Boolean] Specifies if the words are supplemental
144
+ # @return [Array<String>]
145
+ #
146
+ # @example
147
+ # Faker::Hipster.paragraphs #=> ["Tilde microdosing blog cliche meggings. Intelligentsia five dollar toast forage yuccie. Master kitsch knausgaard. Try-hard everyday trust fund mumblecore.", "Normcore viral pickled. Listicle humblebrag swag tote bag. Taxidermy street hammock neutra butcher cred kale chips. Blog portland humblebrag trust fund irony.", "Single-origin coffee fixie cleanse tofu xoxo. Post-ironic tote bag ramps gluten-free locavore mumblecore hammock. Umami loko twee. Ugh kitsch before they sold out."]
148
+ # Faker::Hipster.paragraphs(number: 1) #=> ["Skateboard cronut synth +1 fashion axe. Pop-up polaroid skateboard asymmetrical. Ennui fingerstache shoreditch before they sold out. Tattooed pitchfork ramps. Photo booth yr messenger bag raw denim bespoke locavore lomo synth."]
149
+ # Faker::Hipster.paragraphs(number: 1, supplemental: true) #=> ["Quae direct trade pbr&b quo taxidermy autem loko. Umami quas ratione migas cardigan sriracha minima. Tenetur perspiciatis pickled sed eum doloribus truffaut. Excepturi dreamcatcher meditation."]
150
+ #
151
+ # @faker.version 1.6.0
70
152
  def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
71
153
  warn_for_deprecated_arguments do |keywords|
72
154
  keywords << :number if legacy_number != NOT_GIVEN
@@ -80,6 +162,18 @@ module Faker
80
162
  end
81
163
  end
82
164
 
165
+ ##
166
+ # Produces a random hipster paragraph by characters.
167
+ #
168
+ # @param characters [Integer] Specifies the number of characters in the paragraph
169
+ # @param supplemental [Boolean] Specifies if the words are supplemental
170
+ # @return [String]
171
+ #
172
+ # @example
173
+ # Faker::Hipster.paragraph_by_chars #=> "Truffaut stumptown trust fund 8-bit messenger bag portland. Meh kombucha selvage swag biodiesel. Lomo kinfolk jean shorts asymmetrical diy. Wayfarers portland twee stumptown. Wes anderson biodiesel retro 90's pabst. Diy echo 90's mixtape semiotics. Cornho."
174
+ # Faker::Hipster.paragraph_by_chars(characters: 256, supplemental: false) #=> "Hella kogi blog narwhal sartorial selfies mustache schlitz. Bespoke normcore kitsch cred hella fixie. Park aesthetic fixie migas twee. Cliche mustache brunch tumblr fixie godard. Drinking pop-up synth hoodie dreamcatcher typewriter. Kitsch biodiesel green."
175
+ #
176
+ # @faker.version 1.6.0
83
177
  def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false)
84
178
  warn_for_deprecated_arguments do |keywords|
85
179
  keywords << :characters if legacy_characters != NOT_GIVEN
@@ -19,10 +19,28 @@ module Faker
19
19
  CHILEAN_MODULO = 11
20
20
 
21
21
  class << self
22
+ ##
23
+ # Produces a random valid US Social Security number.
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faker::IDNumber.valid #=> "552-56-3593"
29
+ #
30
+ # @faker.version 1.6.0
22
31
  def valid
23
32
  _translate('valid')
24
33
  end
25
34
 
35
+ ##
36
+ # Produces a random invalid US Social Security number.
37
+ #
38
+ # @return [String]
39
+ #
40
+ # @example
41
+ # Faker::IDNumber.invalid #=> "311-72-0000"
42
+ #
43
+ # @faker.version 1.6.0
26
44
  def invalid
27
45
  _translate('invalid')
28
46
  end
@@ -33,6 +51,15 @@ module Faker
33
51
  INVALID_SSN.any? { |regex| regex =~ ssn } ? ssn_valid : ssn
34
52
  end
35
53
 
54
+ ##
55
+ # Produces a random Spanish citizen identifier (DNI).
56
+ #
57
+ # @return [String]
58
+ #
59
+ # @example
60
+ # Faker::IDNumber.spanish_citizen_number #=> "53290236-H"
61
+ #
62
+ # @faker.version 1.9.0
36
63
  def spanish_citizen_number
37
64
  num = Faker::Number.number(digits: 8)
38
65
  mod = num.to_i % 23
@@ -40,6 +67,15 @@ module Faker
40
67
  "#{num}-#{check}"
41
68
  end
42
69
 
70
+ ##
71
+ # Produces a random Spanish foreign born citizen identifier (NIE).
72
+ #
73
+ # @return [String]
74
+ #
75
+ # @example
76
+ # Faker::IDNumber.spanish_foreign_citizen_number #=> "Z-1600870-Y"
77
+ #
78
+ # @faker.version 1.9.0
43
79
  def spanish_foreign_citizen_number
44
80
  code = 'XYZ'
45
81
  digits = Faker::Number.number(digits: 7)
@@ -50,6 +86,16 @@ module Faker
50
86
  "#{prefix}-#{digits}-#{check}"
51
87
  end
52
88
 
89
+ ##
90
+ # Produces a random valid South African ID Number.
91
+ #
92
+ # @return [String]
93
+ #
94
+ # @example
95
+ # Faker::IDNumber.south_african_id_number #=> "8105128870184"
96
+ # Faker::IDNumber.valid_south_african_id_number #=> "8105128870184"
97
+ #
98
+ # @faker.version 1.9.2
53
99
  def valid_south_african_id_number
54
100
  id_number = [
55
101
  Faker::Date.birthday.strftime('%y%m%d'),
@@ -63,6 +109,15 @@ module Faker
63
109
 
64
110
  alias south_african_id_number valid_south_african_id_number
65
111
 
112
+ ##
113
+ # Produces a random invalid South African ID Number.
114
+ #
115
+ # @return [String]
116
+ #
117
+ # @example
118
+ # Faker::IDNumber.invalid_south_african_id_number #=> "1642972065088"
119
+ #
120
+ # @faker.version 1.9.2
66
121
  def invalid_south_african_id_number
67
122
  invalid_date_of_birth = [
68
123
  Faker::Number.number(digits: 2),
@@ -80,6 +135,17 @@ module Faker
80
135
  [id_number, south_african_id_checksum_digit(id_number)].join
81
136
  end
82
137
 
138
+ ##
139
+ # Produces a random Brazilian Citizen Number (CPF).
140
+ #
141
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
142
+ # @return [String]
143
+ #
144
+ # @example
145
+ # Faker::IDNumber.brazilian_citizen_number #=> "53540542221"
146
+ # Faker::IDNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21"
147
+ #
148
+ # @faker.version 1.9.2
83
149
  def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
84
150
  warn_for_deprecated_arguments do |keywords|
85
151
  keywords << :formatted if legacy_formatted != NOT_GIVEN
@@ -94,6 +160,17 @@ module Faker
94
160
 
95
161
  alias brazilian_cpf brazilian_citizen_number
96
162
 
163
+ ##
164
+ # Produces a random Brazilian ID Number (RG).
165
+ #
166
+ # @param formatted [Boolean] Specifies if the number is formatted with dividers.
167
+ # @return [String]
168
+ #
169
+ # @example
170
+ # Faker::IDNumber.brazilian_id #=> "493054029"
171
+ # Faker::IDNumber.brazilian_id(formatted: true) #=> "49.305.402-9"
172
+ #
173
+ # @faker.version 2.1.2
97
174
  def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
98
175
  warn_for_deprecated_arguments do |keywords|
99
176
  keywords << :formatted if legacy_formatted != NOT_GIVEN
@@ -107,6 +184,15 @@ module Faker
107
184
 
108
185
  alias brazilian_rg brazilian_id
109
186
 
187
+ ##
188
+ # Produces a random Chilean ID (Rut with 8 digits).
189
+ #
190
+ # @return [String]
191
+ #
192
+ # @example
193
+ # Faker::IDNumber.chilean_id #=> "15620613-K"
194
+ #
195
+ # @faker.version 2.1.2
110
196
  def chilean_id
111
197
  digits = Faker::Number.number(digits: 8)
112
198
  verification_code = chilean_verification_code(digits)
@@ -9,11 +9,14 @@ module Faker
9
9
  keywords << :separators if legacy_separators != NOT_GIVEN
10
10
  end
11
11
 
12
- if separators
13
- [username(specifier: name, separators: separators), domain_name(domain: domain)].join('@')
14
- else
15
- [username(specifier: name), domain_name(domain: domain)].join('@')
16
- end
12
+ local_part = if separators
13
+ username(specifier: name, separators: separators)
14
+ else
15
+ username(specifier: name)
16
+ end
17
+
18
+ sanitized_local_part = sanitize_email_local_part(local_part)
19
+ construct_email(sanitized_local_part, domain_name(domain: domain))
17
20
  end
18
21
 
19
22
  def free_email(legacy_name = NOT_GIVEN, name: nil)
@@ -21,7 +24,10 @@ module Faker
21
24
  keywords << :name if legacy_name != NOT_GIVEN
22
25
  end
23
26
 
24
- [username(specifier: name), fetch('internet.free_email')].join('@')
27
+ construct_email(
28
+ sanitize_email_local_part(username(specifier: name)),
29
+ fetch('internet.free_email')
30
+ )
25
31
  end
26
32
 
27
33
  def safe_email(legacy_name = NOT_GIVEN, name: nil)
@@ -29,7 +35,10 @@ module Faker
29
35
  keywords << :name if legacy_name != NOT_GIVEN
30
36
  end
31
37
 
32
- [username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
38
+ construct_email(
39
+ sanitize_email_local_part(username(specifier: name)),
40
+ 'example.' + sample(%w[org com net])
41
+ )
33
42
  end
34
43
 
35
44
  def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
@@ -325,6 +334,25 @@ module Faker
325
334
  end
326
335
 
327
336
  alias user_name username
337
+
338
+ private
339
+
340
+ def sanitize_email_local_part(local_part)
341
+ char_range = [
342
+ Array('0'..'9'),
343
+ Array('A'..'Z'),
344
+ Array('a'..'z'),
345
+ "!#$%&'*+-/=?^_`{|}~.".split(//)
346
+ ].flatten
347
+
348
+ local_part.split(//).map do |char|
349
+ char_range.include?(char) ? char : '#'
350
+ end.join
351
+ end
352
+
353
+ def construct_email(local_part, domain_name)
354
+ [local_part, domain_name].join('@')
355
+ end
328
356
  end
329
357
  end
330
358
  end