faker 1.6.3 → 1.6.4
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/History.txt +13 -0
- data/README.md +185 -23
- data/lib/faker.rb +20 -0
- data/lib/faker/app.rb +1 -1
- data/lib/faker/beer.rb +1 -1
- data/lib/faker/chuck_norris.rb +16 -0
- data/lib/faker/code.rb +59 -0
- data/lib/faker/company.rb +19 -0
- data/lib/faker/crypto.rb +19 -0
- data/lib/faker/date.rb +30 -2
- data/lib/faker/educator.rb +23 -0
- data/lib/faker/file.rb +23 -0
- data/lib/faker/internet.rb +24 -15
- data/lib/faker/lorem.rb +21 -7
- data/lib/faker/music.rb +21 -0
- data/lib/faker/name.rb +7 -0
- data/lib/faker/placeholdit.rb +3 -3
- data/lib/faker/space.rb +54 -0
- data/lib/faker/time.rb +7 -18
- data/lib/faker/vehicle.rb +37 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker/yoda.rb +10 -0
- data/lib/locales/de.yml +26 -8
- data/lib/locales/en-GB.yml +1 -1
- data/lib/locales/en-PAK.yml +17 -0
- data/lib/locales/en.yml +195 -4
- data/lib/locales/es-MX.yml +82 -0
- data/lib/locales/es.yml +4 -0
- data/lib/locales/fr.yml +7 -4
- data/lib/locales/pt-BR.yml +51 -23
- metadata +13 -103
- data/test/test_array_sample_method_compat.rb +0 -56
- data/test/test_avatar.rb +0 -43
- data/test/test_ca_cat_locale.rb +0 -35
- data/test/test_ca_locale.rb +0 -22
- data/test/test_da_dk_locale.rb +0 -32
- data/test/test_en_au_locale.rb +0 -24
- data/test/test_en_au_ocker_locale.rb +0 -25
- data/test/test_en_ca_locale.rb +0 -18
- data/test/test_en_locale.rb +0 -35
- data/test/test_en_nz_locale.rb +0 -33
- data/test/test_en_ug_locale.rb +0 -23
- data/test/test_en_us_locale.rb +0 -89
- data/test/test_es_locale.rb +0 -34
- data/test/test_faker.rb +0 -29
- data/test/test_faker_app.rb +0 -12
- data/test/test_faker_beer.rb +0 -41
- data/test/test_faker_bitcoin.rb +0 -14
- data/test/test_faker_book.rb +0 -24
- data/test/test_faker_boolean.rb +0 -23
- data/test/test_faker_business.rb +0 -34
- data/test/test_faker_cat.rb +0 -20
- data/test/test_faker_city.rb +0 -52
- data/test/test_faker_code.rb +0 -35
- data/test/test_faker_color.rb +0 -50
- data/test/test_faker_commerce.rb +0 -84
- data/test/test_faker_company.rb +0 -34
- data/test/test_faker_date.rb +0 -89
- data/test/test_faker_hacker_talk.rb +0 -37
- data/test/test_faker_hipster.rb +0 -78
- data/test/test_faker_internet.rb +0 -190
- data/test/test_faker_lorem.rb +0 -87
- data/test/test_faker_name.rb +0 -20
- data/test/test_faker_number.rb +0 -107
- data/test/test_faker_shakespeare.rb +0 -53
- data/test/test_faker_slack_emoji.rb +0 -45
- data/test/test_faker_star_wars.rb +0 -74
- data/test/test_faker_street.rb +0 -58
- data/test/test_faker_superhero.rb +0 -16
- data/test/test_faker_team.rb +0 -25
- data/test/test_faker_time.rb +0 -93
- data/test/test_faker_university.rb +0 -20
- data/test/test_fi_locale.rb +0 -33
- data/test/test_flexible.rb +0 -62
- data/test/test_helper.rb +0 -12
- data/test/test_locale.rb +0 -47
- data/test/test_pl_locale.rb +0 -24
- data/test/test_placeholdit.rb +0 -92
- data/test/test_pt_locale.rb +0 -27
- data/test/test_sv_locale.rb +0 -28
- data/test/test_uk_locale.rb +0 -44
data/lib/faker/company.rb
CHANGED
@@ -48,6 +48,13 @@ module Faker
|
|
48
48
|
base + luhn_algorithm(base).to_s
|
49
49
|
end
|
50
50
|
|
51
|
+
def australian_business_number
|
52
|
+
base = ('%09d' % rand(10 ** 9))
|
53
|
+
abn = '00' + base
|
54
|
+
|
55
|
+
(99 - (abn_checksum(abn) % 89)).to_s + base
|
56
|
+
end
|
57
|
+
|
51
58
|
def profession
|
52
59
|
fetch('company.profession')
|
53
60
|
end
|
@@ -81,6 +88,18 @@ module Faker
|
|
81
88
|
|
82
89
|
control_digit
|
83
90
|
end
|
91
|
+
|
92
|
+
def abn_checksum(abn)
|
93
|
+
abn_weights = [10,1,3,5,7,9,11,13,15,17,19]
|
94
|
+
sum = 0
|
95
|
+
|
96
|
+
abn_weights.each_with_index do |weight, i|
|
97
|
+
sum += weight * abn[i].to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
sum
|
101
|
+
end
|
102
|
+
|
84
103
|
end
|
85
104
|
end
|
86
105
|
end
|
data/lib/faker/crypto.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Faker
|
4
|
+
class Crypto < Base
|
5
|
+
class << self
|
6
|
+
def md5
|
7
|
+
Digest::MD5.hexdigest(Lorem.characters)
|
8
|
+
end
|
9
|
+
|
10
|
+
def sha1
|
11
|
+
Digest::SHA1.hexdigest(Lorem.characters)
|
12
|
+
end
|
13
|
+
|
14
|
+
def sha256
|
15
|
+
Digest::SHA256.hexdigest(Lorem.characters)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/faker/date.rb
CHANGED
@@ -32,14 +32,42 @@ module Faker
|
|
32
32
|
|
33
33
|
def birthday(min_age = 18, max_age = 65)
|
34
34
|
t = ::Date.today
|
35
|
-
|
36
|
-
|
35
|
+
top_bound, bottom_bound = prepare_bounds(t, min_age, max_age)
|
36
|
+
years = handled_leap_years(top_bound, bottom_bound)
|
37
|
+
|
38
|
+
from = ::Date.new(years[0], t.month, t.day)
|
39
|
+
to = ::Date.new(years[1], t.month, t.day)
|
37
40
|
|
38
41
|
between(from, to).to_date
|
39
42
|
end
|
40
43
|
|
41
44
|
private
|
42
45
|
|
46
|
+
def prepare_bounds(t, min_age, max_age)
|
47
|
+
[t.year - min_age, t.year - max_age]
|
48
|
+
end
|
49
|
+
|
50
|
+
def handled_leap_years(top_bound, bottom_bound)
|
51
|
+
if (top_bound % 4) != 0 || (bottom_bound % 4) != 0
|
52
|
+
[
|
53
|
+
customized_bound(top_bound),
|
54
|
+
customized_bound(bottom_bound, true)
|
55
|
+
]
|
56
|
+
else
|
57
|
+
[top_bound, bottom_bound]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def customized_bound(bound, increase = false)
|
62
|
+
if (bound % 4) != 0
|
63
|
+
bound = bound + 1 if increase
|
64
|
+
bound = bound - 1 unless increase
|
65
|
+
customized_bound(bound, increase)
|
66
|
+
else
|
67
|
+
bound
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
43
71
|
def get_date_object(date)
|
44
72
|
date = ::Date.parse(date) if date.is_a?(String)
|
45
73
|
date = date.to_date if date.respond_to?(:to_date)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Faker
|
2
|
+
class Educator < Base
|
3
|
+
flexible :educator
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def university
|
7
|
+
"#{fetch('educator.name')} #{fetch('educator.tertiary.type')}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def course
|
11
|
+
"#{fetch('educator.tertiary.course.type')} #{fetch('educator.tertiary.course.subject')}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def secondary_school
|
15
|
+
"#{fetch('educator.name')} #{fetch('educator.secondary')}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def campus
|
19
|
+
"#{fetch('educator.name')} Campus"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/faker/file.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Faker
|
3
|
+
class File < Base
|
4
|
+
class << self
|
5
|
+
def extension
|
6
|
+
fetch('file.extension')
|
7
|
+
end
|
8
|
+
|
9
|
+
def mime_type
|
10
|
+
fetch('file.mime_type')
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_name(dir = nil, name = nil, ext = nil, directory_separator = '/')
|
14
|
+
|
15
|
+
dir = Faker::Internet::slug unless dir
|
16
|
+
name = Faker::Lorem::word().downcase unless name
|
17
|
+
ext = extension unless ext
|
18
|
+
|
19
|
+
[dir, name].join(directory_separator) + ".#{ext}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/faker/internet.rb
CHANGED
@@ -97,28 +97,39 @@ module Faker
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def ip_v4_address
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
(1..4).map { rand(2..254) }.join('.')
|
101
|
+
end
|
102
|
+
|
103
|
+
def private_ip_v4_address
|
104
|
+
is_private = private_net_checker
|
105
|
+
addr = nil
|
106
|
+
begin
|
107
|
+
addr = ip_v4_address
|
108
|
+
end while !is_private[addr]
|
109
|
+
addr
|
105
110
|
end
|
106
111
|
|
107
112
|
def public_ip_v4_address
|
108
|
-
|
113
|
+
is_private = private_net_checker
|
114
|
+
addr = nil
|
115
|
+
begin
|
116
|
+
addr = ip_v4_address
|
117
|
+
end while is_private[addr]
|
118
|
+
addr
|
119
|
+
end
|
120
|
+
|
121
|
+
def private_nets_regex
|
122
|
+
[
|
109
123
|
/^10\./,
|
110
124
|
/^127\./,
|
111
125
|
/^169\.254\./,
|
112
126
|
/^172\.(16|17|18|19|2\d|30|31)\./,
|
113
127
|
/^192\.168\./
|
114
128
|
]
|
129
|
+
end
|
115
130
|
|
116
|
-
|
117
|
-
addr
|
118
|
-
begin
|
119
|
-
addr = ip_v4_address
|
120
|
-
end while is_private[addr]
|
121
|
-
addr
|
131
|
+
def private_net_checker
|
132
|
+
lambda { |addr| private_nets_regex.any? { |net| net =~ addr } }
|
122
133
|
end
|
123
134
|
|
124
135
|
def ip_v4_cidr
|
@@ -126,9 +137,7 @@ module Faker
|
|
126
137
|
end
|
127
138
|
|
128
139
|
def ip_v6_address
|
129
|
-
|
130
|
-
container = (1..8).map{ |_| @@ip_v6_space.sample }
|
131
|
-
container.map{ |n| n.to_s(16) }.join(':')
|
140
|
+
(1..8).map { rand(65536).to_s(16) }.join(':')
|
132
141
|
end
|
133
142
|
|
134
143
|
def ip_v6_cidr
|
data/lib/faker/lorem.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Faker
|
2
2
|
# Based on Perl's Text::Lorem
|
3
3
|
class Lorem < Base
|
4
|
+
CHARACTERS = ('0'..'9').to_a + ('a'..'z').to_a
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def word
|
6
8
|
translate('faker.lorem.words').sample
|
@@ -17,17 +19,17 @@ module Faker
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def character
|
20
|
-
|
22
|
+
CHARACTERS.sample
|
21
23
|
end
|
22
24
|
|
23
25
|
def characters(char_count = 255)
|
24
|
-
return '' if char_count.respond_to?(:to_i) && char_count.to_i < 1
|
25
26
|
char_count = resolve(char_count)
|
26
|
-
|
27
|
+
return '' if char_count.to_i < 1
|
28
|
+
Array.new(char_count) { CHARACTERS.sample }.join
|
27
29
|
end
|
28
30
|
|
29
31
|
def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
|
30
|
-
words(word_count + rand(random_words_to_add.to_i)
|
32
|
+
words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + '.'
|
31
33
|
end
|
32
34
|
|
33
35
|
def sentences(sentence_count = 3, supplemental = false)
|
@@ -39,7 +41,7 @@ module Faker
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
|
42
|
-
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i)
|
44
|
+
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(' ')
|
43
45
|
end
|
44
46
|
|
45
47
|
def paragraphs(paragraph_count = 3, supplemental = false)
|
@@ -50,14 +52,26 @@ module Faker
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
55
|
+
def question(word_count = 4, supplemental = false, random_words_to_add = 6)
|
56
|
+
words(word_count + rand(random_words_to_add.to_i).to_i, supplemental).join(' ').capitalize + '?'
|
57
|
+
end
|
58
|
+
|
59
|
+
def questions(question_count = 3, supplemental = false)
|
60
|
+
[].tap do |questions|
|
61
|
+
1.upto(resolve(question_count)) do
|
62
|
+
questions << question(3, supplemental)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
private
|
54
68
|
|
55
69
|
# If an array or range is passed, a random value will be selected.
|
56
70
|
# All other values are simply returned.
|
57
71
|
def resolve(value)
|
58
72
|
case value
|
59
|
-
when Array then value
|
60
|
-
when Range then rand
|
73
|
+
when Array then value.sample
|
74
|
+
when Range then rand value
|
61
75
|
else value
|
62
76
|
end
|
63
77
|
end
|
data/lib/faker/music.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Faker
|
2
|
+
class Music < Base
|
3
|
+
class << self
|
4
|
+
def key
|
5
|
+
keys.sample + key_variants.sample
|
6
|
+
end
|
7
|
+
|
8
|
+
def instrument
|
9
|
+
fetch('music.instruments')
|
10
|
+
end
|
11
|
+
|
12
|
+
def keys
|
13
|
+
['C', 'D', 'E', 'F', 'G', 'A', 'B']
|
14
|
+
end
|
15
|
+
|
16
|
+
def key_variants
|
17
|
+
['b', '#', '']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/faker/name.rb
CHANGED
@@ -8,6 +8,10 @@ module Faker
|
|
8
8
|
parse('name.name')
|
9
9
|
end
|
10
10
|
|
11
|
+
def name_with_middle
|
12
|
+
parse('name.name_with_middle')
|
13
|
+
end
|
14
|
+
|
11
15
|
def first_name; fetch('name.first_name'); end
|
12
16
|
def last_name; fetch('name.last_name'); end
|
13
17
|
def prefix; fetch('name.prefix'); end
|
@@ -17,6 +21,9 @@ module Faker
|
|
17
21
|
# Wordlist from http://www.bullshitjob.com/title/
|
18
22
|
def title; fetch('name.title.descriptor') + ' ' + fetch('name.title.level') + ' ' + fetch('name.title.job'); end
|
19
23
|
|
24
|
+
def job_titles
|
25
|
+
fetch_all('name.title.job')
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
data/lib/faker/placeholdit.rb
CHANGED
@@ -3,14 +3,14 @@ module Faker
|
|
3
3
|
class << self
|
4
4
|
SUPPORTED_FORMATS = %w(png jpg gif jpeg)
|
5
5
|
|
6
|
-
def image(size = '300x300', format = 'png', background_color =
|
6
|
+
def image(size = '300x300', format = 'png', background_color = nil, text_color = nil, text = nil)
|
7
7
|
raise ArgumentError, "Size should be specified in format 300x300" unless size.match(/^[0-9]+x[0-9]+$/)
|
8
8
|
raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
|
9
|
-
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
|
9
|
+
raise ArgumentError, "background_color must be a hex value without '#'" unless background_color.nil? || background_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
|
10
10
|
raise ArgumentError, "text_color must be a hex value without '#'" unless text_color.nil? || text_color.match(/((?:^\h{3}$)|(?:^\h{6}$)){1}(?!.*\H)/)
|
11
11
|
|
12
12
|
image_url = "https://placehold.it/#{size}.#{format}"
|
13
|
-
image_url += "/#{background_color}"
|
13
|
+
image_url += "/#{background_color}" if background_color
|
14
14
|
image_url += "/#{text_color}" if text_color
|
15
15
|
image_url += "?text=#{text}" if text
|
16
16
|
image_url
|
data/lib/faker/space.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Faker
|
2
|
+
class Space < Base
|
3
|
+
flexible :space
|
4
|
+
class << self
|
5
|
+
def planet
|
6
|
+
fetch('space.planet')
|
7
|
+
end
|
8
|
+
|
9
|
+
def moon
|
10
|
+
fetch('space.moon')
|
11
|
+
end
|
12
|
+
|
13
|
+
def galaxy
|
14
|
+
fetch('space.galaxy')
|
15
|
+
end
|
16
|
+
|
17
|
+
def nebula
|
18
|
+
fetch('space.nebula')
|
19
|
+
end
|
20
|
+
|
21
|
+
def star_cluster
|
22
|
+
fetch('space.star_cluster')
|
23
|
+
end
|
24
|
+
|
25
|
+
def constellation
|
26
|
+
fetch('space.constellation')
|
27
|
+
end
|
28
|
+
|
29
|
+
def star
|
30
|
+
fetch('space.star')
|
31
|
+
end
|
32
|
+
|
33
|
+
def agency
|
34
|
+
fetch('space.agency')
|
35
|
+
end
|
36
|
+
|
37
|
+
def agency_abv
|
38
|
+
fetch('space.agency_abv')
|
39
|
+
end
|
40
|
+
|
41
|
+
def nasa_space_craft
|
42
|
+
fetch('space.nasa_space_craft')
|
43
|
+
end
|
44
|
+
|
45
|
+
def company
|
46
|
+
fetch('space.company')
|
47
|
+
end
|
48
|
+
|
49
|
+
def distance_measurement
|
50
|
+
rand(10..100).to_s + ' ' + fetch('space.distance_measurement')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/faker/time.rb
CHANGED
@@ -12,41 +12,30 @@ module Faker
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def between(from, to, period = :all)
|
15
|
-
|
16
|
-
|
17
|
-
if time_parameters
|
18
|
-
random_time = Faker::Base::rand_in_range(from.to_f, to.to_f)
|
19
|
-
random_time = ::Time.at(random_time)
|
20
|
-
else
|
21
|
-
random_time = super(from, to).to_time + random_time(period)
|
22
|
-
end
|
23
|
-
|
24
|
-
random_time
|
15
|
+
date_with_random_time(super(from, to), period)
|
25
16
|
end
|
26
17
|
|
27
18
|
def forward(days = 365, period = :all)
|
28
|
-
super(days)
|
19
|
+
date_with_random_time(super(days), period)
|
29
20
|
end
|
30
21
|
|
31
22
|
def backward(days = 365, period = :all)
|
32
|
-
super(days)
|
23
|
+
date_with_random_time(super(days), period)
|
33
24
|
end
|
34
25
|
|
35
26
|
private
|
36
27
|
|
37
|
-
def
|
38
|
-
hours(period)
|
28
|
+
def date_with_random_time(date, period)
|
29
|
+
::Time.local(date.year, date.month, date.day, hours(period), minutes, seconds)
|
39
30
|
end
|
40
31
|
|
41
32
|
def hours(period)
|
42
33
|
raise ArgumentError, 'invalid period' unless TIME_RANGES.has_key? period
|
43
|
-
|
44
|
-
|
45
|
-
(60 * 60 * hour_at_period)
|
34
|
+
TIME_RANGES[period].to_a.sample
|
46
35
|
end
|
47
36
|
|
48
37
|
def minutes
|
49
|
-
|
38
|
+
seconds
|
50
39
|
end
|
51
40
|
|
52
41
|
def seconds
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Faker
|
2
|
+
class Vehicle < Base
|
3
|
+
@vin_chars = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'
|
4
|
+
@vin_map = '0123456789X'
|
5
|
+
@vin_weights = '8765432X098765432'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
#ISO 3779
|
9
|
+
def vin
|
10
|
+
manufacture = fetch_all('vehicle.manufacture').sample
|
11
|
+
|
12
|
+
c = @vin_chars.split('').reject{ |n| n == '.'}
|
13
|
+
vehicle_identification_number = manufacture["wmi"].split('').concat( Array.new(14) { c.sample } )
|
14
|
+
(12..14).to_a.each_with_index { |n, i| vehicle_identification_number[n] = manufacture["win_ext"][i] } unless manufacture["win_ext"].nil?
|
15
|
+
vehicle_identification_number[10] = fetch('vehicle.year')
|
16
|
+
vehicle_identification_number[8] = vin_checksum(vehicle_identification_number)
|
17
|
+
|
18
|
+
vehicle_identification_number.join.upcase
|
19
|
+
end
|
20
|
+
|
21
|
+
def manufacture
|
22
|
+
fetch_all('vehicle.manufacture').sample["name"]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def calculate_vin_weight(character, i)
|
28
|
+
(@vin_chars.index(character) % 10) * @vin_map.index(@vin_weights [i])
|
29
|
+
end
|
30
|
+
|
31
|
+
def vin_checksum(vehicle_identification_number)
|
32
|
+
@vin_map[vehicle_identification_number.each_with_index.map(&method(:calculate_vin_weight)).inject(:+) % 11]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|