ffaker 2.2.0 → 2.3.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 +34 -0
- data/README.md +4 -0
- data/REFERENCE.md +1153 -800
- data/Rakefile +23 -24
- data/ffaker.gemspec +12 -420
- data/lib/ffaker.rb +47 -7
- data/lib/ffaker/address.rb +11 -11
- data/lib/ffaker/address_au.rb +60 -60
- data/lib/ffaker/address_br.rb +5 -5
- data/lib/ffaker/address_ca.rb +7 -7
- data/lib/ffaker/address_ch.rb +1 -2
- data/lib/ffaker/address_ch_de.rb +1 -1
- data/lib/ffaker/address_ch_fr.rb +1 -1
- data/lib/ffaker/address_ch_it.rb +1 -1
- data/lib/ffaker/address_da.rb +5 -5
- data/lib/ffaker/address_de.rb +16 -12
- data/lib/ffaker/address_fi.rb +7 -8
- data/lib/ffaker/address_fr.rb +13 -13
- data/lib/ffaker/address_gr.rb +40 -0
- data/lib/ffaker/address_in.rb +12 -12
- data/lib/ffaker/address_kr.rb +87 -0
- data/lib/ffaker/address_mx.rb +409 -409
- data/lib/ffaker/address_nl.rb +17 -13
- data/lib/ffaker/address_ru.rb +6 -6
- data/lib/ffaker/address_se.rb +7 -8
- data/lib/ffaker/address_sn.rb +3 -3
- data/lib/ffaker/address_ua.rb +8 -8
- data/lib/ffaker/address_uk.rb +5 -5
- data/lib/ffaker/address_us.rb +9 -9
- data/lib/ffaker/airline.rb +16 -0
- data/lib/ffaker/avatar.rb +3 -3
- data/lib/ffaker/aws.rb +24 -0
- data/lib/ffaker/bacon_ipsum.rb +2 -2
- data/lib/ffaker/book.rb +45 -0
- data/lib/ffaker/boolean.rb +2 -2
- data/lib/ffaker/cheesy_lingo.rb +15 -12
- data/lib/ffaker/color.rb +54 -1
- data/lib/ffaker/color_ua.rb +1 -1
- data/lib/ffaker/company.rb +13 -11
- data/lib/ffaker/company_cn.rb +23 -0
- data/lib/ffaker/company_it.rb +4 -4
- data/lib/ffaker/company_se.rb +2 -2
- data/lib/ffaker/conference.rb +1 -1
- data/lib/ffaker/courses.rb +2 -3
- data/lib/ffaker/currency.rb +2 -2
- data/lib/ffaker/data/address_gr/city +79 -0
- data/lib/ffaker/data/address_gr/region +13 -0
- data/lib/ffaker/data/address_gr/street +100 -0
- data/lib/ffaker/data/address_kr/boroughs +29 -0
- data/lib/ffaker/data/address_kr/cities +51 -0
- data/lib/ffaker/data/airline/codes_list +209 -0
- data/lib/ffaker/data/airline/names_list +206 -0
- data/lib/ffaker/data/aws/ec2_instance_type +59 -0
- data/lib/ffaker/data/aws/ec2_reserved_instance_tenancy +3 -0
- data/lib/ffaker/data/aws/ec2_reserved_offering_type +6 -0
- data/lib/ffaker/data/aws/ec2_reserved_product_description +14 -0
- data/lib/ffaker/data/book/adj_and_adv +20 -0
- data/lib/ffaker/data/book/genres +369 -0
- data/lib/ffaker/data/book/nouns +36 -0
- data/lib/ffaker/data/book/prefixes +17 -0
- data/lib/ffaker/data/color/names_list +128 -0
- data/lib/ffaker/data/education/degree_prefix +274 -0
- data/lib/ffaker/data/education/degree_short_prefix +19 -0
- data/lib/ffaker/data/job_br/job_nouns +52 -0
- data/lib/ffaker/data/job_vn/job_nouns +191 -0
- data/lib/ffaker/data/lorem_ja/characters +101 -0
- data/lib/ffaker/data/lorem_ja/sentences +30 -0
- data/lib/ffaker/data/lorem_ja/sentences_end +21 -0
- data/lib/ffaker/data/lorem_ja/words +81 -0
- data/lib/ffaker/data/name/first_names_female +4275 -0
- data/lib/ffaker/data/name/first_names_male +1219 -0
- data/lib/ffaker/data/name_br/first_names_female +1068 -0
- data/lib/ffaker/data/name_br/first_names_male +607 -0
- data/lib/ffaker/data/name_br/last_names +52 -0
- data/lib/ffaker/data/name_gr/female_first_names +80 -0
- data/lib/ffaker/data/name_gr/female_last_names +45 -0
- data/lib/ffaker/data/name_gr/male_first_names +90 -0
- data/lib/ffaker/data/name_gr/male_last_names +57 -0
- data/lib/ffaker/data/name_kh/first_names +64 -0
- data/lib/ffaker/data/name_kh/last_names +71 -0
- data/lib/ffaker/data/name_kh/nick_names +30 -0
- data/lib/ffaker/data/name_then/first_names +292 -0
- data/lib/ffaker/data/name_then/last_names +63 -0
- data/lib/ffaker/data/name_then/nick_names +30 -0
- data/lib/ffaker/data/phone_number/phone_calling_code +205 -0
- data/lib/ffaker/data/sport/names +57 -24
- data/lib/ffaker/data/tweet/hashtag +58 -0
- data/lib/ffaker/data/youtube/video_ids +50 -0
- data/lib/ffaker/dizzle_ipsum.rb +2 -2
- data/lib/ffaker/education.rb +17 -16
- data/lib/ffaker/food.rb +5 -6
- data/lib/ffaker/gender.rb +4 -4
- data/lib/ffaker/gender_br.rb +17 -0
- data/lib/ffaker/gender_cn.rb +4 -4
- data/lib/ffaker/gender_kr.rb +4 -4
- data/lib/ffaker/geolocation.rb +26 -26
- data/lib/ffaker/healthcare_ipsum.rb +2 -2
- data/lib/ffaker/hipster_ipsum.rb +2 -2
- data/lib/ffaker/html_ipsum.rb +101 -81
- data/lib/ffaker/identification.rb +4 -4
- data/lib/ffaker/identification_br.rb +84 -0
- data/lib/ffaker/identification_es.rb +2 -2
- data/lib/ffaker/identification_es_cl.rb +7 -5
- data/lib/ffaker/identification_es_co.rb +9 -10
- data/lib/ffaker/identification_kr.rb +3 -4
- data/lib/ffaker/identification_mx.rb +27 -11
- data/lib/ffaker/internet.rb +26 -23
- data/lib/ffaker/internet_se.rb +21 -21
- data/lib/ffaker/job.rb +1 -1
- data/lib/ffaker/job_br.rb +12 -0
- data/lib/ffaker/job_cn.rb +1 -1
- data/lib/ffaker/job_fr.rb +3 -3
- data/lib/ffaker/job_ja.rb +2 -1
- data/lib/ffaker/job_kr.rb +1 -1
- data/lib/ffaker/job_vn.rb +13 -0
- data/lib/ffaker/locale.rb +2 -3
- data/lib/ffaker/lorem.rb +5 -5
- data/lib/ffaker/lorem_ar.rb +4 -4
- data/lib/ffaker/lorem_cn.rb +3 -3
- data/lib/ffaker/lorem_fr.rb +4 -4
- data/lib/ffaker/lorem_ja.rb +40 -0
- data/lib/ffaker/lorem_kr.rb +4 -4
- data/lib/ffaker/lorem_ua.rb +8 -11
- data/lib/ffaker/movie.rb +18 -20
- data/lib/ffaker/music.rb +4 -4
- data/lib/ffaker/name.rb +100 -11
- data/lib/ffaker/name_br.rb +37 -6
- data/lib/ffaker/name_cn.rb +2 -2
- data/lib/ffaker/name_cs.rb +10 -10
- data/lib/ffaker/name_da.rb +6 -6
- data/lib/ffaker/name_de.rb +5 -5
- data/lib/ffaker/name_fr.rb +4 -4
- data/lib/ffaker/name_ga.rb +4 -5
- data/lib/ffaker/name_gr.rb +60 -0
- data/lib/ffaker/name_it.rb +4 -4
- data/lib/ffaker/name_ja.rb +3 -3
- data/lib/ffaker/name_kh.rb +22 -0
- data/lib/ffaker/name_kr.rb +3 -3
- data/lib/ffaker/name_mx.rb +14 -14
- data/lib/ffaker/name_nb.rb +5 -5
- data/lib/ffaker/name_nl.rb +7 -7
- data/lib/ffaker/name_ph.rb +2 -2
- data/lib/ffaker/name_ru.rb +7 -8
- data/lib/ffaker/name_se.rb +5 -5
- data/lib/ffaker/name_sn.rb +23 -23
- data/lib/ffaker/name_th.rb +3 -3
- data/lib/ffaker/name_th_en.rb +26 -0
- data/lib/ffaker/name_ua.rb +8 -8
- data/lib/ffaker/name_vn.rb +4 -4
- data/lib/ffaker/nato_alphabet.rb +10 -10
- data/lib/ffaker/phone_number.rb +31 -21
- data/lib/ffaker/phone_number_au.rb +3 -3
- data/lib/ffaker/phone_number_br.rb +9 -8
- data/lib/ffaker/phone_number_ch.rb +7 -7
- data/lib/ffaker/phone_number_cu.rb +5 -5
- data/lib/ffaker/phone_number_de.rb +1 -1
- data/lib/ffaker/phone_number_fr.rb +4 -4
- data/lib/ffaker/phone_number_it.rb +2 -2
- data/lib/ffaker/phone_number_kr.rb +4 -4
- data/lib/ffaker/phone_number_mx.rb +4 -5
- data/lib/ffaker/phone_number_nl.rb +13 -13
- data/lib/ffaker/phone_number_se.rb +18 -19
- data/lib/ffaker/phone_number_sg.rb +8 -8
- data/lib/ffaker/phone_number_sn.rb +2 -2
- data/lib/ffaker/product.rb +18 -14
- data/lib/ffaker/skill.rb +3 -3
- data/lib/ffaker/sport.rb +1 -1
- data/lib/ffaker/ssn_se.rb +19 -20
- data/lib/ffaker/string.rb +21 -23
- data/lib/ffaker/time.rb +19 -7
- data/lib/ffaker/tweet.rb +59 -0
- data/lib/ffaker/unit.rb +12 -12
- data/lib/ffaker/unit_english.rb +34 -35
- data/lib/ffaker/unit_metric.rb +25 -25
- data/lib/ffaker/utils/array_utils.rb +12 -9
- data/lib/ffaker/utils/module_utils.rb +9 -6
- data/lib/ffaker/utils/random_utils.rb +33 -0
- data/lib/ffaker/vehicle.rb +21 -21
- data/lib/ffaker/venue.rb +1 -1
- data/lib/ffaker/youtube.rb +24 -0
- data/scripts/benchmark.rb +3 -3
- data/scripts/reference.rb +26 -23
- data/test/helper.rb +50 -0
- data/test/test_address.rb +40 -21
- data/test/test_address_au.rb +19 -9
- data/test/test_address_br.rb +9 -2
- data/test/test_address_ca.rb +7 -0
- data/test/test_address_ch.rb +6 -2
- data/test/test_address_ch_de.rb +7 -3
- data/test/test_address_ch_fr.rb +7 -3
- data/test/test_address_ch_it.rb +5 -1
- data/test/test_address_da.rb +18 -9
- data/test/test_address_de.rb +12 -5
- data/test/test_address_fi.rb +10 -3
- data/test/test_address_fr.rb +13 -0
- data/test/test_address_gr.rb +43 -0
- data/test/test_address_in.rb +20 -12
- data/test/test_address_kr.rb +14 -0
- data/test/test_address_mx.rb +12 -5
- data/test/test_address_nl.rb +11 -5
- data/test/test_address_ru.rb +11 -5
- data/test/test_address_se.rb +9 -3
- data/test/test_address_sn.rb +7 -1
- data/test/test_address_ua.rb +17 -10
- data/test/test_address_uk.rb +11 -3
- data/test/test_address_us.rb +15 -6
- data/test/test_airline.rb +17 -0
- data/test/test_array_utils.rb +51 -3
- data/test/test_avatar.rb +5 -1
- data/test/test_aws.rb +25 -0
- data/test/test_bacon_ipsum.rb +12 -6
- data/test/test_book.rb +41 -0
- data/test/test_boolean.rb +4 -0
- data/test/test_cheesy_lingo.rb +14 -10
- data/test/test_color.rb +126 -1
- data/test/test_color_ua.rb +5 -1
- data/test/test_company.rb +7 -0
- data/test/test_company_cn.rb +24 -0
- data/test/test_company_it.rb +7 -1
- data/test/test_company_se.rb +6 -0
- data/test/test_conference.rb +5 -2
- data/test/test_course_mathematiques.rb +5 -1
- data/test/test_course_philosophie.rb +5 -1
- data/test/test_currency.rb +12 -0
- data/test/test_dizzle_ipsum.rb +12 -6
- data/test/test_education.rb +9 -2
- data/test/test_faker.rb +8 -1
- data/test/test_food.rb +11 -4
- data/test/test_gender.rb +5 -1
- data/test/test_gender_br.rb +18 -0
- data/test/test_gender_cn.rb +5 -2
- data/test/test_gender_kr.rb +7 -3
- data/test/test_geolocation.rb +11 -8
- data/test/test_guid.rb +6 -1
- data/test/test_healthcare_ipsum.rb +13 -6
- data/test/test_hipster_ipsum.rb +13 -6
- data/test/test_html_ipsum.rb +28 -20
- data/test/test_identification.rb +9 -2
- data/test/test_identification_br.rb +46 -0
- data/test/test_identification_co.rb +7 -0
- data/test/test_identification_es.rb +5 -1
- data/test/test_identification_es_cl.rb +5 -1
- data/test/test_identification_es_mx.rb +7 -2
- data/test/test_identification_kr.rb +4 -0
- data/test/test_internet.rb +36 -5
- data/test/test_internet_se.rb +12 -4
- data/test/test_job.rb +4 -0
- data/test/test_job_br.rb +17 -0
- data/test/test_job_cn.rb +4 -0
- data/test/test_job_fr.rb +4 -0
- data/test/test_job_ja.rb +4 -0
- data/test/test_job_kr.rb +4 -0
- data/test/test_job_vn.rb +22 -0
- data/test/test_locale.rb +10 -4
- data/test/test_lorem.rb +18 -11
- data/test/test_lorem_ar.rb +16 -8
- data/test/test_lorem_cn.rb +9 -2
- data/test/test_lorem_fr.rb +16 -8
- data/test/test_lorem_ja.rb +81 -0
- data/test/test_lorem_kr.rb +17 -8
- data/test/test_lorem_ua.rb +15 -8
- data/test/test_module_utils.rb +2 -2
- data/test/test_movie.rb +5 -1
- data/test/test_music.rb +11 -4
- data/test/test_name.rb +114 -1
- data/test/test_name_br.rb +41 -2
- data/test/test_name_cn.rb +7 -0
- data/test/test_name_cs.rb +7 -0
- data/test/test_name_da.rb +13 -6
- data/test/test_name_de.rb +4 -0
- data/test/test_name_fr.rb +7 -0
- data/test/test_name_ga.rb +7 -0
- data/test/test_name_gr.rb +70 -0
- data/test/test_name_it.rb +7 -0
- data/test/test_name_ja.rb +7 -0
- data/test/test_name_kh.rb +32 -0
- data/test/test_name_kr.rb +7 -0
- data/test/test_name_mx.rb +9 -0
- data/test/test_name_nb.rb +8 -0
- data/test/test_name_nl.rb +4 -0
- data/test/test_name_ph.rb +7 -0
- data/test/test_name_ru.rb +10 -3
- data/test/test_name_se.rb +12 -4
- data/test/test_name_sn.rb +8 -0
- data/test/test_name_th.rb +7 -0
- data/test/test_name_th_en.rb +35 -0
- data/test/test_name_ua.rb +26 -17
- data/test/test_name_vn.rb +42 -0
- data/test/test_nato_alphabet.rb +15 -4
- data/test/test_phone_number.rb +24 -6
- data/test/test_phone_number_au.rb +17 -6
- data/test/test_phone_number_br.rb +22 -13
- data/test/test_phone_number_cu.rb +29 -18
- data/test/test_phone_number_da.rb +16 -7
- data/test/test_phone_number_de.rb +17 -9
- data/test/test_phone_number_kr.rb +9 -0
- data/test/test_phone_number_mx.rb +16 -8
- data/test/test_phone_number_nl.rb +9 -2
- data/test/test_phone_number_se.rb +12 -7
- data/test/test_phone_number_sg.rb +17 -9
- data/test/test_phone_number_sn.rb +12 -4
- data/test/test_products.rb +22 -0
- data/test/test_skill.rb +8 -2
- data/test/test_sports.rb +4 -0
- data/test/test_ssn.rb +3 -1
- data/test/test_ssn_mx.rb +6 -1
- data/test/test_ssn_se.rb +3 -0
- data/test/test_string.rb +28 -1
- data/test/test_time.rb +33 -2
- data/test/test_tweet.rb +59 -0
- data/test/test_units.rb +7 -0
- data/test/test_units_english.rb +9 -0
- data/test/test_units_metric.rb +9 -0
- data/test/test_vehicle.rb +24 -15
- data/test/test_venue.rb +5 -1
- data/test/test_youtube.rb +28 -0
- metadata +101 -5
- data/lib/ffaker/data/name/first_names +0 -3008
- data/lib/ffaker/data/name_br/first_names +0 -91
data/lib/ffaker/unit_metric.rb
CHANGED
@@ -11,30 +11,30 @@ module FFaker
|
|
11
11
|
extend self
|
12
12
|
|
13
13
|
LENGTH_UNITS = [
|
14
|
-
{ name:
|
15
|
-
{ name:
|
16
|
-
{
|
17
|
-
{ name:
|
18
|
-
]
|
14
|
+
{ name: 'millimeters', abbreviation: 'mm' },
|
15
|
+
{ name: 'centimeters', abbreviation: 'cm' },
|
16
|
+
{ name: 'meters', abbreviation: 'm' },
|
17
|
+
{ name: 'kilometers', abbreviation: 'km' }
|
18
|
+
].freeze
|
19
19
|
MASS_UNITS = [
|
20
|
-
{ name:
|
21
|
-
{ name:
|
22
|
-
{ name:
|
23
|
-
]
|
20
|
+
{ name: 'gram', abbreviation: 'g' },
|
21
|
+
{ name: 'kilogram', abbreviation: 'kg' },
|
22
|
+
{ name: 'metric ton', abbreviation: 'mt' }
|
23
|
+
].freeze
|
24
24
|
LIQUID_UNITS = [
|
25
|
-
{ name:
|
26
|
-
{ name:
|
27
|
-
]
|
25
|
+
{ name: 'milliliters', abbreviation: 'ml' },
|
26
|
+
{ name: 'liters', abbreviation: 'L' }
|
27
|
+
].freeze
|
28
28
|
VOLUME_UNITS = [
|
29
|
-
{ name:
|
30
|
-
{ name:
|
31
|
-
]
|
29
|
+
{ name: ' cubic centimeters', abbreviation: 'cm^3' },
|
30
|
+
{ name: 'cubic meters', abbreviation: 'm^3' }
|
31
|
+
].freeze
|
32
32
|
AREA_UNITS = [
|
33
|
-
{ name:
|
34
|
-
{ name:
|
35
|
-
{ name:
|
36
|
-
{ name:
|
37
|
-
]
|
33
|
+
{ name: 'centimeters squared', abbreviation: 'cm^2' },
|
34
|
+
{ name: 'meters squared', abbreviation: 'm^2' },
|
35
|
+
{ name: 'hectares', abbreviation: 'ha' },
|
36
|
+
{ name: 'kilometers', abbreviation: 'km' }
|
37
|
+
].freeze
|
38
38
|
|
39
39
|
def mass_name
|
40
40
|
mass.name
|
@@ -79,23 +79,23 @@ module FFaker
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def length
|
82
|
-
OpenStruct.new
|
82
|
+
OpenStruct.new(fetch_sample(LENGTH_UNITS))
|
83
83
|
end
|
84
84
|
|
85
85
|
def mass
|
86
|
-
OpenStruct.new
|
86
|
+
OpenStruct.new(fetch_sample(MASS_UNITS))
|
87
87
|
end
|
88
88
|
|
89
89
|
def liquid
|
90
|
-
OpenStruct.new
|
90
|
+
OpenStruct.new(fetch_sample(LIQUID_UNITS))
|
91
91
|
end
|
92
92
|
|
93
93
|
def volume
|
94
|
-
OpenStruct.new
|
94
|
+
OpenStruct.new(fetch_sample(VOLUME_UNITS))
|
95
95
|
end
|
96
96
|
|
97
97
|
def area
|
98
|
-
OpenStruct.new
|
98
|
+
OpenStruct.new(fetch_sample(AREA_UNITS))
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'ffaker/utils/random_utils'
|
1
2
|
module FFaker
|
2
3
|
module ArrayUtils
|
4
|
+
extend RandomUtils
|
5
|
+
|
3
6
|
def self.const_array(argument)
|
4
7
|
array = argument.is_a?(Array) ? argument : argument.to_a
|
5
8
|
array.extend ArrayUtils
|
@@ -7,13 +10,13 @@ module FFaker
|
|
7
10
|
end
|
8
11
|
|
9
12
|
def self.random_pick(array, n)
|
10
|
-
warn '[ArrayUtils.random_pick] is deprecated. Please use the
|
11
|
-
array
|
13
|
+
warn '[ArrayUtils.random_pick] is deprecated. Please use the ModuleUtils#fetch_sample method'
|
14
|
+
fetch_sample(array, count: n)
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.rand(array)
|
15
|
-
warn '[ArrayUtils.rand] is deprecated. Please use the
|
16
|
-
array
|
18
|
+
warn '[ArrayUtils.rand] is deprecated. Please use the ModuleUtils#fetch_sample method'
|
19
|
+
fetch_sample(array)
|
17
20
|
end
|
18
21
|
|
19
22
|
def self.freeze_all(array)
|
@@ -23,17 +26,17 @@ module FFaker
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def self.shuffle(array)
|
26
|
-
array.sort_by{
|
29
|
+
array.sort_by { FFaker::Random.rand }
|
27
30
|
end
|
28
31
|
|
29
32
|
def random_pick(n)
|
30
|
-
warn '[ArrayUtils#random_pick] is deprecated. Please use the
|
31
|
-
|
33
|
+
warn '[ArrayUtils#random_pick] is deprecated. Please use the ModuleUtils#fetch_sample method'
|
34
|
+
ArrayUtils.random_pick(self, n)
|
32
35
|
end
|
33
36
|
|
34
37
|
def rand
|
35
|
-
warn '[ArrayUtils#rand] is deprecated. Please use the
|
36
|
-
|
38
|
+
warn '[ArrayUtils#rand] is deprecated. Please use the ModuleUtils#fetch_sample method'
|
39
|
+
ArrayUtils.rand(self)
|
37
40
|
end
|
38
41
|
|
39
42
|
def freeze_all
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'ffaker/utils/array_utils'
|
2
|
+
require 'ffaker/utils/random_utils'
|
2
3
|
|
3
4
|
module FFaker
|
4
5
|
module ModuleUtils
|
6
|
+
include RandomUtils
|
7
|
+
|
5
8
|
def k(arg)
|
6
9
|
FFaker::ArrayUtils.const_array(arg)
|
7
10
|
end
|
@@ -10,7 +13,7 @@ module FFaker
|
|
10
13
|
if const_name =~ /[a-z]/ # Not a constant, probably a class/module name.
|
11
14
|
super const_name
|
12
15
|
else
|
13
|
-
mod_name = ancestors.first.to_s.split(
|
16
|
+
mod_name = ancestors.first.to_s.split('::').last
|
14
17
|
data_path = "#{FFaker::BASE_LIB_PATH}/ffaker/data/#{underscore(mod_name)}/#{underscore(const_name.to_s)}"
|
15
18
|
data = k File.read(data_path).split("\n")
|
16
19
|
const_set const_name, data
|
@@ -19,11 +22,11 @@ module FFaker
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def underscore(string)
|
22
|
-
string.gsub(/::/, '/')
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
string.gsub(/::/, '/')
|
26
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
27
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
28
|
+
.tr('-', '_')
|
29
|
+
.downcase
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FFaker
|
2
|
+
# Methods for returning repeatably-random data using the internal
|
3
|
+
# Random Number Generator. You should not need to use this directly, it is
|
4
|
+
# automatically included when you `include ModuleUtils` in a FFaker module.
|
5
|
+
module RandomUtils
|
6
|
+
# Returns a randon number from the internal Random Number Generator. Can be
|
7
|
+
# used in place of `rand` or `Kernal.rand`.
|
8
|
+
def rand(max = nil)
|
9
|
+
FFaker::Random.rand(max)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Performs Array#sample on `list` using a the internal Random Number
|
13
|
+
# Generator so that the results are deterministic.
|
14
|
+
#
|
15
|
+
# * Returns one random item from `list`.
|
16
|
+
# * Pass `count: n` in options argument, where `n` is an integer, to
|
17
|
+
# return *n* items from `list`
|
18
|
+
def fetch_sample(list, options = {})
|
19
|
+
if (count = options.delete(:count))
|
20
|
+
list.sample(count, random: FFaker::Random)
|
21
|
+
else
|
22
|
+
list.sample(random: FFaker::Random)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Performs same action as as `Array#suffle` (returns a randomly-reordered
|
27
|
+
# copy of `list`) except that it uses the internal Random Number Generator
|
28
|
+
# so that the results are deterministic.
|
29
|
+
def shuffle(list)
|
30
|
+
list.shuffle(random: FFaker::Random)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/ffaker/vehicle.rb
CHANGED
@@ -5,39 +5,39 @@ module FFaker
|
|
5
5
|
extend ModuleUtils
|
6
6
|
extend self
|
7
7
|
|
8
|
-
DRIVETRAINS = %w(4WD 4X4 AWD FWD RWD)
|
9
|
-
YEARS = [*'1900'..
|
8
|
+
DRIVETRAINS = %w(4WD 4X4 AWD FWD RWD).freeze
|
9
|
+
YEARS = [*'1900'..(Date.today.year + 1).to_s].freeze
|
10
10
|
COLOR_PREFIXES = k(%w(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
TRANSMISSIONS_ABBR = %w(AT MT AM CVT)
|
15
|
-
CYLINDERS = %w(2 5 6 8)
|
11
|
+
beautiful bright calm dangerous dark dull fast magnetic magnificent majestic melodic metallic
|
12
|
+
mundane mute mysterious new pleasant pretty resonant royal slate soft tranquil vibrant weak
|
13
|
+
))
|
14
|
+
TRANSMISSIONS_ABBR = %w(AT MT AM CVT).freeze
|
15
|
+
CYLINDERS = %w(2 5 6 8).freeze
|
16
16
|
|
17
17
|
def base_color
|
18
18
|
FFaker::Color.name
|
19
19
|
end
|
20
20
|
|
21
21
|
def drivetrain
|
22
|
-
DRIVETRAINS
|
22
|
+
fetch_sample(DRIVETRAINS)
|
23
23
|
end
|
24
24
|
|
25
25
|
def make
|
26
|
-
MAKES_LIST
|
26
|
+
fetch_sample(MAKES_LIST)
|
27
27
|
end
|
28
28
|
|
29
|
-
def manufacturer_color(n=2)
|
29
|
+
def manufacturer_color(n = 2)
|
30
30
|
# Take two prefixes because it's more fun than one
|
31
|
-
(COLOR_PREFIXES
|
31
|
+
(fetch_sample(COLOR_PREFIXES, count: n) + [base_color]).join(' ')
|
32
32
|
end
|
33
|
-
|
33
|
+
alias mfg_color manufacturer_color
|
34
34
|
|
35
35
|
def model
|
36
|
-
MODELS_LIST
|
36
|
+
fetch_sample(MODELS_LIST)
|
37
37
|
end
|
38
38
|
|
39
39
|
def trim
|
40
|
-
TRIMS_LIST
|
40
|
+
fetch_sample(TRIMS_LIST)
|
41
41
|
end
|
42
42
|
|
43
43
|
def vin
|
@@ -45,31 +45,31 @@ module FFaker
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def year
|
48
|
-
YEARS
|
48
|
+
fetch_sample(YEARS)
|
49
49
|
end
|
50
50
|
|
51
51
|
def transmission
|
52
|
-
TRANSMISSIONS_LIST
|
52
|
+
fetch_sample(TRANSMISSIONS_LIST)
|
53
53
|
end
|
54
54
|
|
55
55
|
def transmission_abbr
|
56
|
-
TRANSMISSIONS_ABBR
|
56
|
+
fetch_sample(TRANSMISSIONS_ABBR)
|
57
57
|
end
|
58
58
|
|
59
59
|
def engine_cylinders
|
60
|
-
CYLINDERS
|
60
|
+
fetch_sample(CYLINDERS)
|
61
61
|
end
|
62
62
|
|
63
63
|
def engine_displacement
|
64
|
-
DISPLACEMENTS_LIST
|
64
|
+
fetch_sample(DISPLACEMENTS_LIST)
|
65
65
|
end
|
66
66
|
|
67
67
|
def fuel_type
|
68
|
-
FUEL_TYPES_LIST
|
68
|
+
fetch_sample(FUEL_TYPES_LIST)
|
69
69
|
end
|
70
70
|
|
71
71
|
def interior_upholstery
|
72
|
-
UPHOLSTERY_LIST
|
72
|
+
fetch_sample(UPHOLSTERY_LIST)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
data/lib/ffaker/venue.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module FFaker
|
4
|
+
module Youtube
|
5
|
+
extend ModuleUtils
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def url
|
9
|
+
"www.youtube.com/watch?v=#{video_id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def share_url
|
13
|
+
"youtu.be/#{video_id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def embed_url
|
17
|
+
"www.youtube.com/embed/#{video_id}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def video_id
|
21
|
+
fetch_sample(VIDEO_IDS)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/scripts/benchmark.rb
CHANGED
@@ -6,7 +6,7 @@ N = 10_000
|
|
6
6
|
def run(name)
|
7
7
|
require name
|
8
8
|
Benchmark.bm do |rep|
|
9
|
-
rep.report("generating #{
|
9
|
+
rep.report("generating #{N} names (#{name} #{FFaker::VERSION})") do
|
10
10
|
N.times do
|
11
11
|
FFaker::Name.name
|
12
12
|
end
|
@@ -16,5 +16,5 @@ def run(name)
|
|
16
16
|
exit(0)
|
17
17
|
end
|
18
18
|
|
19
|
-
fork { run(
|
20
|
-
fork { run(
|
19
|
+
fork { run('faker') }; Process.wait
|
20
|
+
fork { run('ffaker') }; Process.wait
|
data/scripts/reference.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__) + '/../lib'
|
2
2
|
require 'ffaker'
|
3
3
|
|
4
4
|
ICONS = {
|
5
|
-
:
|
6
|
-
:
|
7
|
-
}
|
5
|
+
error: "‼️",
|
6
|
+
warning: "❗"
|
7
|
+
}.freeze
|
8
8
|
|
9
9
|
# Get a list of sections
|
10
10
|
def faker_modules
|
@@ -13,13 +13,16 @@ def faker_modules
|
|
13
13
|
next unless mod.is_a?(Module)
|
14
14
|
next if mod == FFaker::ArrayUtils
|
15
15
|
next if mod == FFaker::ModuleUtils
|
16
|
+
next if mod == FFaker::RandomUtils
|
17
|
+
next if mod == FFaker::Random
|
16
18
|
mod
|
17
19
|
end.compact
|
18
20
|
end
|
19
21
|
|
20
22
|
# Returns faker methods for a given module
|
21
23
|
def faker_methods(mod)
|
22
|
-
methods = mod.methods - Module.methods -
|
24
|
+
methods = mod.methods - Module.methods -
|
25
|
+
[:k, :underscore, :fetch_sample, :rand, :shuffle]
|
23
26
|
|
24
27
|
# For Company.name (et al), don't discard :name if it was reimplemented
|
25
28
|
methods << :name if mod.send(:name) != mod.to_s
|
@@ -32,13 +35,13 @@ def warn(msg)
|
|
32
35
|
$warnings << msg if $warnings
|
33
36
|
end
|
34
37
|
|
35
|
-
def catch_warnings
|
38
|
+
def catch_warnings
|
36
39
|
$warnings = []
|
37
40
|
[yield, $warnings]
|
38
41
|
end
|
39
42
|
|
40
43
|
def escape(str)
|
41
|
-
str.gsub('&', '&').gsub('<', '<').gsub('>', '>').
|
44
|
+
str.gsub('&', '&').gsub('<', '<').gsub('>', '>').delete("\n")
|
42
45
|
end
|
43
46
|
|
44
47
|
sections = faker_modules.each.map do |mod|
|
@@ -46,28 +49,28 @@ sections = faker_modules.each.map do |mod|
|
|
46
49
|
|
47
50
|
methods = faker_methods(mod)
|
48
51
|
lines << "## #{mod}"
|
49
|
-
lines <<
|
50
|
-
lines <<
|
51
|
-
lines <<
|
52
|
+
lines << ''
|
53
|
+
lines << '| Method | Example |'
|
54
|
+
lines << '| ------ | ------- |'
|
52
55
|
|
53
56
|
methods.sort.each do |meth|
|
54
57
|
arity = mod.method(meth).arity
|
55
58
|
|
56
59
|
left = "`#{meth}`"
|
57
|
-
right =''
|
60
|
+
right = ''
|
58
61
|
|
59
62
|
if arity > 0
|
60
|
-
left = "`#{meth}`(#{arity.times.map{'...'}.join(', ')})"
|
63
|
+
left = "`#{meth}`(#{arity.times.map { '...' }.join(', ')})"
|
61
64
|
else
|
62
65
|
begin
|
63
|
-
examples, warnings = catch_warnings
|
66
|
+
examples, warnings = catch_warnings do
|
64
67
|
3.times.map { mod.send meth }
|
65
|
-
}
|
66
|
-
if warnings.any?
|
67
|
-
right = "#{ICONS[:warning]} *#{warnings.first}*"
|
68
|
-
else
|
69
|
-
right = "#{escape examples.join(', ')}"
|
70
68
|
end
|
69
|
+
right = if warnings.any?
|
70
|
+
"#{ICONS[:warning]} *#{warnings.first}*"
|
71
|
+
else
|
72
|
+
(escape examples.join(', ')).to_s
|
73
|
+
end
|
71
74
|
rescue => e
|
72
75
|
right = "#{ICONS[:error]} #{e.class}: #{e.message}"
|
73
76
|
end
|
@@ -76,14 +79,14 @@ sections = faker_modules.each.map do |mod|
|
|
76
79
|
lines << "| #{left} | #{right} |"
|
77
80
|
end
|
78
81
|
|
79
|
-
lines <<
|
82
|
+
lines << ''
|
80
83
|
end
|
81
84
|
|
82
|
-
puts
|
83
|
-
puts
|
85
|
+
puts '# FFaker reference'
|
86
|
+
puts ''
|
84
87
|
faker_modules.each do |mod|
|
85
|
-
name = mod.to_s.downcase.
|
88
|
+
name = mod.to_s.downcase.delete(':')
|
86
89
|
puts " * [#{mod}](##{name})"
|
87
90
|
end
|
88
|
-
puts
|
91
|
+
puts ''
|
89
92
|
puts sections.flatten.join("\n")
|