faker 3.0.0 → 3.5.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +598 -1
- data/README.md +203 -107
- data/lib/faker/books/lovecraft.rb +2 -3
- data/lib/faker/default/address.rb +2 -2
- data/lib/faker/default/alphanumeric.rb +1 -1
- data/lib/faker/default/chile_rut.rb +23 -17
- data/lib/faker/default/code.rb +65 -19
- data/lib/faker/default/company.rb +112 -5
- data/lib/faker/default/crypto.rb +13 -4
- data/lib/faker/default/date.rb +61 -5
- data/lib/faker/default/driving_licence.rb +19 -8
- data/lib/faker/default/drone.rb +1 -1
- data/lib/faker/default/finance.rb +2 -2
- data/lib/faker/default/food.rb +14 -1
- data/lib/faker/default/hipster.rb +2 -3
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +38 -24
- data/lib/faker/default/internet.rb +85 -78
- data/lib/faker/default/invoice.rb +4 -4
- data/lib/faker/default/json.rb +9 -4
- data/lib/faker/default/lorem.rb +24 -16
- data/lib/faker/default/marketing.rb +1 -1
- data/lib/faker/default/measurement.rb +8 -8
- data/lib/faker/default/{nhs.rb → national_health_service.rb} +8 -4
- data/lib/faker/default/number.rb +1 -1
- data/lib/faker/default/omniauth.rb +5 -5
- data/lib/faker/default/phone_number.rb +37 -18
- data/lib/faker/default/placeholdit.rb +1 -1
- data/lib/faker/default/south_africa.rb +3 -3
- data/lib/faker/{music/show.rb → default/theater.rb} +8 -8
- data/lib/faker/default/twitter.rb +4 -6
- data/lib/faker/default/types.rb +5 -6
- data/lib/faker/default/vehicle.rb +26 -36
- data/lib/faker/games/clash_of_clans.rb +1 -1
- data/lib/faker/games/dnd.rb +49 -7
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/heroes_of_the_storm.rb +0 -11
- data/lib/faker/games/minecraft.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/japanese_media/cowboy_bebop.rb +61 -0
- data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +10 -10
- data/lib/faker/locations/australia.rb +40 -38
- data/lib/faker/movies/avatar.rb +49 -0
- data/lib/faker/movies/star_wars.rb +1 -1
- data/lib/faker/movies/{room.rb → the_room.rb} +4 -4
- data/lib/faker/music/smashing_pumpkins.rb +64 -0
- data/lib/faker/quotes/quote.rb +13 -0
- data/lib/faker/sports/chess.rb +90 -0
- data/lib/faker/sports/sport.rb +9 -3
- data/lib/faker/travel/airport.rb +43 -0
- data/lib/faker/travel/train_station.rb +54 -0
- data/lib/faker/tv_shows/archer.rb +51 -0
- data/lib/faker/tv_shows/buffy.rb +0 -13
- data/lib/faker/tv_shows/dr_who.rb +0 -13
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/tv_shows/spongebob.rb +50 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +0 -13
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +20 -9
- data/lib/helpers/deprecator.rb +118 -0
- data/lib/helpers/positional_generator.rb +480 -0
- data/lib/locales/README.md +18 -2
- data/lib/locales/ar.yml +1 -0
- data/lib/locales/bg.yml +1 -2
- data/lib/locales/da-DK.yml +529 -35
- data/lib/locales/de-AT.yml +3487 -27
- data/lib/locales/de-CH.yml +4359 -12
- data/lib/locales/de.yml +7182 -100
- data/lib/locales/ee.yml +0 -1
- data/lib/locales/en/address.yml +1826 -561
- data/lib/locales/en/airport.yml +381 -0
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/australia.yml +106 -105
- data/lib/locales/en/avatar.yml +31 -0
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/chess.yml +103 -0
- data/lib/locales/en/company.yml +1 -0
- data/lib/locales/en/cosmere.yml +1 -1
- data/lib/locales/en/cowboy_bebop.yml +163 -0
- data/lib/locales/en/dnd.yml +186 -1
- data/lib/locales/en/dog.yml +262 -7
- data/lib/locales/en/dota.yml +120 -67
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/finance.yml +4 -4
- data/lib/locales/en/food.yml +14 -1
- data/lib/locales/en/{fma_brotherhood.yml → fullmetal_alchemist_brotherhood.yml} +3 -3
- data/lib/locales/en/harry_potter.yml +1 -1
- data/lib/locales/en/heroes.yml +0 -0
- data/lib/locales/en/id_number.yml +1 -1
- data/lib/locales/en/internet.yml +3 -4
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/mitch_hedberg.yml +46 -0
- data/lib/locales/en/music.yml +25 -25
- data/lib/locales/en/opera.yml +1 -1
- data/lib/locales/en/phone_number.yml +78 -3
- data/lib/locales/en/restaurant.yml +1 -1
- data/lib/locales/en/smashing_pumpkins.yml +382 -0
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/spongebob.yml +489 -0
- data/lib/locales/en/star_wars.yml +1 -1
- data/lib/locales/en/{room.yml → the_room.yml} +1 -1
- data/lib/locales/en/{show.yml → theater.yml} +1 -1
- data/lib/locales/en/train_station.yml +280 -0
- data/lib/locales/en/vehicle.yml +1 -1
- data/lib/locales/en-AU.yml +718 -47
- data/lib/locales/en-CA.yml +373 -19
- data/lib/locales/en-GB.yml +116 -8
- data/lib/locales/en-IND.yml +1259 -17
- data/lib/locales/en-KE.yml +212 -0
- data/lib/locales/en-MS.yml +364 -17
- data/lib/locales/en-NEP.yml +212 -38
- data/lib/locales/en-NG.yml +1 -0
- data/lib/locales/en-NZ.yml +1153 -123
- data/lib/locales/en-PAK.yml +392 -10
- data/lib/locales/en-SG.yml +581 -16
- data/lib/locales/en-UG.yml +1 -0
- data/lib/locales/en-US.yml +6914 -74
- data/lib/locales/en-ZA.yml +1 -1
- data/lib/locales/en-au-ocker.yml +266 -22
- data/lib/locales/es-AR.yml +4569 -4599
- data/lib/locales/es-MX.yml +1 -2
- data/lib/locales/es.yml +2 -3
- data/lib/locales/fi-FI.yml +1 -0
- data/lib/locales/fr/address.yml +761 -9
- data/lib/locales/fr/internet.yml +0 -1
- data/lib/locales/fr/name.yml +2 -1
- data/lib/locales/fr-CA.yml +2733 -44
- data/lib/locales/fr-CH.yml +1 -2
- data/lib/locales/fr.yml +3 -1
- data/lib/locales/hy.yml +3624 -119
- data/lib/locales/id.yml +839 -12
- data/lib/locales/it.yml +1304 -32
- data/lib/locales/ja/book.yml +492 -3
- data/lib/locales/ja/football.yml +115 -0
- data/lib/locales/ja/lorem.yml +1 -1
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ja/super_mario.yml +1 -1
- data/lib/locales/ja/touhou.yml +466 -0
- data/lib/locales/ko.yml +1361 -20
- data/lib/locales/lt.yml +297 -17
- data/lib/locales/lv.yml +0 -1
- data/lib/locales/mi-NZ.yml +2 -0
- data/lib/locales/nb-NO.yml +518 -29
- data/lib/locales/nl.yml +10 -2
- data/lib/locales/pl.yml +1 -2
- data/lib/locales/pt-BR.yml +8205 -664
- data/lib/locales/pt.yml +844 -45
- data/lib/locales/ru.yml +1353 -69
- data/lib/locales/sk.yml +4410 -43
- data/lib/locales/sv.yml +100 -0
- data/lib/locales/tr.yml +1 -2
- data/lib/locales/uk.yml +1808 -44
- data/lib/locales/vi.yml +1 -0
- data/lib/locales/zh-CN/bank.yml +17 -0
- data/lib/locales/zh-CN.yml +1 -0
- data/lib/locales/zh-TW.yml +1 -0
- metadata +37 -156
- data/History.md +0 -176
- data/lib/faker/default/fillmurray.rb +0 -36
- data/lib/faker/default/lorem_pixel.rb +0 -64
@@ -0,0 +1,230 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faker
|
4
|
+
class HTML < Base
|
5
|
+
class << self
|
6
|
+
##
|
7
|
+
# Produces a random HTML header format.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::HTML.heading #=> "<h5>Autem</h5>"
|
13
|
+
#
|
14
|
+
# @faker.version 3.2.1
|
15
|
+
def heading
|
16
|
+
level = rand(1..6)
|
17
|
+
"<h#{level}>#{Lorem.word.capitalize}</h#{level}>"
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Produces a random HTML paragraph format.
|
22
|
+
#
|
23
|
+
# @param sentence_count [Integer] The number of sentences in the paragraph.
|
24
|
+
# @param supplemental [Boolean] Include supplemental text.
|
25
|
+
# @param random_sentences_to_add [Integer] The number of random sentences to add to the paragraph.
|
26
|
+
# @param exclude_words [Array<String>] Words to exclude from the generated paragraph.
|
27
|
+
# @return [String]
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# Faker::HTML.paragraph #=> "<p>Incidunt atque quis</p>"
|
31
|
+
#
|
32
|
+
# @faker.version 3.2.1
|
33
|
+
def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0, exclude_words: nil)
|
34
|
+
"<p>#{Faker::Lorem.paragraph(sentence_count: sentence_count, supplemental: supplemental, random_sentences_to_add: random_sentences_to_add, exclude_words: exclude_words)}</p>"
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Produces a random emphasis formatting on a random word in two HTML paragraphs.
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# Faker::HTML.emphasis #=> "<em>repellat id impedit</em>"
|
44
|
+
#
|
45
|
+
# @faker.version 3.2.1
|
46
|
+
def emphasis
|
47
|
+
"<em>#{Faker::Lorem.paragraph(sentence_count: 1)}</em>"
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Produces a random ordered list in HTML format, with at least one element.
|
52
|
+
#
|
53
|
+
# @return [String]
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# Faker::HTML.ordered_list #=> "<ol>\n<li>Qui reiciendis non consequatur atque.</li>\n<li>Quo doloremque veritatis tempora aut.</li>\n<li>Aspernatur.</li>\n<li>Ea ab.</li>\n<li>Qui.</li>\n<li>Sit pariatur nemo eveniet.</li>\n<li>Molestiae aut.</li>\n<li>Nihil molestias iure placeat.</li>\n<li>Dolore autem quisquam.</li>\n</ol>"
|
57
|
+
#
|
58
|
+
# @faker.version 3.2.1
|
59
|
+
def ordered_list
|
60
|
+
number = rand(1..10)
|
61
|
+
|
62
|
+
items = []
|
63
|
+
number.times do
|
64
|
+
items << "<li>#{Faker::Lorem.sentence(word_count: 1)}</li>"
|
65
|
+
end
|
66
|
+
|
67
|
+
"<ol>\n#{items.join("\n")}\n</ol>"
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Produces a random unordered list of items between 1 and 10 randomly in HTML format.
|
72
|
+
#
|
73
|
+
# @return [String]
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# Faker::HTML.unordered_list #=> "<ul>\n<li>Voluptatum aliquid tempora molestiae facilis non sed.</li>\n<li>Nostrum omnis iste impedit voluptatum dolor.</li>\n<li>Esse quidem et facere.</li>\n</ul>"
|
77
|
+
#
|
78
|
+
# @faker.version 3.2.1
|
79
|
+
def unordered_list
|
80
|
+
number = rand(1..10)
|
81
|
+
|
82
|
+
items = []
|
83
|
+
number.times do
|
84
|
+
items << "<li>#{Faker::Lorem.sentence(word_count: 1)}</li>"
|
85
|
+
end
|
86
|
+
|
87
|
+
"<ul>\n#{items.join("\n")}\n</ul>"
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Produces a random code block formatted in HTML.
|
92
|
+
#
|
93
|
+
# @return [String]
|
94
|
+
#
|
95
|
+
# @example
|
96
|
+
# Faker::HTML.code #=> "<code>Eos quasi qui.</code>"
|
97
|
+
#
|
98
|
+
# @faker.version 3.2.1
|
99
|
+
def code
|
100
|
+
"<code>#{Lorem.sentence(word_count: 1)}</code>"
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Produces a random HTML table.
|
105
|
+
#
|
106
|
+
# @return [String]
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# Faker::HTML.table #=> "<table>\n<thead>\n<th>ad</th>\n<th>similique</th>\n<th>voluptatem</th>\n</thead>\n<tbody>\n<td>corrupti</td>\n<td>est</td>\n<td>rerum</td>\n<td>molestiae</td>\n<td>quidem</td>\n<td>et</td>\n<td>in</td>\n<td>tempora</td>\n<td>at</td>\n<\tbody>\n<tfoot>\n<td>voluptatem</td>\n<td>debitis</td>\n<td>rem</td>\n</tfoot>\n</table>"
|
110
|
+
#
|
111
|
+
# @faker.version 3.2.1
|
112
|
+
def table
|
113
|
+
header_row = generate_table_row('th', 3)
|
114
|
+
footer_row = generate_table_row('td', 3)
|
115
|
+
|
116
|
+
body_rows = []
|
117
|
+
3.times do
|
118
|
+
row = generate_table_row('td', 3)
|
119
|
+
body_rows << row
|
120
|
+
end
|
121
|
+
|
122
|
+
thead = "<thead>\n#{header_row}</thead>"
|
123
|
+
tbody = "<tbody>\n#{body_rows.join("\n")}</tbody>"
|
124
|
+
tfoot = "<tfoot>\n#{footer_row}</tfoot>"
|
125
|
+
|
126
|
+
"<table>\n#{thead}\n#{tbody}\n#{tfoot}\n</table>"
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Generates a random <script> tag with the `src` attribute set to a random URL.
|
131
|
+
#
|
132
|
+
# @return [String]
|
133
|
+
#
|
134
|
+
# @example
|
135
|
+
# Faker::HTML.script #=> "<script src=\"http://gulgowski.name/jordan.weimann.js\"></script>"
|
136
|
+
#
|
137
|
+
# @faker.version 3.2.1
|
138
|
+
def script
|
139
|
+
"<script src=\"#{Faker::Internet.url}.js\"></script>"
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Generates a random <link> tag with the `rel` attribute set to "stylesheet" and the `href` attribute set to a random URL.
|
144
|
+
#
|
145
|
+
# @param rel [String] The rel of the link tag.
|
146
|
+
# @return [String]
|
147
|
+
#
|
148
|
+
# @example
|
149
|
+
# Faker::HTML.link #=> "<link rel=\"stylesheet\" href=\"http://fay.io/darryl.barrows.css\">"
|
150
|
+
#
|
151
|
+
# @faker.version 3.2.1
|
152
|
+
def link(rel: 'stylesheet')
|
153
|
+
"<link rel=\"#{rel}\" href=\"#{Faker::Internet.url}.css\">"
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Generates HTML content with customizable attributes for any HTML tag.
|
158
|
+
#
|
159
|
+
# @param tag [String] The HTML tag to generate.
|
160
|
+
# @param content [String] The Content of the HTML tag.
|
161
|
+
# @param attributes [Hash] The attributes to include in the tag.
|
162
|
+
# @return [String]
|
163
|
+
#
|
164
|
+
# @example
|
165
|
+
# Faker::HTML.element(tag: 'div', content: "This is a div with XSS attributes.", attributes: {class: 'xss', onclick: "alert('XSS')"}) #=> "<div class=\"xss\" onclick=\"alert('XSS')\">This is a div with XSS attributes.</div>"
|
166
|
+
#
|
167
|
+
# @faker.version 3.2.1
|
168
|
+
def element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { class: Lorem.word, onclick: "#{Lorem.word}()" })
|
169
|
+
attribute_string = attributes.map { |key, value| "#{key}=\"#{value}\"" }.join(' ')
|
170
|
+
"<#{tag} #{attribute_string}>#{content}</#{tag}>"
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# Produces a random method from the methods above, excluding the methods listed in the arguments.
|
175
|
+
#
|
176
|
+
# @overload random(methods)
|
177
|
+
# @param methods [Symbol] Specify which methods to exclude.
|
178
|
+
#
|
179
|
+
# @return [String]
|
180
|
+
#
|
181
|
+
# @example
|
182
|
+
# Faker::HTML.random #=> returns output from a single method outlined above
|
183
|
+
# Faker::HTML.random(exclude: [:table]) #=> returns output from any single method outlined above except for "table"
|
184
|
+
# Faker::HTML.random(exclude: [:ordered_list, :unordered_list]) #=> returns output from any single method outlined above except for either ordered_list and unordered_list
|
185
|
+
#
|
186
|
+
# @faker.version 3.2.1
|
187
|
+
def random(exclude: [])
|
188
|
+
method_list = available_methods
|
189
|
+
exclude.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
|
190
|
+
send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
|
191
|
+
end
|
192
|
+
|
193
|
+
##
|
194
|
+
# Generates a random HTML content sandwich, starting with a header, followed by paragraphs, and random elements.
|
195
|
+
#
|
196
|
+
# @param sentences [Integer] The number of sentences in each paragraph.
|
197
|
+
# @param repeat [Integer] The number of times to repeat the pattern (header, paragraph, random).
|
198
|
+
# @return [String]
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# Faker::HTML.sandwich(sentences: 3, repeat: 2) #=> returns a sandwich of HTML content with 2 repetitions, each having a header, paragraph, and random element
|
202
|
+
#
|
203
|
+
# @faker.version 3.2.1
|
204
|
+
def sandwich(sentences: 3, repeat: 1)
|
205
|
+
text_block = []
|
206
|
+
text_block << heading
|
207
|
+
repeat.times do
|
208
|
+
text_block << paragraph(sentence_count: sentences)
|
209
|
+
text_block << random(exclude: %i[script link])
|
210
|
+
end
|
211
|
+
text_block.join("\n")
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def available_methods
|
217
|
+
(HTML.public_methods(false) - Base.methods).sort
|
218
|
+
end
|
219
|
+
|
220
|
+
def generate_table_row(tag, cell_count)
|
221
|
+
row = "<tr>\n"
|
222
|
+
cell_count.times do
|
223
|
+
row += "<#{tag == 'th' ? 'th' : 'td'}>#{Lorem.word}</#{tag == 'th' ? 'th' : 'td'}>\n"
|
224
|
+
end
|
225
|
+
row += "</tr>\n"
|
226
|
+
row
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Faker
|
4
|
-
class
|
4
|
+
class IdNumber < Base
|
5
5
|
CHECKS = 'TRWAGMYFPDXBNJZSQVHLCKE'
|
6
6
|
INVALID_SSN = [
|
7
7
|
/0{3}-\d{2}-\d{4}/,
|
@@ -12,7 +12,7 @@ module Faker
|
|
12
12
|
].freeze
|
13
13
|
ZA_RACE_DIGIT = '8'
|
14
14
|
ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
|
15
|
-
BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])
|
15
|
+
BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/
|
16
16
|
BRAZILIAN_ID_FROM = 10_000_000
|
17
17
|
BRAZILIAN_ID_TO = 99_999_999
|
18
18
|
|
@@ -25,7 +25,7 @@ module Faker
|
|
25
25
|
# @return [String]
|
26
26
|
#
|
27
27
|
# @example
|
28
|
-
# Faker::
|
28
|
+
# Faker::IdNumber.valid #=> "552-56-3593"
|
29
29
|
#
|
30
30
|
# @faker.version 1.6.0
|
31
31
|
def valid
|
@@ -38,7 +38,7 @@ module Faker
|
|
38
38
|
# @return [String]
|
39
39
|
#
|
40
40
|
# @example
|
41
|
-
# Faker::
|
41
|
+
# Faker::IdNumber.invalid #=> "311-72-0000"
|
42
42
|
#
|
43
43
|
# @faker.version 1.6.0
|
44
44
|
def invalid
|
@@ -46,9 +46,23 @@ module Faker
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def ssn_valid
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
generate(:string) do |g|
|
50
|
+
g.computed(name: :first) do
|
51
|
+
range = [1..665, 667..899].sample(random: Faker::Config.random)
|
52
|
+
n = Faker::Base.rand(range)
|
53
|
+
format('%03d', n)
|
54
|
+
end
|
55
|
+
g.lit('-')
|
56
|
+
g.computed(name: :second) do
|
57
|
+
n = Faker::Base.rand(1..99)
|
58
|
+
format('%02d', n)
|
59
|
+
end
|
60
|
+
g.lit('-')
|
61
|
+
g.computed(name: :third) do
|
62
|
+
n = Faker::Base.rand(1..9999)
|
63
|
+
format('%04d', n)
|
64
|
+
end
|
65
|
+
end
|
52
66
|
end
|
53
67
|
|
54
68
|
##
|
@@ -57,7 +71,7 @@ module Faker
|
|
57
71
|
# @return [String]
|
58
72
|
#
|
59
73
|
# @example
|
60
|
-
# Faker::
|
74
|
+
# Faker::IdNumber.spanish_citizen_number #=> "53290236-H"
|
61
75
|
#
|
62
76
|
# @faker.version 1.9.0
|
63
77
|
def spanish_citizen_number
|
@@ -73,7 +87,7 @@ module Faker
|
|
73
87
|
# @return [String]
|
74
88
|
#
|
75
89
|
# @example
|
76
|
-
# Faker::
|
90
|
+
# Faker::IdNumber.spanish_foreign_citizen_number #=> "Z-1600870-Y"
|
77
91
|
#
|
78
92
|
# @faker.version 1.9.0
|
79
93
|
def spanish_foreign_citizen_number
|
@@ -92,8 +106,8 @@ module Faker
|
|
92
106
|
# @return [String]
|
93
107
|
#
|
94
108
|
# @example
|
95
|
-
# Faker::
|
96
|
-
# Faker::
|
109
|
+
# Faker::IdNumber.south_african_id_number #=> "8105128870184"
|
110
|
+
# Faker::IdNumber.valid_south_african_id_number #=> "8105128870184"
|
97
111
|
#
|
98
112
|
# @faker.version 1.9.2
|
99
113
|
def valid_south_african_id_number
|
@@ -115,7 +129,7 @@ module Faker
|
|
115
129
|
# @return [String]
|
116
130
|
#
|
117
131
|
# @example
|
118
|
-
# Faker::
|
132
|
+
# Faker::IdNumber.invalid_south_african_id_number #=> "1642972065088"
|
119
133
|
#
|
120
134
|
# @faker.version 1.9.2
|
121
135
|
def invalid_south_african_id_number
|
@@ -142,8 +156,8 @@ module Faker
|
|
142
156
|
# @return [String]
|
143
157
|
#
|
144
158
|
# @example
|
145
|
-
# Faker::
|
146
|
-
# Faker::
|
159
|
+
# Faker::IdNumber.brazilian_citizen_number #=> "53540542221"
|
160
|
+
# Faker::IdNumber.brazilian_citizen_number(formatted: true) #=> "535.405.422-21"
|
147
161
|
#
|
148
162
|
# @faker.version 1.9.2
|
149
163
|
def brazilian_citizen_number(formatted: false)
|
@@ -163,8 +177,8 @@ module Faker
|
|
163
177
|
# @return [String]
|
164
178
|
#
|
165
179
|
# @example
|
166
|
-
# Faker::
|
167
|
-
# Faker::
|
180
|
+
# Faker::IdNumber.brazilian_id #=> "493054029"
|
181
|
+
# Faker::IdNumber.brazilian_id(formatted: true) #=> "49.305.402-9"
|
168
182
|
#
|
169
183
|
# @faker.version 2.1.2
|
170
184
|
def brazilian_id(formatted: false)
|
@@ -182,7 +196,7 @@ module Faker
|
|
182
196
|
# @return [String]
|
183
197
|
#
|
184
198
|
# @example
|
185
|
-
# Faker::
|
199
|
+
# Faker::IdNumber.chilean_id #=> "15620613-K"
|
186
200
|
#
|
187
201
|
# @faker.version 2.1.2
|
188
202
|
def chilean_id
|
@@ -199,8 +213,8 @@ module Faker
|
|
199
213
|
# @return [String]
|
200
214
|
#
|
201
215
|
# @example
|
202
|
-
# Faker::
|
203
|
-
# Faker::
|
216
|
+
# Faker::IdNumber.croatian_id #=> "88467617508"
|
217
|
+
# Faker::IdNumber.croatian_id(international: true) #=> "HR88467617508"
|
204
218
|
#
|
205
219
|
# @faker.version next
|
206
220
|
def croatian_id(international: false)
|
@@ -224,10 +238,10 @@ module Faker
|
|
224
238
|
# @return [String]
|
225
239
|
#
|
226
240
|
# @example
|
227
|
-
# Faker::
|
228
|
-
# Faker::
|
229
|
-
# Faker::
|
230
|
-
# Faker::
|
241
|
+
# Faker::IdNumber.danish_id_number #=> "0503909980"
|
242
|
+
# Faker::IdNumber.danish_id_number(formatted: true) #=> "050390-9980"
|
243
|
+
# Faker::IdNumber.danish_id_number(birthday: Date.new(1990, 3, 5)) #=> "0503909980"
|
244
|
+
# Faker::IdNumber.danish_id_number(gender: :female) #=> "0503909980"
|
231
245
|
#
|
232
246
|
# @faker.version next
|
233
247
|
def danish_id_number(formatted: false, birthday: Faker::Date.birthday, gender: nil)
|
@@ -261,7 +275,7 @@ module Faker
|
|
261
275
|
# @return [String]
|
262
276
|
#
|
263
277
|
# @example
|
264
|
-
# Faker::
|
278
|
+
# Faker::IdNumber.french_insee_number #=> "53290236-H"
|
265
279
|
#
|
266
280
|
# @faker.version next
|
267
281
|
def french_insee_number
|
@@ -25,10 +25,11 @@ module Faker
|
|
25
25
|
# @param domain [String]
|
26
26
|
#
|
27
27
|
# @example
|
28
|
-
# Faker::Internet.email #=> "
|
29
|
-
# Faker::Internet.email(name: 'smith') #=> "smith@
|
30
|
-
# Faker::Internet.email(name: 'sam smith', separators: ['-']) #=> "sam
|
31
|
-
# Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: '
|
28
|
+
# Faker::Internet.email #=> "renee@zieme.test"
|
29
|
+
# Faker::Internet.email(name: 'smith') #=> "smith@bergnaum.test"
|
30
|
+
# Faker::Internet.email(name: 'sam smith', separators: ['-']) #=> "smith-sam@tromp.example"
|
31
|
+
# Faker::Internet.email(name: 'sam smith', separators: ['-'], domain: 'test') #=> "sam-smith@test.example"
|
32
|
+
# Faker::Internet.email(domain: 'gmail.com') #=> "foo@gmail.com"
|
32
33
|
def email(name: nil, separators: nil, domain: nil)
|
33
34
|
local_part = if separators
|
34
35
|
username(specifier: name, separators: separators)
|
@@ -37,41 +38,14 @@ module Faker
|
|
37
38
|
end
|
38
39
|
|
39
40
|
sanitized_local_part = sanitize_email_local_part(local_part)
|
40
|
-
construct_email(sanitized_local_part, domain_name(domain: domain))
|
41
|
-
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# @param name [String]
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# Faker::Internet.free_email #=> "samsmith@gmail.com"
|
52
|
-
# Faker::Internet.free_email(name: 'smith') #=> "smith@yahoo.com"
|
53
|
-
def free_email(name: nil)
|
54
|
-
construct_email(
|
55
|
-
sanitize_email_local_part(username(specifier: name)),
|
56
|
-
fetch('internet.free_email')
|
57
|
-
)
|
58
|
-
end
|
42
|
+
generate_domain = if domain.nil?
|
43
|
+
domain_name
|
44
|
+
else
|
45
|
+
domain_name(domain: domain)
|
46
|
+
end
|
59
47
|
|
60
|
-
|
61
|
-
# Returns the email address with fixed domain name as 'example'
|
62
|
-
#
|
63
|
-
# @return [String]
|
64
|
-
#
|
65
|
-
# @param name [String]
|
66
|
-
#
|
67
|
-
# @example
|
68
|
-
# Faker::Internet.safe_email #=> "samsmith@example.com"
|
69
|
-
# Faker::Internet.safe_email(name: 'smith') #=> "smith@example.net"
|
70
|
-
def safe_email(name: nil)
|
71
|
-
construct_email(
|
72
|
-
sanitize_email_local_part(username(specifier: name)),
|
73
|
-
"example.#{sample(%w[org com net])}"
|
74
|
-
)
|
48
|
+
construct_email(sanitized_local_part, generate_domain)
|
75
49
|
end
|
76
50
|
|
77
51
|
##
|
@@ -86,12 +60,15 @@ module Faker
|
|
86
60
|
# Faker::Internet.username(specifier: 10) #=> "lulu.goodwin"
|
87
61
|
# Faker::Internet.username(specifier: 5..10) #=> "morris"
|
88
62
|
# Faker::Internet.username(specifier: 5..10) #=> "berryberry"
|
89
|
-
# Faker::Internet.username(specifier: 20, separators: ['
|
63
|
+
# Faker::Internet.username(specifier: 20, separators: ['_']) #=> "nikki_sawaynnikki_saway"
|
90
64
|
def username(specifier: nil, separators: %w[. _])
|
91
65
|
with_locale(:en) do
|
92
|
-
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
|
93
|
-
|
94
66
|
case specifier
|
67
|
+
when ::String
|
68
|
+
names = specifier.gsub("'", '').scan(/[[:word:]]+/)
|
69
|
+
shuffled_names = shuffle(names)
|
70
|
+
|
71
|
+
return shuffled_names.join(sample(separators)).downcase
|
95
72
|
when Integer
|
96
73
|
# If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
|
97
74
|
raise ArgumentError, 'Given argument is too large' if specifier > 10**6
|
@@ -147,37 +124,53 @@ module Faker
|
|
147
124
|
#
|
148
125
|
# @faker.version 2.1.3
|
149
126
|
def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
|
150
|
-
raise ArgumentError, '
|
127
|
+
raise ArgumentError, 'min_length and max_length must be greater than or equal to one' if min_length < 1 || max_length < 1
|
128
|
+
raise ArgumentError, 'min_length must be smaller than or equal to max_length' unless min_length <= max_length
|
151
129
|
|
152
|
-
|
153
|
-
|
154
|
-
|
130
|
+
character_types = []
|
131
|
+
required_min_length = 0
|
132
|
+
|
133
|
+
if mix_case
|
134
|
+
character_types << :mix_case
|
135
|
+
required_min_length += 2
|
136
|
+
end
|
155
137
|
|
156
|
-
if
|
157
|
-
|
158
|
-
|
138
|
+
if special_characters
|
139
|
+
character_types << :special_characters
|
140
|
+
required_min_length += 1
|
159
141
|
end
|
160
142
|
|
143
|
+
raise ArgumentError, "min_length should be at least #{required_min_length} to enable #{character_types.join(', ')} configuration" if min_length < required_min_length
|
144
|
+
|
145
|
+
target_length = rand(min_length..max_length)
|
146
|
+
|
147
|
+
password = []
|
148
|
+
character_bag = []
|
149
|
+
|
150
|
+
# use lower_chars by default and add upper_chars if mix_case
|
151
|
+
lower_chars = self::LLetters
|
152
|
+
password << sample(lower_chars)
|
153
|
+
character_bag += lower_chars
|
154
|
+
|
155
|
+
digits = ('0'..'9').to_a
|
156
|
+
password << sample(digits)
|
157
|
+
character_bag += digits
|
158
|
+
|
161
159
|
if mix_case
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
temp[index] = char.upcase if alpha_count.even?
|
166
|
-
alpha_count += 1
|
167
|
-
end
|
168
|
-
end
|
160
|
+
upper_chars = self::ULetters
|
161
|
+
password << sample(upper_chars)
|
162
|
+
character_bag += upper_chars
|
169
163
|
end
|
170
164
|
|
171
165
|
if special_characters
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
end
|
166
|
+
special_chars = %w[! @ # $ % ^ & *]
|
167
|
+
password << sample(special_chars)
|
168
|
+
character_bag += special_chars
|
176
169
|
end
|
177
170
|
|
178
|
-
|
171
|
+
password << sample(character_bag) while password.length < target_length
|
179
172
|
|
180
|
-
|
173
|
+
shuffle(password).join
|
181
174
|
end
|
182
175
|
|
183
176
|
##
|
@@ -189,10 +182,12 @@ module Faker
|
|
189
182
|
# @param domain [String]
|
190
183
|
#
|
191
184
|
# @example
|
192
|
-
# Faker::Internet.domain_name
|
193
|
-
# Faker::Internet.domain_name(subdomain: true)
|
194
|
-
# Faker::Internet.domain_name(subdomain: true, domain: '
|
195
|
-
# Faker::Internet.domain_name(domain: 'faker')
|
185
|
+
# Faker::Internet.domain_name #=> "altenwerth-gerhold.example"
|
186
|
+
# Faker::Internet.domain_name(subdomain: true) #=> "metz.mclaughlin-brekke.test"
|
187
|
+
# Faker::Internet.domain_name(subdomain: true, domain: 'faker') #=> "foo.faker.test"
|
188
|
+
# Faker::Internet.domain_name(domain: 'faker-ruby.org') #=> "faker-ruby.org"
|
189
|
+
# Faker::Internet.domain_name(subdomain: true, domain: 'faker-ruby.org') #=> "foo.faker-ruby.org"
|
190
|
+
# Faker::Internet.domain_name(subdomain: true, domain: 'faker.faker-ruby.org') #=> "faker.faker-ruby.org"
|
196
191
|
def domain_name(subdomain: false, domain: nil)
|
197
192
|
with_locale(:en) do
|
198
193
|
if domain
|
@@ -200,12 +195,18 @@ module Faker
|
|
200
195
|
.split('.')
|
201
196
|
.map { |domain_part| Char.prepare(domain_part) }
|
202
197
|
.tap do |domain_elements|
|
203
|
-
|
204
|
-
|
198
|
+
if domain_elements.length < 2
|
199
|
+
domain_elements << domain_suffix(safe: true)
|
200
|
+
end
|
201
|
+
if subdomain && domain_elements.length < 3
|
202
|
+
domain_elements.unshift(Char.prepare(domain_word))
|
203
|
+
end
|
205
204
|
end.join('.')
|
206
205
|
else
|
207
|
-
[domain_word, domain_suffix].tap do |domain_elements|
|
208
|
-
|
206
|
+
[domain_word, domain_suffix(safe: true)].tap do |domain_elements|
|
207
|
+
if subdomain
|
208
|
+
domain_elements.unshift(Char.prepare(domain_word))
|
209
|
+
end
|
209
210
|
end.join('.')
|
210
211
|
end
|
211
212
|
end
|
@@ -242,10 +243,16 @@ module Faker
|
|
242
243
|
# @return [String]
|
243
244
|
#
|
244
245
|
# @example
|
245
|
-
# Faker::Internet.domain_suffix
|
246
|
-
# Faker::Internet.domain_suffix
|
247
|
-
|
248
|
-
|
246
|
+
# Faker::Internet.domain_suffix #=> "com"
|
247
|
+
# Faker::Internet.domain_suffix #=> "biz"
|
248
|
+
# Faker::Internet.domain_suffix(safe: true) #=> "example"
|
249
|
+
# Faker::Internet.domain_suffix(safe: true) #=> "test"
|
250
|
+
def domain_suffix(safe: nil)
|
251
|
+
if safe
|
252
|
+
fetch('internet.safe_domain_suffix')
|
253
|
+
else
|
254
|
+
fetch('internet.domain_suffix')
|
255
|
+
end
|
249
256
|
end
|
250
257
|
|
251
258
|
##
|
@@ -260,7 +267,7 @@ module Faker
|
|
260
267
|
# Faker::Internet.mac_address(prefix: 'aa:44') #=> "aa:44:30:88:6e:95"
|
261
268
|
def mac_address(prefix: '')
|
262
269
|
prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
|
263
|
-
address_digits = Array.new(
|
270
|
+
address_digits = Array.new(6 - prefix_digits.size) { rand(256) }
|
264
271
|
(prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
|
265
272
|
end
|
266
273
|
|
@@ -410,10 +417,10 @@ module Faker
|
|
410
417
|
# @param scheme [String]
|
411
418
|
#
|
412
419
|
# @example
|
413
|
-
# Faker::Internet.url #=> "http://
|
420
|
+
# Faker::Internet.url #=> "http://treutel.test/demarcus"
|
414
421
|
# Faker::Internet.url(host: 'faker') #=> "http://faker/shad"
|
415
|
-
# Faker::Internet.url(host: 'faker', path: '/
|
416
|
-
# Faker::Internet.url(host: 'faker', path: '/
|
422
|
+
# Faker::Internet.url(host: 'faker', path: '/docs') #=> "http://faker/docs"
|
423
|
+
# Faker::Internet.url(host: 'faker', path: '/docs', scheme: 'https') #=> "https://faker/docs"
|
417
424
|
def url(host: domain_name, path: "/#{username}", scheme: 'http')
|
418
425
|
"#{scheme}://#{host}#{path}"
|
419
426
|
end
|
@@ -531,10 +538,10 @@ module Faker
|
|
531
538
|
##
|
532
539
|
# Produces a randomized hash of internet user details
|
533
540
|
# @example
|
534
|
-
# Faker::Internet.user #=> { username: 'alexie', email: '
|
541
|
+
# Faker::Internet.user #=> { username: 'alexie', email: 'trudie@grant.test' }
|
535
542
|
#
|
536
543
|
# @example
|
537
|
-
# Faker::Internet.user('username', 'email', 'password') #=> { username: 'alexie', email: '
|
544
|
+
# Faker::Internet.user('username', 'email', 'password') #=> { username: 'alexie', email: 'gayle@kohler.test', password: 'DtEf9P8wS31iMyC' }
|
538
545
|
#
|
539
546
|
# @return [hash]
|
540
547
|
#
|
@@ -13,8 +13,8 @@ module Faker
|
|
13
13
|
# @return [Integer]
|
14
14
|
#
|
15
15
|
# @example
|
16
|
-
# Faker::
|
17
|
-
# Faker::
|
16
|
+
# Faker::Invoice.amount_between #=> 0
|
17
|
+
# Faker::Invoice.amount_between(from: 0, to: 10) #=> 4.33
|
18
18
|
#
|
19
19
|
# @faker.version 1.9.0
|
20
20
|
def amount_between(from: 0, to: 0)
|
@@ -22,7 +22,7 @@ module Faker
|
|
22
22
|
end
|
23
23
|
|
24
24
|
##
|
25
|
-
# Produces a random valid reference
|
25
|
+
# Produces a random valid reference according to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
|
26
26
|
#
|
27
27
|
# @param ref [String] Specifies reference base.
|
28
28
|
# @return [String]
|
@@ -102,7 +102,7 @@ module Faker
|
|
102
102
|
mod10_remainder(weighted_sum)
|
103
103
|
end
|
104
104
|
|
105
|
-
# Calculates
|
105
|
+
# Calculates weighted sum
|
106
106
|
#
|
107
107
|
# For example with 12345678, [1,2]
|
108
108
|
# Ref.num. 1 2 3 4 5 6 7 8
|