ffaker 2.18.0 → 2.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +25 -0
- data/REFERENCE.md +1463 -1352
- data/ffaker.gemspec +1 -4
- data/lib/ffaker/address_au.rb +1 -1
- data/lib/ffaker/address_br.rb +15 -3
- data/lib/ffaker/address_ca.rb +1 -1
- data/lib/ffaker/address_it.rb +36 -0
- data/lib/ffaker/address_mx.rb +2 -8
- data/lib/ffaker/animal_br.rb +12 -0
- data/lib/ffaker/company.rb +3 -6
- data/lib/ffaker/company_fr.rb +35 -0
- data/lib/ffaker/{courses.rb → courses_fr.rb} +2 -0
- data/lib/ffaker/data/address_br/city +0 -1
- data/lib/ffaker/data/address_br/complement +3 -0
- data/lib/ffaker/data/address_br/neighborhood_prefixes +3 -0
- data/lib/ffaker/data/address_br/state +1 -1
- data/lib/ffaker/data/address_it/city +111 -0
- data/lib/ffaker/data/address_it/region +20 -0
- data/lib/ffaker/data/animal_br/common_names +423 -0
- data/lib/ffaker/data/food_pl/fermented +1 -1
- data/lib/ffaker/data/food_pl/fruits +1 -1
- data/lib/ffaker/data/food_pl/herbs +1 -1
- data/lib/ffaker/data/food_pl/meats +1 -1
- data/lib/ffaker/data/food_pl/preserves +1 -1
- data/lib/ffaker/data/food_pl/spices +1 -1
- data/lib/ffaker/data/food_pl/vegetables +1 -1
- data/lib/ffaker/data/game/adj_and_adv +18 -0
- data/lib/ffaker/data/game/category +84 -0
- data/lib/ffaker/data/game/mechanic +182 -0
- data/lib/ffaker/data/game/nouns +37 -0
- data/lib/ffaker/data/game/prefixes +17 -0
- data/lib/ffaker/data/job_it/job_adj +37 -0
- data/lib/ffaker/data/job_it/job_noun +25 -0
- data/lib/ffaker/data/job_it/job_prefix +22 -0
- data/lib/ffaker/data/lorem_br/characters +36 -0
- data/lib/ffaker/data/lorem_br/words +183 -0
- data/lib/ffaker/data/lorem_it/words +321 -0
- data/lib/ffaker/data/name/pronouns +1 -1
- data/lib/ffaker/data/name_ga/first_names_male +286 -286
- data/lib/ffaker/data/sport_ru/summer +68 -0
- data/lib/ffaker/data/sport_ru/winter +20 -0
- data/lib/ffaker/freedom_ipsum.rb +1 -1
- data/lib/ffaker/game.rb +33 -0
- data/lib/ffaker/gender_it.rb +17 -0
- data/lib/ffaker/gender_ru.rb +22 -0
- data/lib/ffaker/html_ipsum.rb +7 -1
- data/lib/ffaker/identification_it.rb +30 -0
- data/lib/ffaker/identification_tw.rb +3 -2
- data/lib/ffaker/job_it.rb +12 -0
- data/lib/ffaker/lorem_br.rb +45 -0
- data/lib/ffaker/lorem_it.rb +39 -0
- data/lib/ffaker/name_th_en.rb +1 -1
- data/lib/ffaker/number.rb +26 -0
- data/lib/ffaker/phone_number_it.rb +8 -6
- data/lib/ffaker/sport_ru.rb +25 -0
- data/lib/ffaker/ssn_se.rb +0 -19
- data/lib/ffaker/string.rb +6 -6
- data/lib/ffaker/time.rb +1 -1
- data/lib/ffaker/utils/array_utils.rb +1 -1
- data/lib/ffaker/utils/module_utils.rb +23 -3
- data/lib/ffaker/utils/unique_utils.rb +1 -0
- data/lib/ffaker/vehicle.rb +63 -1
- data/lib/ffaker.rb +15 -3
- data/lib/version.rb +1 -1
- data/scripts/profiling.rb +1 -1
- data/scripts/reference.rb +16 -15
- data/test/helper.rb +1 -1
- data/test/test_address.rb +1 -1
- data/test/test_address_au.rb +1 -1
- data/test/test_address_br.rb +16 -3
- data/test/test_address_ca.rb +1 -1
- data/test/test_address_ch.rb +1 -1
- data/test/test_address_ch_de.rb +1 -1
- data/test/test_address_ch_fr.rb +1 -1
- data/test/test_address_ch_it.rb +1 -1
- data/test/test_address_da.rb +1 -1
- data/test/test_address_de.rb +1 -1
- data/test/test_address_fi.rb +1 -1
- data/test/test_address_fr.rb +1 -1
- data/test/test_address_gr.rb +1 -1
- data/test/test_address_id.rb +1 -1
- data/test/test_address_in.rb +1 -1
- data/test/test_address_it.rb +12 -0
- data/test/test_address_ja.rb +1 -1
- data/test/test_address_kr.rb +1 -1
- data/test/test_address_mx.rb +1 -1
- data/test/test_address_nl.rb +1 -1
- data/test/test_address_pl.rb +1 -1
- data/test/test_address_ru.rb +1 -1
- data/test/test_address_se.rb +1 -1
- data/test/test_address_sn.rb +1 -1
- data/test/test_address_ua.rb +1 -1
- data/test/test_address_uk.rb +1 -1
- data/test/test_address_us.rb +1 -1
- data/test/test_airline.rb +1 -1
- data/test/test_animal.rb +1 -1
- data/test/test_animal_br.rb +17 -0
- data/test/test_animal_cn.rb +1 -1
- data/test/test_animal_es.rb +1 -1
- data/test/test_animal_pl.rb +1 -1
- data/test/test_animal_us.rb +1 -1
- data/test/test_array_utils.rb +2 -1
- data/test/test_avatar.rb +1 -1
- data/test/test_aws.rb +1 -1
- data/test/test_bacon_ipsum.rb +1 -1
- data/test/test_bank.rb +1 -1
- data/test/test_book.rb +1 -1
- data/test/test_boolean.rb +1 -1
- data/test/test_cheesy_lingo.rb +1 -1
- data/test/test_code.rb +1 -1
- data/test/test_color.rb +1 -1
- data/test/test_color_pl.rb +1 -1
- data/test/test_color_ua.rb +1 -1
- data/test/test_company.rb +1 -1
- data/test/test_company_cn.rb +1 -1
- data/test/test_company_fr.rb +33 -0
- data/test/test_company_it.rb +1 -1
- data/test/test_company_ja.rb +1 -1
- data/test/test_company_se.rb +1 -1
- data/test/test_conference.rb +1 -1
- data/test/test_course_mathematiques.rb +1 -1
- data/test/test_course_philosophie.rb +1 -1
- data/test/test_currency.rb +1 -1
- data/test/test_dizzle_ipsum.rb +1 -1
- data/test/test_education.rb +1 -1
- data/test/test_education_cn.rb +1 -1
- data/test/test_ffaker.rb +1 -1
- data/test/test_filesystem.rb +1 -1
- data/test/test_food.rb +1 -1
- data/test/test_food_pl.rb +1 -1
- data/test/test_freedom_ipsum.rb +1 -1
- data/test/test_game.rb +28 -0
- data/test/test_gender.rb +2 -2
- data/test/test_gender_br.rb +1 -1
- data/test/test_gender_cn.rb +1 -1
- data/test/test_gender_id.rb +1 -1
- data/test/test_gender_it.rb +27 -0
- data/test/test_gender_ja.rb +1 -1
- data/test/test_gender_jp.rb +1 -1
- data/test/test_gender_kr.rb +1 -1
- data/test/test_gender_pl.rb +1 -1
- data/test/test_gender_ru.rb +23 -0
- data/test/test_geolocation.rb +1 -1
- data/test/test_guid.rb +1 -1
- data/test/test_healthcare_ipsum.rb +1 -1
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_hipster_ipsum.rb +1 -1
- data/test/test_html_ipsum.rb +7 -1
- data/test/test_identification.rb +1 -1
- data/test/test_identification_br.rb +1 -1
- data/test/test_identification_co.rb +1 -1
- data/test/test_identification_es.rb +1 -1
- data/test/test_identification_es_cl.rb +1 -1
- data/test/test_identification_es_mx.rb +1 -1
- data/test/test_identification_in.rb +1 -1
- data/test/test_identification_it.rb +34 -0
- data/test/test_identification_kr.rb +1 -1
- data/test/test_identification_tw.rb +1 -1
- data/test/test_image.rb +1 -1
- data/test/test_internet.rb +1 -1
- data/test/test_internet_se.rb +1 -1
- data/test/test_job.rb +1 -1
- data/test/test_job_br.rb +1 -1
- data/test/test_job_cn.rb +1 -1
- data/test/test_job_fr.rb +1 -1
- data/test/test_job_it.rb +17 -0
- data/test/test_job_ja.rb +1 -1
- data/test/test_job_kr.rb +1 -1
- data/test/test_job_vn.rb +1 -1
- data/test/test_locale.rb +1 -1
- data/test/test_lorem.rb +1 -1
- data/test/test_lorem_ar.rb +1 -1
- data/test/test_lorem_br.rb +62 -0
- data/test/test_lorem_cn.rb +1 -1
- data/test/test_lorem_fr.rb +1 -1
- data/test/test_lorem_ie.rb +1 -1
- data/test/test_lorem_it.rb +51 -0
- data/test/test_lorem_ja.rb +1 -1
- data/test/test_lorem_kr.rb +1 -1
- data/test/test_lorem_pl.rb +1 -1
- data/test/test_lorem_ru.rb +1 -1
- data/test/test_lorem_ua.rb +1 -1
- data/test/test_module_utils.rb +1 -1
- data/test/test_movie.rb +1 -1
- data/test/test_music.rb +1 -1
- data/test/test_name.rb +1 -1
- data/test/test_name_ar.rb +1 -1
- data/test/test_name_br.rb +1 -1
- data/test/test_name_cn.rb +1 -1
- data/test/test_name_cs.rb +1 -1
- data/test/test_name_da.rb +1 -1
- data/test/test_name_de.rb +1 -1
- data/test/test_name_es.rb +1 -1
- data/test/test_name_fr.rb +1 -1
- data/test/test_name_ga.rb +1 -1
- data/test/test_name_gr.rb +1 -1
- data/test/test_name_id.rb +1 -1
- data/test/test_name_it.rb +1 -1
- data/test/test_name_ja.rb +1 -1
- data/test/test_name_kh.rb +1 -1
- data/test/test_name_kr.rb +1 -1
- data/test/test_name_mx.rb +1 -1
- data/test/test_name_nb.rb +1 -1
- data/test/test_name_nl.rb +1 -1
- data/test/test_name_ph.rb +1 -1
- data/test/test_name_pl.rb +1 -1
- data/test/test_name_ru.rb +1 -1
- data/test/test_name_se.rb +1 -1
- data/test/test_name_sn.rb +1 -1
- data/test/test_name_th.rb +1 -1
- data/test/test_name_th_en.rb +1 -1
- data/test/test_name_tw.rb +1 -1
- data/test/test_name_ua.rb +1 -1
- data/test/test_name_vn.rb +1 -1
- data/test/test_nato_alphabet.rb +1 -1
- data/test/test_number.rb +45 -0
- data/test/test_phone_number.rb +1 -1
- data/test/test_phone_number_au.rb +1 -1
- data/test/test_phone_number_br.rb +1 -1
- data/test/test_phone_number_cu.rb +1 -1
- data/test/test_phone_number_da.rb +1 -1
- data/test/test_phone_number_de.rb +1 -1
- data/test/test_phone_number_fr.rb +1 -1
- data/test/test_phone_number_id.rb +1 -1
- data/test/test_phone_number_it.rb +12 -0
- data/test/test_phone_number_ja.rb +1 -1
- data/test/test_phone_number_kr.rb +1 -1
- data/test/test_phone_number_mx.rb +1 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_phone_number_pl.rb +1 -1
- data/test/test_phone_number_se.rb +1 -1
- data/test/test_phone_number_sg.rb +1 -1
- data/test/test_phone_number_sn.rb +1 -1
- data/test/test_phone_number_tw.rb +1 -1
- data/test/test_phone_number_ua.rb +1 -1
- data/test/test_products.rb +1 -1
- data/test/test_sem_ver.rb +1 -1
- data/test/test_skill.rb +1 -1
- data/test/test_sport_pl.rb +1 -1
- data/test/test_sport_ru.rb +30 -0
- data/test/test_sport_us.rb +1 -1
- data/test/test_sports.rb +1 -1
- data/test/test_ssn.rb +1 -1
- data/test/test_ssn_mx.rb +1 -1
- data/test/test_ssn_se.rb +1 -1
- data/test/test_string.rb +1 -1
- data/test/test_time.rb +1 -1
- data/test/test_tweet.rb +1 -1
- data/test/test_unique_utils.rb +1 -1
- data/test/test_units.rb +2 -1
- data/test/test_units_english.rb +1 -1
- data/test/test_units_metric.rb +1 -1
- data/test/test_vehicle.rb +7 -2
- data/test/test_venue.rb +1 -1
- data/test/test_youtube.rb +1 -1
- metadata +216 -160
data/lib/ffaker/game.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module Game
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def title
|
9
|
+
case rand(0..1)
|
10
|
+
when 0 then simple_title
|
11
|
+
when 1 then title_with_prefix
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def category
|
16
|
+
fetch_sample(CATEGORY)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mechanic
|
20
|
+
fetch_sample(MECHANIC)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def simple_title
|
26
|
+
"#{fetch_sample(ADJ_AND_ADV)} #{fetch_sample(NOUNS)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def title_with_prefix
|
30
|
+
"#{fetch_sample(PREFIXES)} #{simple_title}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module GenderIT
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
GENDERS = %w[maschio femmina].freeze
|
9
|
+
|
10
|
+
def random
|
11
|
+
fetch_sample(GENDERS)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias maybe random
|
15
|
+
alias sample random
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module GenderRU
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
GENDERS = %w[мужчина женщина нонбайнари агендер].freeze
|
9
|
+
BINARY_GENDERS = %w[мужчина женщина].freeze
|
10
|
+
|
11
|
+
def random
|
12
|
+
fetch_sample(GENDERS)
|
13
|
+
end
|
14
|
+
|
15
|
+
def binary
|
16
|
+
fetch_sample(BINARY_GENDERS)
|
17
|
+
end
|
18
|
+
|
19
|
+
alias maybe random
|
20
|
+
alias sample random
|
21
|
+
end
|
22
|
+
end
|
data/lib/ffaker/html_ipsum.rb
CHANGED
@@ -134,9 +134,15 @@ module FFaker
|
|
134
134
|
a = k([
|
135
135
|
content_tag_for(:strong, words(2).capitalize!),
|
136
136
|
content_tag_for(:em, paragraph),
|
137
|
+
content_tag_for(:mark, paragraph),
|
138
|
+
content_tag_for(:del, words(2)),
|
139
|
+
content_tag_for(:ins, words(2)),
|
140
|
+
content_tag_for(:sub, words(2)),
|
141
|
+
content_tag_for(:sup, words(2)),
|
137
142
|
content_tag_for(:code, words(2)),
|
143
|
+
content_tag_for(:small, words(2)),
|
138
144
|
(a 2).to_s
|
139
|
-
] + FFaker::Lorem.paragraphs(count))
|
145
|
+
] + FFaker::Lorem.paragraphs(count - 1))
|
140
146
|
fetch_sample(a, count: count).join(sep)
|
141
147
|
end
|
142
148
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module IdentificationIT
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
ETHNICITIES = [
|
9
|
+
'Afroamericano', 'Asiatico/isolano del Pacifico', 'Caucasico', 'Ispanico', 'Nativo americano',
|
10
|
+
'Multirazziale', 'Altro', 'Preferisco non rispondere'
|
11
|
+
].freeze
|
12
|
+
GENDERS = %w[Maschio Femmina].freeze
|
13
|
+
|
14
|
+
def drivers_license
|
15
|
+
FFaker::String.from_regexp(/U1[1-9]\d{7}[A-Z]/)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ssn
|
19
|
+
FFaker.numerify('####################')
|
20
|
+
end
|
21
|
+
|
22
|
+
def ethnicity
|
23
|
+
fetch_sample(ETHNICITIES)
|
24
|
+
end
|
25
|
+
|
26
|
+
def gender
|
27
|
+
fetch_sample(GENDERS)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -5,7 +5,8 @@ module FFaker
|
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
8
|
-
AREA_CODE = { a: 10, b: 11, c: 12, d: 13, e: 14, f: 15, g: 16, h: 17, i: 34, j: 18, k: 19, l: 20, m: 21, n: 22,
|
8
|
+
AREA_CODE = { a: 10, b: 11, c: 12, d: 13, e: 14, f: 15, g: 16, h: 17, i: 34, j: 18, k: 19, l: 20, m: 21, n: 22,
|
9
|
+
o: 35, p: 23, q: 24, r: 25, s: 26, t: 27, u: 28, v: 29, w: 32, x: 30, y: 31, z: 33 }.freeze
|
9
10
|
|
10
11
|
# Identity Card Number
|
11
12
|
# https://en.wikipedia.org/wiki/National_identification_card_(Taiwan)#Identity_card_number
|
@@ -14,7 +15,7 @@ module FFaker
|
|
14
15
|
code = AREA_CODE[letter.to_sym]
|
15
16
|
gender = fetch_sample([1, 2])
|
16
17
|
serial = FFaker.numerify('#######')
|
17
|
-
a, b, c, d, e, f, g, h, i, j = "#{code}#{gender}#{serial}".
|
18
|
+
a, b, c, d, e, f, g, h, i, j = "#{code}#{gender}#{serial}".chars.map(&:to_i)
|
18
19
|
|
19
20
|
checksum = (9 * a + b + 2 * c + 3 * d + 4 * e + 5 * f + 6 * g + 7 * h + 8 * i + 9 * j) % 10
|
20
21
|
"#{letter.upcase}#{gender}#{serial}#{checksum}"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
# Based on Perl's Text::Lorem
|
5
|
+
module LoremBR
|
6
|
+
extend ModuleUtils
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def characters(character_count = 255)
|
10
|
+
character_count = 0 if character_count.negative?
|
11
|
+
Array.new(character_count).map { fetch_sample(CHARACTERS) }.join
|
12
|
+
end
|
13
|
+
|
14
|
+
def word
|
15
|
+
fetch_sample(WORDS)
|
16
|
+
end
|
17
|
+
|
18
|
+
def words(num = 3)
|
19
|
+
fetch_sample(WORDS, count: num)
|
20
|
+
end
|
21
|
+
|
22
|
+
def sentence(word_count = 4)
|
23
|
+
first_word, *last_words = words(word_count + rand(1..5))
|
24
|
+
return "#{first_word.capitalize} #{last_words.join(' ')}." if last_words
|
25
|
+
|
26
|
+
first_word.capitalize
|
27
|
+
end
|
28
|
+
|
29
|
+
alias phrase sentence
|
30
|
+
|
31
|
+
def sentences(sentence_count = 3)
|
32
|
+
(1..sentence_count).map { sentence }
|
33
|
+
end
|
34
|
+
|
35
|
+
alias phrases sentences
|
36
|
+
|
37
|
+
def paragraph(sentence_count = 3)
|
38
|
+
sentences(sentence_count + rand(0..2)).join(' ')
|
39
|
+
end
|
40
|
+
|
41
|
+
def paragraphs(paragraph_count = 3)
|
42
|
+
(1..paragraph_count).map { paragraph }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module LoremIT
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def word
|
9
|
+
fetch_sample(WORDS)
|
10
|
+
end
|
11
|
+
|
12
|
+
def words(num = 3)
|
13
|
+
fetch_sample(WORDS, count: num)
|
14
|
+
end
|
15
|
+
|
16
|
+
def sentence(word_count = 4)
|
17
|
+
s = words(word_count + rand(0..5))
|
18
|
+
s = s.join(' ')
|
19
|
+
s.capitalize!
|
20
|
+
"#{s}."
|
21
|
+
end
|
22
|
+
|
23
|
+
alias phrase sentence
|
24
|
+
|
25
|
+
def sentences(sentence_count = 3)
|
26
|
+
(1..sentence_count).map { sentence }
|
27
|
+
end
|
28
|
+
|
29
|
+
alias phrases sentences
|
30
|
+
|
31
|
+
def paragraph(sentence_count = 3)
|
32
|
+
sentences(sentence_count + rand(0..2)).join(' ')
|
33
|
+
end
|
34
|
+
|
35
|
+
def paragraphs(paragraph_count = 3)
|
36
|
+
(1..paragraph_count).map { paragraph }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ffaker/name_th_en.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module Number
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def number(digits: 1)
|
9
|
+
FFaker.numerify(generate_pattern(digits)).to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def decimal(whole_digits: 1, fractional_digits: 1)
|
13
|
+
whole_part_pattern = generate_pattern(whole_digits)
|
14
|
+
fractional_part_pattern = generate_pattern(fractional_digits).reverse
|
15
|
+
FFaker.numerify("#{whole_part_pattern}.#{fractional_part_pattern}").to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generate_pattern(digits)
|
21
|
+
raise ArgumentError.new('Digits cannot be less than 1') if digits < 1
|
22
|
+
|
23
|
+
"#{fetch_sample(1..9)}#{"#" * (digits - 1)}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -24,15 +24,17 @@ module FFaker
|
|
24
24
|
number MOBILE_PHONE_PREFIXES
|
25
25
|
end
|
26
26
|
|
27
|
+
private
|
28
|
+
|
27
29
|
def number(prefixes)
|
28
|
-
|
29
|
-
COUNTRY_PREFIX
|
30
|
-
prefixes
|
30
|
+
pattern = [
|
31
|
+
fetch_sample(COUNTRY_PREFIX),
|
32
|
+
fetch_sample(prefixes),
|
31
33
|
random_space,
|
32
|
-
PHONE_NUMBER
|
33
|
-
].join
|
34
|
+
fetch_sample(PHONE_NUMBER)
|
35
|
+
].join
|
34
36
|
|
35
|
-
FFaker.numerify
|
37
|
+
FFaker.numerify(pattern)
|
36
38
|
end
|
37
39
|
|
38
40
|
def random_space
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
# Inspirations:
|
5
|
+
# https://olympic.ru/team/sport/
|
6
|
+
# http://ru.sport-wiki.org/vidy-sporta/
|
7
|
+
module SportRU
|
8
|
+
extend ModuleUtils
|
9
|
+
extend self
|
10
|
+
|
11
|
+
ALL = SUMMER + WINTER
|
12
|
+
|
13
|
+
def name
|
14
|
+
fetch_sample(ALL)
|
15
|
+
end
|
16
|
+
|
17
|
+
def summer
|
18
|
+
fetch_sample(SUMMER)
|
19
|
+
end
|
20
|
+
|
21
|
+
def winter
|
22
|
+
fetch_sample(WINTER)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/ffaker/ssn_se.rb
CHANGED
@@ -76,24 +76,5 @@ module FFaker
|
|
76
76
|
def three_character_string(number)
|
77
77
|
format('%03d', number)
|
78
78
|
end
|
79
|
-
|
80
|
-
# http://en.wikipedia.org/wiki/Luhn_algorithm
|
81
|
-
def luhn_check(number)
|
82
|
-
multiplications = []
|
83
|
-
|
84
|
-
number.split(//).each_with_index do |digit, i|
|
85
|
-
multiplications << i.even? ? digit.to_i * 2 : digit.to_i
|
86
|
-
end
|
87
|
-
|
88
|
-
sum = 0
|
89
|
-
multiplications.each do |num|
|
90
|
-
num.to_s.each_byte do |character|
|
91
|
-
sum += character.chr.to_i
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
control_digit = (sum % 10).zero? ? 0 : (sum / 10 + 1) * 10 - sum
|
96
|
-
control_digit.to_s
|
97
|
-
end
|
98
79
|
end
|
99
80
|
end
|
data/lib/ffaker/string.rb
CHANGED
@@ -53,15 +53,15 @@ module FFaker
|
|
53
53
|
when '?'
|
54
54
|
# TODO: Let ? generate nothing
|
55
55
|
'' # We already printed its target
|
56
|
-
when '+'
|
56
|
+
when '+'
|
57
57
|
tokens.unshift(token) if rand(0..1) == 1 # Leave the `+` on to run again
|
58
58
|
process_token(@last_token) # Run the last one at least once
|
59
|
-
when '*'
|
59
|
+
when '*'
|
60
60
|
tokens.unshift(token) if rand(0..1) == 1 # Leave the `*` on to run again
|
61
61
|
return '' if rand(0..1) == 1 # Or maybe do nothing
|
62
62
|
|
63
63
|
process_token(@last_token) # Else run the last one again
|
64
|
-
when '{'
|
64
|
+
when '{'
|
65
65
|
number = +''
|
66
66
|
while (ch = tokens.shift) != '}'
|
67
67
|
number << ch
|
@@ -76,14 +76,14 @@ module FFaker
|
|
76
76
|
|
77
77
|
def generate_token(token, tokens)
|
78
78
|
case token
|
79
|
-
when /\w/
|
79
|
+
when /\w/
|
80
80
|
@last_token = [token]
|
81
81
|
token
|
82
|
-
when BACKSLASH
|
82
|
+
when BACKSLASH
|
83
83
|
token = tokens.shift
|
84
84
|
@last_token = ['\\', token]
|
85
85
|
special(token)
|
86
|
-
when '['
|
86
|
+
when '['
|
87
87
|
set = []
|
88
88
|
while (ch = tokens.shift) != ']'
|
89
89
|
set << ch
|
data/lib/ffaker/time.rb
CHANGED
@@ -22,7 +22,7 @@ module FFaker
|
|
22
22
|
|
23
23
|
def datetime(params = {})
|
24
24
|
years_back = params[:year_range] || 5
|
25
|
-
latest_year = params
|
25
|
+
latest_year = params[:year_latest] || 0
|
26
26
|
year = (rand * years_back).ceil + (::DateTime.now.year - latest_year - years_back)
|
27
27
|
month = rand(1..12)
|
28
28
|
day = rand(1..Date.new(year, month, -1).day)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'array_utils'
|
4
|
+
require_relative 'random_utils'
|
5
|
+
require_relative 'unique_utils'
|
6
6
|
|
7
7
|
module FFaker
|
8
8
|
module ModuleUtils
|
@@ -35,5 +35,25 @@ module FFaker
|
|
35
35
|
def unique(max_retries = 10_000)
|
36
36
|
@unique_generator ||= FFaker::UniqueUtils.new(self, max_retries)
|
37
37
|
end
|
38
|
+
|
39
|
+
# http://en.wikipedia.org/wiki/Luhn_algorithm
|
40
|
+
def luhn_check(number)
|
41
|
+
multiplications = []
|
42
|
+
|
43
|
+
number.split(//).each_with_index do |digit, i|
|
44
|
+
multiplications << i.even? ? digit.to_i * 2 : digit.to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
sum = 0
|
48
|
+
multiplications.each do |num|
|
49
|
+
num.to_s.each_byte do |character|
|
50
|
+
sum += character.chr.to_i
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
control_digit = (sum % 10).zero? ? 0 : (sum / 10 + 1) * 10 - sum
|
55
|
+
control_digit.to_s
|
56
|
+
end
|
57
|
+
|
38
58
|
end
|
39
59
|
end
|
data/lib/ffaker/vehicle.rb
CHANGED
@@ -2,6 +2,68 @@
|
|
2
2
|
|
3
3
|
module FFaker
|
4
4
|
module Vehicle
|
5
|
+
module VIN
|
6
|
+
extend ModuleUtils
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# https://en.wikibooks.org/wiki/Vehicle_Identification_Numbers_(VIN_codes)/World_Manufacturer_Identifier_(WMI)
|
10
|
+
VALID_WMI_REGIONS = [*'A'..'C', *'J'..'Z', *'1'..'9'].freeze
|
11
|
+
|
12
|
+
VALID_YEAR_CHARS = %w[
|
13
|
+
5 6 7 8 9 A B C D E F G H J K L M N P R S T V W X Y 1 2 3 4 5 6 7 8 9
|
14
|
+
].freeze # 2005-2039
|
15
|
+
|
16
|
+
# https://en.wikibooks.org/wiki/Vehicle_Identification_Numbers_(VIN_codes)/Check_digit
|
17
|
+
TRANSLITERATION_VALUES = {
|
18
|
+
'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8,
|
19
|
+
'J' => 1, 'K' => 2, 'L' => 3, 'M' => 4, 'N' => 5, 'P' => 7, 'R' => 9,
|
20
|
+
'S' => 2, 'T' => 3, 'U' => 4, 'V' => 5, 'W' => 6, 'X' => 7, 'Y' => 8, 'Z' => 9
|
21
|
+
}.freeze
|
22
|
+
POSITION_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
23
|
+
|
24
|
+
VALID_ALPHA = TRANSLITERATION_VALUES.keys
|
25
|
+
VALID_ALPHANUMERIC = [*VALID_ALPHA, *'1'..'9'].freeze
|
26
|
+
|
27
|
+
# Generate a VIN that is compliant with specifications of US Title 49 Section 565.15
|
28
|
+
# https://www.govinfo.gov/content/pkg/CFR-2019-title49-vol6/xml/CFR-2019-title49-vol6-part565.xml#seqnum565.15
|
29
|
+
#
|
30
|
+
# Position Meaning
|
31
|
+
# 1-3 Manufacturer ID aka WMI (alpha and digits)
|
32
|
+
# 4-8 Vehicle Description ("For passenger cars ..[position 7].. shall be alphabetic")
|
33
|
+
# 9 Check Digit (0-9 or "X")
|
34
|
+
# 10 Year (see VIN_VALID_YEARS)
|
35
|
+
# 11 Plant of manufacture (alpha and digits)
|
36
|
+
# 12-17 Serial number (digits only)
|
37
|
+
#
|
38
|
+
# I, O and Q are NOT allowed. VIN_VALID_ALPHA has valid alpha characters.
|
39
|
+
def vin
|
40
|
+
generated_vin = [
|
41
|
+
# Manufacturer ID / WMI
|
42
|
+
fetch_sample(VALID_WMI_REGIONS),
|
43
|
+
fetch_sample(VALID_ALPHANUMERIC, count: 2),
|
44
|
+
# Vehicle Description
|
45
|
+
fetch_sample(VALID_ALPHANUMERIC, count: 3),
|
46
|
+
fetch_sample(VALID_ALPHA),
|
47
|
+
fetch_sample(VALID_ALPHANUMERIC),
|
48
|
+
'0', # check digit placeholder
|
49
|
+
fetch_sample(VALID_YEAR_CHARS), # Year of Manufacture
|
50
|
+
fetch_sample(VALID_ALPHANUMERIC), # Plant ID
|
51
|
+
FFaker.numerify('######') # Serial Number
|
52
|
+
].join
|
53
|
+
|
54
|
+
# Calculate the Check Digit
|
55
|
+
weighted_sum = generated_vin.chars.each_with_index.sum do |char, idx|
|
56
|
+
(TRANSLITERATION_VALUES[char.to_sym] || char).to_i * POSITION_WEIGHTS[idx]
|
57
|
+
end
|
58
|
+
|
59
|
+
check_digit = weighted_sum % 11
|
60
|
+
check_digit = 'X' if check_digit == 10
|
61
|
+
generated_vin[8] = check_digit.to_s
|
62
|
+
|
63
|
+
generated_vin
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
5
67
|
extend ModuleUtils
|
6
68
|
extend self
|
7
69
|
|
@@ -37,7 +99,7 @@ module FFaker
|
|
37
99
|
end
|
38
100
|
|
39
101
|
def vin
|
40
|
-
|
102
|
+
VIN.vin
|
41
103
|
end
|
42
104
|
|
43
105
|
def year
|
data/lib/ffaker.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module FFaker
|
4
|
-
|
5
|
-
|
4
|
+
require_relative 'ffaker/utils/array_utils'
|
5
|
+
require_relative 'ffaker/utils/module_utils'
|
6
6
|
|
7
7
|
extend ModuleUtils
|
8
8
|
|
@@ -43,6 +43,7 @@ module FFaker
|
|
43
43
|
autoload :AddressGR, 'ffaker/address_gr'
|
44
44
|
autoload :AddressID, 'ffaker/address_id'
|
45
45
|
autoload :AddressIN, 'ffaker/address_in'
|
46
|
+
autoload :AddressIT, 'ffaker/address_it'
|
46
47
|
autoload :AddressJA, 'ffaker/address_ja'
|
47
48
|
autoload :AddressKR, 'ffaker/address_kr'
|
48
49
|
autoload :AddressMX, 'ffaker/address_mx'
|
@@ -56,6 +57,7 @@ module FFaker
|
|
56
57
|
autoload :AddressUS, 'ffaker/address_us'
|
57
58
|
autoload :Airline, 'ffaker/airline'
|
58
59
|
autoload :Animal, 'ffaker/animal'
|
60
|
+
autoload :AnimalBR, 'ffaker/animal_br'
|
59
61
|
autoload :AnimalCN, 'ffaker/animal_cn'
|
60
62
|
autoload :AnimalES, 'ffaker/animal_es'
|
61
63
|
autoload :AnimalPL, 'ffaker/animal_pl'
|
@@ -73,11 +75,12 @@ module FFaker
|
|
73
75
|
autoload :ColorUA, 'ffaker/color_ua'
|
74
76
|
autoload :Company, 'ffaker/company'
|
75
77
|
autoload :CompanyCN, 'ffaker/company_cn'
|
78
|
+
autoload :CompanyFR, 'ffaker/company_fr'
|
76
79
|
autoload :CompanyIT, 'ffaker/company_it'
|
77
80
|
autoload :CompanyJA, 'ffaker/company_ja'
|
78
81
|
autoload :CompanySE, 'ffaker/company_se'
|
79
82
|
autoload :Conference, 'ffaker/conference'
|
80
|
-
autoload :CoursesFR, 'ffaker/
|
83
|
+
autoload :CoursesFR, 'ffaker/courses_fr'
|
81
84
|
autoload :Currency, 'ffaker/currency'
|
82
85
|
autoload :DizzleIpsum, 'ffaker/dizzle_ipsum'
|
83
86
|
autoload :Education, 'ffaker/education'
|
@@ -86,14 +89,17 @@ module FFaker
|
|
86
89
|
autoload :Food, 'ffaker/food'
|
87
90
|
autoload :FoodPL, 'ffaker/food_pl'
|
88
91
|
autoload :FreedomIpsum, 'ffaker/freedom_ipsum'
|
92
|
+
autoload :Game, 'ffaker/game'
|
89
93
|
autoload :Gender, 'ffaker/gender'
|
90
94
|
autoload :GenderBR, 'ffaker/gender_br'
|
91
95
|
autoload :GenderCN, 'ffaker/gender_cn'
|
92
96
|
autoload :GenderID, 'ffaker/gender_id'
|
97
|
+
autoload :GenderIT, 'ffaker/gender_it'
|
93
98
|
autoload :GenderJA, 'ffaker/gender_ja'
|
94
99
|
autoload :GenderJP, 'ffaker/gender_jp'
|
95
100
|
autoload :GenderKR, 'ffaker/gender_kr'
|
96
101
|
autoload :GenderPL, 'ffaker/gender_pl'
|
102
|
+
autoload :GenderRU, 'ffaker/gender_ru'
|
97
103
|
autoload :Geolocation, 'ffaker/geolocation'
|
98
104
|
autoload :Guid, 'ffaker/guid'
|
99
105
|
autoload :HealthcareIpsum, 'ffaker/healthcare_ipsum'
|
@@ -106,6 +112,7 @@ module FFaker
|
|
106
112
|
autoload :IdentificationESCL, 'ffaker/identification_es_cl'
|
107
113
|
autoload :IdentificationESCO, 'ffaker/identification_es_co'
|
108
114
|
autoload :IdentificationIN, 'ffaker/identification_in'
|
115
|
+
autoload :IdentificationIT, 'ffaker/identification_it'
|
109
116
|
autoload :IdentificationKr, 'ffaker/identification_kr'
|
110
117
|
autoload :IdentificationMX, 'ffaker/identification_mx'
|
111
118
|
autoload :IdentificationPL, 'ffaker/identification_pl'
|
@@ -117,15 +124,18 @@ module FFaker
|
|
117
124
|
autoload :JobBR, 'ffaker/job_br'
|
118
125
|
autoload :JobCN, 'ffaker/job_cn'
|
119
126
|
autoload :JobFR, 'ffaker/job_fr'
|
127
|
+
autoload :JobIT, 'ffaker/job_it'
|
120
128
|
autoload :JobJA, 'ffaker/job_ja'
|
121
129
|
autoload :JobKR, 'ffaker/job_kr'
|
122
130
|
autoload :JobVN, 'ffaker/job_vn'
|
123
131
|
autoload :Locale, 'ffaker/locale'
|
124
132
|
autoload :Lorem, 'ffaker/lorem'
|
125
133
|
autoload :LoremAR, 'ffaker/lorem_ar'
|
134
|
+
autoload :LoremBR, 'ffaker/lorem_br'
|
126
135
|
autoload :LoremCN, 'ffaker/lorem_cn'
|
127
136
|
autoload :LoremFR, 'ffaker/lorem_fr'
|
128
137
|
autoload :LoremIE, 'ffaker/lorem_ie'
|
138
|
+
autoload :LoremIT, 'ffaker/lorem_it'
|
129
139
|
autoload :LoremJA, 'ffaker/lorem_ja'
|
130
140
|
autoload :LoremKR, 'ffaker/lorem_kr'
|
131
141
|
autoload :LoremPL, 'ffaker/lorem_pl'
|
@@ -164,6 +174,7 @@ module FFaker
|
|
164
174
|
autoload :NameUA, 'ffaker/name_ua'
|
165
175
|
autoload :NameVN, 'ffaker/name_vn'
|
166
176
|
autoload :NatoAlphabet, 'ffaker/nato_alphabet'
|
177
|
+
autoload :Number, 'ffaker/number'
|
167
178
|
autoload :PhoneNumber, 'ffaker/phone_number'
|
168
179
|
autoload :PhoneNumberAU, 'ffaker/phone_number_au'
|
169
180
|
autoload :PhoneNumberBR, 'ffaker/phone_number_br'
|
@@ -191,6 +202,7 @@ module FFaker
|
|
191
202
|
autoload :Sport, 'ffaker/sport'
|
192
203
|
autoload :SportPL, 'ffaker/sport_pl'
|
193
204
|
autoload :SportUS, 'ffaker/sport_us'
|
205
|
+
autoload :SportRU, 'ffaker/sport_ru'
|
194
206
|
autoload :SSN, 'ffaker/ssn'
|
195
207
|
autoload :SSNMX, 'ffaker/ssn_mx'
|
196
208
|
autoload :SSNSE, 'ffaker/ssn_se'
|
data/lib/version.rb
CHANGED