faker 3.2.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 +437 -2
- data/README.md +29 -14
- 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 +64 -18
- data/lib/faker/default/company.rb +99 -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/finance.rb +2 -2
- 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 +19 -53
- data/lib/faker/default/invoice.rb +3 -3
- data/lib/faker/default/json.rb +9 -4
- data/lib/faker/default/lorem.rb +6 -3
- 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 +4 -4
- 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/types.rb +5 -6
- data/lib/faker/default/vehicle.rb +23 -11
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/heroes_of_the_storm.rb +0 -11
- data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +10 -10
- data/lib/faker/locations/australia.rb +40 -38
- 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/travel/airport.rb +2 -2
- 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/the_fresh_prince_of_bel_air.rb +0 -13
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +20 -8
- 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/bg.yml +0 -1
- data/lib/locales/da-DK.yml +529 -35
- data/lib/locales/de-AT.yml +3487 -26
- 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/archer.yml +75 -0
- data/lib/locales/en/australia.yml +106 -105
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/cosmere.yml +1 -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 +2 -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/id_number.yml +1 -1
- data/lib/locales/en/internet.yml +0 -4
- data/lib/locales/en/minecraft.yml +4 -4
- 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/{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 -9
- data/lib/locales/en-IND.yml +1259 -17
- data/lib/locales/en-KE.yml +212 -0
- data/lib/locales/en-MS.yml +364 -18
- data/lib/locales/en-NEP.yml +212 -38
- data/lib/locales/en-NZ.yml +1153 -124
- data/lib/locales/en-PAK.yml +392 -11
- data/lib/locales/en-SG.yml +581 -17
- data/lib/locales/en-US.yml +6914 -74
- data/lib/locales/en-au-ocker.yml +266 -24
- data/lib/locales/es-AR.yml +4569 -4600
- data/lib/locales/es-MX.yml +0 -1
- data/lib/locales/es.yml +0 -1
- data/lib/locales/fr/address.yml +761 -8
- 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 +0 -1
- data/lib/locales/fr.yml +3 -1
- data/lib/locales/hy.yml +3624 -120
- data/lib/locales/id.yml +839 -12
- data/lib/locales/it.yml +1304 -33
- 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/touhou.yml +466 -0
- data/lib/locales/ko.yml +1361 -21
- data/lib/locales/lt.yml +297 -16
- data/lib/locales/lv.yml +0 -1
- data/lib/locales/nb-NO.yml +518 -30
- data/lib/locales/nl.yml +9 -2
- data/lib/locales/pl.yml +0 -1
- data/lib/locales/pt-BR.yml +8205 -665
- data/lib/locales/pt.yml +844 -45
- data/lib/locales/ru.yml +1353 -70
- data/lib/locales/sk.yml +4410 -44
- data/lib/locales/sv.yml +99 -0
- data/lib/locales/tr.yml +0 -2
- data/lib/locales/uk.yml +1808 -45
- data/lib/locales/zh-CN/bank.yml +17 -0
- metadata +26 -154
- data/History.md +0 -176
@@ -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
|
@@ -15,8 +15,6 @@ module Faker
|
|
15
15
|
].each(&:freeze).freeze
|
16
16
|
|
17
17
|
class << self
|
18
|
-
extend Gem::Deprecate
|
19
|
-
|
20
18
|
##
|
21
19
|
# Returns the email address
|
22
20
|
#
|
@@ -50,42 +48,6 @@ module Faker
|
|
50
48
|
construct_email(sanitized_local_part, generate_domain)
|
51
49
|
end
|
52
50
|
|
53
|
-
##
|
54
|
-
# Returns the email address with domain either gmail.com, yahoo.com or hotmail.com
|
55
|
-
#
|
56
|
-
# @return [String]
|
57
|
-
#
|
58
|
-
# @param name [String]
|
59
|
-
#
|
60
|
-
# @example
|
61
|
-
# Faker::Internet.free_email #=> "samsmith@gmail.com"
|
62
|
-
# Faker::Internet.free_email(name: 'smith') #=> "smith@yahoo.com"
|
63
|
-
def free_email(name: nil)
|
64
|
-
construct_email(
|
65
|
-
sanitize_email_local_part(username(specifier: name)),
|
66
|
-
fetch('internet.free_email')
|
67
|
-
)
|
68
|
-
end
|
69
|
-
deprecate :free_email, :email, 2023, 10
|
70
|
-
|
71
|
-
##
|
72
|
-
# Returns the email address with fixed domain name as 'example'
|
73
|
-
#
|
74
|
-
# @return [String]
|
75
|
-
#
|
76
|
-
# @param name [String]
|
77
|
-
#
|
78
|
-
# @example
|
79
|
-
# Faker::Internet.safe_email #=> "samsmith@example.com"
|
80
|
-
# Faker::Internet.safe_email(name: 'smith') #=> "smith@example.net"
|
81
|
-
def safe_email(name: nil)
|
82
|
-
construct_email(
|
83
|
-
sanitize_email_local_part(username(specifier: name)),
|
84
|
-
"example.#{sample(%w[org com net])}"
|
85
|
-
)
|
86
|
-
end
|
87
|
-
deprecate :safe_email, :email, 2023, 10
|
88
|
-
|
89
51
|
##
|
90
52
|
# Returns the username
|
91
53
|
#
|
@@ -98,12 +60,15 @@ module Faker
|
|
98
60
|
# Faker::Internet.username(specifier: 10) #=> "lulu.goodwin"
|
99
61
|
# Faker::Internet.username(specifier: 5..10) #=> "morris"
|
100
62
|
# Faker::Internet.username(specifier: 5..10) #=> "berryberry"
|
101
|
-
# Faker::Internet.username(specifier: 20, separators: ['
|
63
|
+
# Faker::Internet.username(specifier: 20, separators: ['_']) #=> "nikki_sawaynnikki_saway"
|
102
64
|
def username(specifier: nil, separators: %w[. _])
|
103
65
|
with_locale(:en) do
|
104
|
-
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
|
105
|
-
|
106
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
|
107
72
|
when Integer
|
108
73
|
# If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
|
109
74
|
raise ArgumentError, 'Given argument is too large' if specifier > 10**6
|
@@ -159,7 +124,8 @@ module Faker
|
|
159
124
|
#
|
160
125
|
# @faker.version 2.1.3
|
161
126
|
def password(min_length: 8, max_length: 16, mix_case: true, special_characters: false)
|
162
|
-
raise ArgumentError, 'max_length must be
|
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
|
163
129
|
|
164
130
|
character_types = []
|
165
131
|
required_min_length = 0
|
@@ -182,27 +148,27 @@ module Faker
|
|
182
148
|
character_bag = []
|
183
149
|
|
184
150
|
# use lower_chars by default and add upper_chars if mix_case
|
185
|
-
lower_chars =
|
186
|
-
password <<
|
151
|
+
lower_chars = self::LLetters
|
152
|
+
password << sample(lower_chars)
|
187
153
|
character_bag += lower_chars
|
188
154
|
|
189
|
-
digits = ('
|
190
|
-
password <<
|
155
|
+
digits = ('0'..'9').to_a
|
156
|
+
password << sample(digits)
|
191
157
|
character_bag += digits
|
192
158
|
|
193
|
-
if
|
194
|
-
upper_chars =
|
195
|
-
password <<
|
159
|
+
if mix_case
|
160
|
+
upper_chars = self::ULetters
|
161
|
+
password << sample(upper_chars)
|
196
162
|
character_bag += upper_chars
|
197
163
|
end
|
198
164
|
|
199
|
-
if
|
165
|
+
if special_characters
|
200
166
|
special_chars = %w[! @ # $ % ^ & *]
|
201
|
-
password <<
|
167
|
+
password << sample(special_chars)
|
202
168
|
character_bag += special_chars
|
203
169
|
end
|
204
170
|
|
205
|
-
password <<
|
171
|
+
password << sample(character_bag) while password.length < target_length
|
206
172
|
|
207
173
|
shuffle(password).join
|
208
174
|
end
|
@@ -301,7 +267,7 @@ module Faker
|
|
301
267
|
# Faker::Internet.mac_address(prefix: 'aa:44') #=> "aa:44:30:88:6e:95"
|
302
268
|
def mac_address(prefix: '')
|
303
269
|
prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
|
304
|
-
address_digits = Array.new(
|
270
|
+
address_digits = Array.new(6 - prefix_digits.size) { rand(256) }
|
305
271
|
(prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
|
306
272
|
end
|
307
273
|
|
@@ -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]
|
data/lib/faker/default/json.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Faker
|
2
4
|
class Json < Base
|
3
5
|
require 'json'
|
@@ -71,7 +73,7 @@ module Faker
|
|
71
73
|
options[:value] = "Faker::#{options[:value]}"
|
72
74
|
|
73
75
|
hash = JSON.parse(json)
|
74
|
-
hash.
|
76
|
+
hash.each_key do |key|
|
75
77
|
add_hash_to_bottom(hash, [key], width, options)
|
76
78
|
end
|
77
79
|
JSON.generate(hash)
|
@@ -93,7 +95,7 @@ module Faker
|
|
93
95
|
def add_hash_to_bottom(hash, key_array, width, options)
|
94
96
|
key_string = build_keys_from_array(key_array)
|
95
97
|
if eval("hash#{key_string}").is_a?(::Hash)
|
96
|
-
eval("hash#{key_string}").
|
98
|
+
eval("hash#{key_string}").each_key do |key|
|
97
99
|
key_array << key
|
98
100
|
add_hash_to_bottom(hash, key_array, width, options)
|
99
101
|
end
|
@@ -104,17 +106,20 @@ module Faker
|
|
104
106
|
end
|
105
107
|
|
106
108
|
def add_hash(key_array, hash, width, options)
|
107
|
-
string_to_eval = 'hash'
|
109
|
+
string_to_eval = 'hash'.dup
|
110
|
+
|
108
111
|
key_array.length.times do |index|
|
109
112
|
string_to_eval << "['#{key_array[index]}']"
|
110
113
|
end
|
111
114
|
string_to_eval << " = #{build_shallow_hash(width, options)}"
|
112
115
|
eval(string_to_eval)
|
116
|
+
|
113
117
|
hash
|
114
118
|
end
|
115
119
|
|
116
120
|
def build_keys_from_array(key_array)
|
117
|
-
key_string = ''
|
121
|
+
key_string = ''.dup
|
122
|
+
|
118
123
|
key_array.each do |value|
|
119
124
|
key_string << "['#{value}']"
|
120
125
|
end
|
data/lib/faker/default/lorem.rb
CHANGED
@@ -10,10 +10,13 @@ module Faker
|
|
10
10
|
#
|
11
11
|
# @example
|
12
12
|
# Faker::Lorem.word #=> "soluto"
|
13
|
+
# Faker::Lorem.word(exclude_words: 'error') #=> "nisi"
|
14
|
+
# Faker::Lorem.word(exclude_words: 'id, error') #=> "et"
|
15
|
+
# Faker::Lorem.word(exclude_words: ['id', 'error']) #=> "consequatur"
|
13
16
|
#
|
14
17
|
# @faker.version 2.1.3
|
15
|
-
def word
|
16
|
-
|
18
|
+
def word(exclude_words: nil)
|
19
|
+
words(number: 1, exclude_words: exclude_words).first
|
17
20
|
end
|
18
21
|
|
19
22
|
##
|
@@ -42,7 +45,7 @@ module Faker
|
|
42
45
|
word_list -= exclude_words
|
43
46
|
end
|
44
47
|
word_list *= ((resolved_num / word_list.length) + 1)
|
45
|
-
|
48
|
+
sample(word_list, resolved_num)
|
46
49
|
end
|
47
50
|
|
48
51
|
##
|
@@ -6,24 +6,28 @@ module Faker
|
|
6
6
|
##
|
7
7
|
# Produces a random British NHS number.
|
8
8
|
#
|
9
|
+
# The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999
|
10
|
+
# for test purposes.
|
11
|
+
#
|
9
12
|
# @return [String]
|
10
13
|
#
|
11
14
|
# @example
|
12
|
-
# Faker::NationalHealthService.british_number #=> "
|
15
|
+
# Faker::NationalHealthService.british_number #=> "999 464 0232"
|
13
16
|
#
|
14
17
|
# @faker.version 1.9.2
|
15
18
|
def british_number
|
16
|
-
base_number = rand(
|
19
|
+
base_number = rand(999_000_001...999_999_999)
|
17
20
|
# If the check digit is equivalent to 10, the number is invalid.
|
18
21
|
# See https://en.wikipedia.org/wiki/NHS_number
|
19
22
|
base_number -= 1 if check_digit(number: base_number) == 10
|
20
|
-
"#{base_number}#{check_digit(number: base_number)}".
|
21
|
-
.chars
|
23
|
+
"#{base_number}#{check_digit(number: base_number)}".chars
|
22
24
|
.insert(3, ' ')
|
23
25
|
.insert(7, ' ')
|
24
26
|
.join
|
25
27
|
end
|
26
28
|
|
29
|
+
private
|
30
|
+
|
27
31
|
##
|
28
32
|
# Produces a random British NHS number's check digit.
|
29
33
|
#
|
data/lib/faker/default/number.rb
CHANGED
@@ -444,11 +444,11 @@ module Faker
|
|
444
444
|
private
|
445
445
|
|
446
446
|
def gender
|
447
|
-
|
447
|
+
sample(%w[male female])
|
448
448
|
end
|
449
449
|
|
450
450
|
def timezone
|
451
|
-
|
451
|
+
sample((-12..12).to_a)
|
452
452
|
end
|
453
453
|
|
454
454
|
def image
|
@@ -460,11 +460,11 @@ module Faker
|
|
460
460
|
end
|
461
461
|
|
462
462
|
def random_number_from_range(range)
|
463
|
-
|
463
|
+
sample(range.to_a)
|
464
464
|
end
|
465
465
|
|
466
466
|
def random_boolean
|
467
|
-
|
467
|
+
sample([true, false])
|
468
468
|
end
|
469
469
|
end
|
470
470
|
end
|