faker 1.9.6 → 2.0.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 +152 -6
- data/README.md +4 -0
- data/lib/faker/books/dune.rb +2 -2
- data/lib/faker/books/lovecraft.rb +18 -18
- data/lib/faker/creature/animal.rb +1 -1
- data/lib/faker/creature/cat.rb +1 -1
- data/lib/faker/creature/dog.rb +1 -1
- data/lib/faker/creature/horse.rb +1 -1
- data/lib/faker/default/address.rb +3 -3
- data/lib/faker/default/alphanumeric.rb +4 -4
- data/lib/faker/default/avatar.rb +1 -1
- data/lib/faker/default/bank.rb +2 -2
- data/lib/faker/default/boolean.rb +1 -1
- data/lib/faker/default/cannabis.rb +4 -0
- data/lib/faker/default/chile_rut.rb +3 -3
- data/lib/faker/default/code.rb +5 -5
- data/lib/faker/default/commerce.rb +4 -4
- data/lib/faker/default/company.rb +2 -2
- data/lib/faker/default/crypto_coin.rb +9 -4
- data/lib/faker/default/date.rb +9 -9
- data/lib/faker/default/demographic.rb +1 -1
- data/lib/faker/default/device.rb +2 -2
- data/lib/faker/default/driving_licence.rb +2 -2
- data/lib/faker/default/educator.rb +0 -3
- data/lib/faker/default/file.rb +3 -3
- data/lib/faker/default/fillmurray.rb +2 -2
- data/lib/faker/default/finance.rb +1 -1
- data/lib/faker/default/hipster.rb +16 -16
- data/lib/faker/default/id_number.rb +8 -8
- data/lib/faker/default/internet.rb +22 -21
- data/lib/faker/default/invoice.rb +3 -3
- data/lib/faker/default/json.rb +2 -2
- data/lib/faker/default/lorem.rb +20 -20
- data/lib/faker/default/lorem_flickr.rb +4 -4
- data/lib/faker/default/lorem_pixel.rb +1 -1
- data/lib/faker/default/markdown.rb +7 -7
- data/lib/faker/default/measurement.rb +8 -8
- data/lib/faker/default/name.rb +2 -4
- data/lib/faker/default/nhs.rb +7 -7
- data/lib/faker/default/number.rb +35 -32
- data/lib/faker/default/omniauth.rb +11 -11
- data/lib/faker/default/phone_number.rb +1 -1
- data/lib/faker/default/placeholdit.rb +1 -1
- data/lib/faker/default/relationship.rb +1 -1
- data/lib/faker/default/source.rb +2 -2
- data/lib/faker/default/south_africa.rb +1 -1
- data/lib/faker/default/space.rb +2 -2
- data/lib/faker/default/string.rb +1 -1
- data/lib/faker/default/stripe.rb +4 -4
- data/lib/faker/default/time.rb +23 -8
- data/lib/faker/default/twitter.rb +30 -30
- data/lib/faker/default/types.rb +7 -7
- data/lib/faker/default/vehicle.rb +5 -5
- data/lib/faker/default/world_cup.rb +2 -2
- data/lib/faker/games/dota.rb +1 -1
- data/lib/faker/games/elder_scrolls.rb +1 -1
- data/lib/faker/games/fallout.rb +1 -1
- data/lib/faker/games/half_life.rb +1 -1
- data/lib/faker/games/heroes.rb +1 -1
- data/lib/faker/games/heroes_of_the_storm.rb +1 -1
- data/lib/faker/games/league_of_legends.rb +1 -1
- data/lib/faker/games/myst.rb +1 -1
- data/lib/faker/games/overwatch.rb +1 -1
- data/lib/faker/games/pokemon.rb +1 -1
- data/lib/faker/games/sonic_the_hedgehog.rb +1 -1
- data/lib/faker/games/super_smash_bros.rb +1 -1
- data/lib/faker/games/witcher.rb +1 -1
- data/lib/faker/games/world_of_warcraft.rb +1 -1
- data/lib/faker/games/zelda.rb +1 -1
- data/lib/faker/japanese_media/dragon_ball.rb +1 -1
- data/lib/faker/japanese_media/one_piece.rb +1 -1
- data/lib/faker/japanese_media/sword_art_online.rb +1 -1
- data/lib/faker/movies/back_to_the_future.rb +1 -1
- data/lib/faker/movies/ghostbusters.rb +1 -1
- data/lib/faker/movies/harry_potter.rb +1 -1
- data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +1 -1
- data/lib/faker/movies/hobbit.rb +1 -1
- data/lib/faker/movies/lebowski.rb +1 -1
- data/lib/faker/movies/lord_of_the_rings.rb +1 -1
- data/lib/faker/movies/princess_bride.rb +1 -1
- data/lib/faker/movies/star_wars.rb +2 -2
- data/lib/faker/movies/v_for_vendetta.rb +1 -1
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +1 -1
- data/lib/faker/tv_shows/bojack_horseman.rb +1 -1
- data/lib/faker/tv_shows/breaking_bad.rb +1 -1
- data/lib/faker/tv_shows/buffy.rb +1 -1
- data/lib/faker/tv_shows/community.rb +1 -1
- data/lib/faker/tv_shows/dr_who.rb +1 -1
- data/lib/faker/tv_shows/dumb_and_dumber.rb +1 -1
- data/lib/faker/tv_shows/family_guy.rb +1 -1
- data/lib/faker/tv_shows/friends.rb +1 -1
- data/lib/faker/tv_shows/game_of_thrones.rb +1 -1
- data/lib/faker/tv_shows/hey_arnold.rb +1 -1
- data/lib/faker/tv_shows/how_i_met_your_mother.rb +1 -1
- data/lib/faker/tv_shows/michael_scott.rb +1 -1
- data/lib/faker/tv_shows/new_girl.rb +1 -1
- data/lib/faker/tv_shows/parks_and_rec.rb +1 -1
- data/lib/faker/tv_shows/rick_and_morty.rb +1 -1
- data/lib/faker/tv_shows/ru_paul.rb +1 -1
- data/lib/faker/tv_shows/seinfeld.rb +1 -1
- data/lib/faker/tv_shows/silicon_valley.rb +1 -1
- data/lib/faker/tv_shows/simpsons.rb +1 -1
- data/lib/faker/tv_shows/south_park.rb +1 -1
- data/lib/faker/tv_shows/star_trek.rb +1 -1
- data/lib/faker/tv_shows/stargate.rb +1 -1
- data/lib/faker/tv_shows/stranger_things.rb +1 -1
- data/lib/faker/tv_shows/the_expanse.rb +1 -1
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +1 -1
- data/lib/faker/tv_shows/the_it_crowd.rb +1 -1
- data/lib/faker/tv_shows/the_thick_of_it.rb +1 -1
- data/lib/faker/tv_shows/twin_peaks.rb +1 -1
- data/lib/faker/tv_shows/venture_bros.rb +1 -1
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en-IND.yml +1 -1
- data/lib/locales/en.yml +51 -1
- data/lib/locales/en/address.yml +1 -4
- data/lib/locales/en/animal.yml +2 -2
- data/lib/locales/en/cannabis.yml +1 -0
- data/lib/locales/en/space.yml +1 -1
- data/lib/locales/en/super_smash_bros.yml +4 -0
- data/lib/locales/vi.yml +1 -1
- metadata +3 -11
- data/lib/faker/default/creature.rb +0 -6
- data/lib/faker/default/games.rb +0 -6
- data/lib/faker/default/japanese_media.rb +0 -6
- data/lib/faker/default/movies.rb +0 -6
- data/lib/faker/default/tv_shows.rb +0 -6
- data/lib/faker/deprecate/unreleased/football.rb +0 -35
- data/lib/faker/deprecate/unreleased/movies/grateful_dead.rb +0 -22
@@ -6,13 +6,13 @@ module Faker
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
# Generate random amount between values with 2 decimals
|
9
|
-
def amount_between(from
|
9
|
+
def amount_between(from: 0, to: 0)
|
10
10
|
Faker::Base.rand_in_range(from, to).round(2)
|
11
11
|
end
|
12
12
|
|
13
13
|
# International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
|
14
14
|
# ref is optional so that we can create unit tests
|
15
|
-
def creditor_reference(ref
|
15
|
+
def creditor_reference(ref: '')
|
16
16
|
ref = reference if ref.empty?
|
17
17
|
|
18
18
|
'RF' + iban_checksum('RF', ref) + ref
|
@@ -20,7 +20,7 @@ module Faker
|
|
20
20
|
|
21
21
|
# Payment references have some rules in certain countries
|
22
22
|
# ref is optional so that we can create unit tests
|
23
|
-
def reference(ref
|
23
|
+
def reference(ref: '')
|
24
24
|
pattern = fetch('invoice.reference.pattern')
|
25
25
|
|
26
26
|
ref = Base.regexify(/#{pattern}/) if ref.empty?
|
data/lib/faker/default/json.rb
CHANGED
@@ -3,7 +3,7 @@ module Faker
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def shallow_json(width
|
6
|
+
def shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
|
7
7
|
options[:key] = 'Faker::' + options[:key]
|
8
8
|
options[:value] = 'Faker::' + options[:value]
|
9
9
|
|
@@ -11,7 +11,7 @@ module Faker
|
|
11
11
|
JSON.generate(hash)
|
12
12
|
end
|
13
13
|
|
14
|
-
def add_depth_to_json(json
|
14
|
+
def add_depth_to_json(json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
|
15
15
|
options[:key] = 'Faker::' + options[:key]
|
16
16
|
options[:value] = 'Faker::' + options[:value]
|
17
17
|
|
data/lib/faker/default/lorem.rb
CHANGED
@@ -8,8 +8,8 @@ module Faker
|
|
8
8
|
sample(translate('faker.lorem.words'))
|
9
9
|
end
|
10
10
|
|
11
|
-
def words(
|
12
|
-
resolved_num = resolve(
|
11
|
+
def words(number: 3, supplemental: false)
|
12
|
+
resolved_num = resolve(number)
|
13
13
|
word_list = (
|
14
14
|
translate('faker.lorem.words') +
|
15
15
|
(supplemental ? translate('faker.lorem.supplemental') : [])
|
@@ -22,44 +22,44 @@ module Faker
|
|
22
22
|
sample(Types::CHARACTERS)
|
23
23
|
end
|
24
24
|
|
25
|
-
def characters(
|
26
|
-
Alphanumeric.alphanumeric(
|
25
|
+
def characters(number: 255)
|
26
|
+
Alphanumeric.alphanumeric(number: number)
|
27
27
|
end
|
28
28
|
|
29
29
|
def multibyte
|
30
30
|
sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8')
|
31
31
|
end
|
32
32
|
|
33
|
-
def sentence(word_count
|
34
|
-
words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
|
33
|
+
def sentence(word_count: 4, supplemental: false, random_words_to_add: 0)
|
34
|
+
words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(' ').capitalize + locale_period
|
35
35
|
end
|
36
36
|
|
37
|
-
def sentences(
|
38
|
-
1.upto(resolve(
|
37
|
+
def sentences(number: 3, supplemental: false)
|
38
|
+
1.upto(resolve(number)).collect { sentence(word_count: 3, supplemental: supplemental) }
|
39
39
|
end
|
40
40
|
|
41
|
-
def paragraph(sentence_count
|
42
|
-
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space)
|
41
|
+
def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0)
|
42
|
+
sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental: supplemental).join(locale_space)
|
43
43
|
end
|
44
44
|
|
45
|
-
def paragraphs(
|
46
|
-
1.upto(resolve(
|
45
|
+
def paragraphs(number: 3, supplemental: false)
|
46
|
+
1.upto(resolve(number)).collect { paragraph(sentence_count: 3, supplemental: supplemental) }
|
47
47
|
end
|
48
48
|
|
49
|
-
def paragraph_by_chars(
|
50
|
-
paragraph = paragraph(3, supplemental)
|
49
|
+
def paragraph_by_chars(number: 256, supplemental: false)
|
50
|
+
paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
|
51
51
|
|
52
|
-
paragraph += ' ' + paragraph(3, supplemental) while paragraph.length <
|
52
|
+
paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < number
|
53
53
|
|
54
|
-
paragraph[0...
|
54
|
+
paragraph[0...number - 1] + '.'
|
55
55
|
end
|
56
56
|
|
57
|
-
def question(word_count
|
58
|
-
words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark
|
57
|
+
def question(word_count: 4, supplemental: false, random_words_to_add: 0)
|
58
|
+
words(number: word_count + rand(random_words_to_add), supplemental: supplemental).join(' ').capitalize + locale_question_mark
|
59
59
|
end
|
60
60
|
|
61
|
-
def questions(
|
62
|
-
1.upto(resolve(
|
61
|
+
def questions(number: 3, supplemental: false)
|
62
|
+
1.upto(resolve(number)).collect { question(word_count: 3, supplemental: supplemental) }
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
@@ -5,23 +5,23 @@ module Faker
|
|
5
5
|
class << self
|
6
6
|
SUPPORTED_COLORIZATIONS = %w[red green blue].freeze
|
7
7
|
|
8
|
-
def image(size
|
8
|
+
def image(size: '300x300', search_terms: [], match_all: false)
|
9
9
|
build_url(size, nil, search_terms, match_all)
|
10
10
|
end
|
11
11
|
|
12
|
-
def grayscale_image(size
|
12
|
+
def grayscale_image(size: '300x300', search_terms: ['all'], match_all: false)
|
13
13
|
raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any?
|
14
14
|
|
15
15
|
build_url(size, 'g', search_terms, match_all)
|
16
16
|
end
|
17
17
|
|
18
|
-
def pixelated_image(size
|
18
|
+
def pixelated_image(size: '300x300', search_terms: ['all'], match_all: false)
|
19
19
|
raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any?
|
20
20
|
|
21
21
|
build_url(size, 'p', search_terms, match_all)
|
22
22
|
end
|
23
23
|
|
24
|
-
def colorized_image(size
|
24
|
+
def colorized_image(size: '300x300', color: 'red', search_terms: ['all'], match_all: false)
|
25
25
|
raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any?
|
26
26
|
raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color)
|
27
27
|
|
@@ -18,7 +18,7 @@ module Faker
|
|
18
18
|
transport].freeze
|
19
19
|
|
20
20
|
# rubocop:disable Metrics/ParameterLists
|
21
|
-
def image(size
|
21
|
+
def image(size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true)
|
22
22
|
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
23
23
|
raise ArgumentError, "Supported categories are #{SUPPORTED_CATEGORIES.join(', ')}" unless category.nil? || SUPPORTED_CATEGORIES.include?(category)
|
24
24
|
raise ArgumentError, 'Category required when number is passed' if !number.nil? && category.nil?
|
@@ -8,7 +8,7 @@ module Faker
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def emphasis
|
11
|
-
paragraph = Faker::Lorem.paragraph(3)
|
11
|
+
paragraph = Faker::Lorem.paragraph(sentence_count: 3)
|
12
12
|
words = paragraph.split(' ')
|
13
13
|
position = rand(0..words.length - 1)
|
14
14
|
formatting = fetch('markdown.emphasis')
|
@@ -21,7 +21,7 @@ module Faker
|
|
21
21
|
|
22
22
|
result = []
|
23
23
|
number.times do |i|
|
24
|
-
result << "#{i}. #{Faker::Lorem.sentence(1)} \n"
|
24
|
+
result << "#{i}. #{Faker::Lorem.sentence(word_count: 1)} \n"
|
25
25
|
end
|
26
26
|
result.join('')
|
27
27
|
end
|
@@ -31,17 +31,17 @@ module Faker
|
|
31
31
|
|
32
32
|
result = []
|
33
33
|
number.times do |_i|
|
34
|
-
result << "* #{Faker::Lorem.sentence(1)} \n"
|
34
|
+
result << "* #{Faker::Lorem.sentence(word_count: 1)} \n"
|
35
35
|
end
|
36
36
|
result.join('')
|
37
37
|
end
|
38
38
|
|
39
39
|
def inline_code
|
40
|
-
"`#{Faker::Lorem.sentence(1)}`"
|
40
|
+
"`#{Faker::Lorem.sentence(word_count: 1)}`"
|
41
41
|
end
|
42
42
|
|
43
43
|
def block_code
|
44
|
-
"```ruby\n#{Lorem.sentence(1)}\n```"
|
44
|
+
"```ruby\n#{Lorem.sentence(word_count: 1)}\n```"
|
45
45
|
end
|
46
46
|
|
47
47
|
def table
|
@@ -59,11 +59,11 @@ module Faker
|
|
59
59
|
send(method_list[rand(0..method_list.length - 1)])
|
60
60
|
end
|
61
61
|
|
62
|
-
def sandwich(sentences
|
62
|
+
def sandwich(sentences: 3, repeat: 1)
|
63
63
|
text_block = []
|
64
64
|
text_block << headers
|
65
65
|
repeat.times do
|
66
|
-
text_block << Faker::Lorem.paragraph(sentences)
|
66
|
+
text_block << Faker::Lorem.paragraph(sentence_count: sentences)
|
67
67
|
text_block << random
|
68
68
|
end
|
69
69
|
text_block.join("\n")
|
@@ -6,35 +6,35 @@ module Faker
|
|
6
6
|
ALL = 'all'
|
7
7
|
NONE = 'none'
|
8
8
|
|
9
|
-
def height(amount
|
9
|
+
def height(amount: rand(10))
|
10
10
|
define_measurement_locale(amount, 'height')
|
11
11
|
end
|
12
12
|
|
13
|
-
def length(amount
|
13
|
+
def length(amount: rand(10))
|
14
14
|
define_measurement_locale(amount, 'length')
|
15
15
|
end
|
16
16
|
|
17
|
-
def volume(amount
|
17
|
+
def volume(amount: rand(10))
|
18
18
|
define_measurement_locale(amount, 'volume')
|
19
19
|
end
|
20
20
|
|
21
|
-
def weight(amount
|
21
|
+
def weight(amount: rand(10))
|
22
22
|
define_measurement_locale(amount, 'weight')
|
23
23
|
end
|
24
24
|
|
25
|
-
def metric_height(amount
|
25
|
+
def metric_height(amount: rand(10))
|
26
26
|
define_measurement_locale(amount, 'metric_height')
|
27
27
|
end
|
28
28
|
|
29
|
-
def metric_length(amount
|
29
|
+
def metric_length(amount: rand(10))
|
30
30
|
define_measurement_locale(amount, 'metric_length')
|
31
31
|
end
|
32
32
|
|
33
|
-
def metric_volume(amount
|
33
|
+
def metric_volume(amount: rand(10))
|
34
34
|
define_measurement_locale(amount, 'metric_volume')
|
35
35
|
end
|
36
36
|
|
37
|
-
def metric_weight(amount
|
37
|
+
def metric_weight(amount: rand(10))
|
38
38
|
define_measurement_locale(amount, 'metric_weight')
|
39
39
|
end
|
40
40
|
|
data/lib/faker/default/name.rb
CHANGED
@@ -5,8 +5,6 @@ module Faker
|
|
5
5
|
flexible :name
|
6
6
|
|
7
7
|
class << self
|
8
|
-
extend Gem::Deprecate
|
9
|
-
|
10
8
|
def name
|
11
9
|
parse('name.name')
|
12
10
|
end
|
@@ -48,8 +46,8 @@ module Faker
|
|
48
46
|
fetch('name.suffix')
|
49
47
|
end
|
50
48
|
|
51
|
-
def initials(
|
52
|
-
(0...
|
49
|
+
def initials(number: 3)
|
50
|
+
(0...number).map { rand(65..90).chr }.join
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
data/lib/faker/default/nhs.rb
CHANGED
@@ -7,15 +7,15 @@ module Faker
|
|
7
7
|
base_number = rand(400_000_001...499_999_999)
|
8
8
|
# If the check digit is equivalent to 10, the number is invalid.
|
9
9
|
# See https://en.wikipedia.org/wiki/NHS_number
|
10
|
-
base_number -= 1 if check_digit(base_number) == 10
|
11
|
-
"#{base_number}#{check_digit(base_number)}".to_s
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
base_number -= 1 if check_digit(number: base_number) == 10
|
11
|
+
"#{base_number}#{check_digit(number: base_number)}".to_s
|
12
|
+
.chars
|
13
|
+
.insert(3, ' ')
|
14
|
+
.insert(7, ' ')
|
15
|
+
.join('')
|
16
16
|
end
|
17
17
|
|
18
|
-
def check_digit(number
|
18
|
+
def check_digit(number: 0)
|
19
19
|
sum = 0
|
20
20
|
number.to_s.chars.each_with_index do |digit, idx|
|
21
21
|
position = idx + 1
|
data/lib/faker/default/number.rb
CHANGED
@@ -3,82 +3,88 @@
|
|
3
3
|
module Faker
|
4
4
|
class Number < Base
|
5
5
|
class << self
|
6
|
-
|
6
|
+
def number(digits: 10)
|
7
|
+
return if digits < 1
|
8
|
+
return 0 if digits == 1
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
if digits > 1
|
12
|
-
num = non_zero_digit
|
13
|
-
digits -= 1
|
14
|
-
end
|
15
|
-
|
16
|
-
num + (1..digits).collect { digit }.join
|
10
|
+
# Ensure the first digit is not zero
|
11
|
+
([non_zero_digit] + generate(digits - 1)).join.to_i
|
17
12
|
end
|
18
13
|
|
19
|
-
def leading_zero_number(digits
|
14
|
+
def leading_zero_number(digits: 10)
|
20
15
|
'0' + (2..digits).collect { digit }.join
|
21
16
|
end
|
22
17
|
|
23
|
-
def decimal_part(digits
|
18
|
+
def decimal_part(digits: 10)
|
24
19
|
num = ''
|
25
20
|
if digits > 1
|
26
21
|
num = non_zero_digit
|
27
22
|
digits -= 1
|
28
23
|
end
|
29
|
-
leading_zero_number(digits) + num
|
24
|
+
leading_zero_number(digits: digits) + num.to_s
|
30
25
|
end
|
31
26
|
|
32
|
-
def decimal(l_digits
|
33
|
-
l_d = number(l_digits)
|
34
|
-
r_d =
|
35
|
-
|
36
|
-
|
27
|
+
def decimal(l_digits: 5, r_digits: 2)
|
28
|
+
l_d = number(digits: l_digits)
|
29
|
+
r_d = if r_digits == 1
|
30
|
+
generate(r_digits)
|
31
|
+
else
|
32
|
+
# Ensure the last digit is not zero
|
33
|
+
# so it does not get truncated on converting to float
|
34
|
+
generate(r_digits - 1).join + non_zero_digit.to_s
|
35
|
+
end
|
36
|
+
"#{l_d}.#{r_d}".to_f
|
37
37
|
end
|
38
38
|
|
39
39
|
def non_zero_digit
|
40
|
-
rand(1..9)
|
40
|
+
rand(1..9)
|
41
41
|
end
|
42
42
|
|
43
43
|
def digit
|
44
|
-
rand(10)
|
44
|
+
rand(10)
|
45
45
|
end
|
46
46
|
|
47
|
-
def hexadecimal(digits
|
47
|
+
def hexadecimal(digits: 6)
|
48
48
|
hex = ''
|
49
49
|
digits.times { hex += rand(15).to_s(16) }
|
50
50
|
hex
|
51
51
|
end
|
52
52
|
|
53
|
-
def normal(mean
|
53
|
+
def normal(mean: 1, standard_deviation: 1)
|
54
54
|
theta = 2 * Math::PI * rand
|
55
55
|
rho = Math.sqrt(-2 * Math.log(1 - rand))
|
56
56
|
scale = standard_deviation * rho
|
57
57
|
mean + scale * Math.cos(theta)
|
58
58
|
end
|
59
59
|
|
60
|
-
def between(from
|
60
|
+
def between(from: 1.00, to: 5000.00)
|
61
61
|
Faker::Base.rand_in_range(from, to)
|
62
62
|
end
|
63
63
|
|
64
|
-
def within(range
|
65
|
-
between(range.min, range.max)
|
64
|
+
def within(range: 1.00..5000.00)
|
65
|
+
between(from: range.min, to: range.max)
|
66
66
|
end
|
67
67
|
|
68
|
-
def positive(from
|
69
|
-
random_number = between(from, to)
|
68
|
+
def positive(from: 1.00, to: 5000.00)
|
69
|
+
random_number = between(from: from, to: to)
|
70
70
|
|
71
71
|
greater_than_zero(random_number)
|
72
72
|
end
|
73
73
|
|
74
|
-
def negative(from
|
75
|
-
random_number = between(from, to)
|
74
|
+
def negative(from: -5000.00, to: -1.00)
|
75
|
+
random_number = between(from: from, to: to)
|
76
76
|
|
77
77
|
less_than_zero(random_number)
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
81
81
|
|
82
|
+
def generate(count)
|
83
|
+
return [] if count.zero?
|
84
|
+
|
85
|
+
Array.new(count) { digit }
|
86
|
+
end
|
87
|
+
|
82
88
|
def greater_than_zero(number)
|
83
89
|
should_be(number, :>)
|
84
90
|
end
|
@@ -94,9 +100,6 @@ module Faker
|
|
94
100
|
number * -1
|
95
101
|
end
|
96
102
|
end
|
97
|
-
|
98
|
-
deprecate :decimal_part, nil, 2019, 06
|
99
|
-
deprecate :leading_zero_number, nil, 2019, 06
|
100
103
|
end
|
101
104
|
end
|
102
105
|
end
|
@@ -10,12 +10,12 @@ module Faker
|
|
10
10
|
|
11
11
|
def initialize(name: nil, email: nil)
|
12
12
|
@name = name || "#{Name.first_name} #{Name.last_name}"
|
13
|
-
@email = email || Internet.safe_email(self.name)
|
13
|
+
@email = email || Internet.safe_email(name: self.name)
|
14
14
|
@first_name, @last_name = self.name.split
|
15
15
|
end
|
16
16
|
|
17
17
|
class << self
|
18
|
-
def google(name: nil, email: nil, uid: Number.number(9))
|
18
|
+
def google(name: nil, email: nil, uid: Number.number(digits: 9).to_s)
|
19
19
|
auth = Omniauth.new(name: name, email: email)
|
20
20
|
{
|
21
21
|
provider: 'google_oauth2',
|
@@ -44,7 +44,7 @@ module Faker
|
|
44
44
|
profile: "https://plus.google.com/#{uid}",
|
45
45
|
picture: image,
|
46
46
|
gender: gender,
|
47
|
-
birthday: Date.backward(36_400).strftime('%Y-%m-%d'),
|
47
|
+
birthday: Date.backward(days: 36_400).strftime('%Y-%m-%d'),
|
48
48
|
local: 'en',
|
49
49
|
hd: "#{Company.name.downcase}.com"
|
50
50
|
},
|
@@ -52,7 +52,7 @@ module Faker
|
|
52
52
|
'iss' => 'accounts.google.com',
|
53
53
|
'at_hash' => Crypto.md5,
|
54
54
|
'email_verified' => true,
|
55
|
-
'sub' => Number.number(28).to_s,
|
55
|
+
'sub' => Number.number(digits: 28).to_s,
|
56
56
|
'azp' => 'APP_ID',
|
57
57
|
'email' => auth.email,
|
58
58
|
'aud' => 'APP_ID',
|
@@ -64,7 +64,7 @@ module Faker
|
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
67
|
-
def facebook(name: nil, email: nil, username: nil, uid: Number.number(7))
|
67
|
+
def facebook(name: nil, email: nil, username: nil, uid: Number.number(digits: 7).to_s)
|
68
68
|
auth = Omniauth.new(name: name, email: email)
|
69
69
|
username ||= "#{auth.first_name.downcase[0]}#{auth.last_name.downcase}"
|
70
70
|
{
|
@@ -92,7 +92,7 @@ module Faker
|
|
92
92
|
link: "http://www.facebook.com/#{username}",
|
93
93
|
username: username,
|
94
94
|
location: {
|
95
|
-
id: Number.number(9),
|
95
|
+
id: Number.number(digits: 9).to_s,
|
96
96
|
name: city_state
|
97
97
|
},
|
98
98
|
gender: gender,
|
@@ -106,7 +106,7 @@ module Faker
|
|
106
106
|
}
|
107
107
|
end
|
108
108
|
|
109
|
-
def twitter(name: nil, nickname: nil, uid: Number.number(6))
|
109
|
+
def twitter(name: nil, nickname: nil, uid: Number.number(digits: 6).to_s)
|
110
110
|
auth = Omniauth.new(name: name)
|
111
111
|
nickname ||= auth.name.downcase.delete(' ')
|
112
112
|
location = city_state
|
@@ -179,7 +179,7 @@ module Faker
|
|
179
179
|
}
|
180
180
|
end
|
181
181
|
|
182
|
-
def linkedin(name: nil, email: nil, uid: Number.number(6))
|
182
|
+
def linkedin(name: nil, email: nil, uid: Number.number(digits: 6).to_s)
|
183
183
|
auth = Omniauth.new(name: name, email: email)
|
184
184
|
first_name = auth.first_name.downcase
|
185
185
|
last_name = auth.last_name.downcase
|
@@ -242,7 +242,7 @@ module Faker
|
|
242
242
|
}
|
243
243
|
end
|
244
244
|
|
245
|
-
def github(name: nil, email: nil, uid: Number.number(8))
|
245
|
+
def github(name: nil, email: nil, uid: Number.number(digits: 8).to_s)
|
246
246
|
auth = Omniauth.new(name: name, email: email)
|
247
247
|
login = auth.name.downcase.tr(' ', '-')
|
248
248
|
html_url = "https://github.com/#{login}"
|
@@ -293,8 +293,8 @@ module Faker
|
|
293
293
|
public_gists: random_number_from_range(1..1000),
|
294
294
|
followers: random_number_from_range(1..1000),
|
295
295
|
following: random_number_from_range(1..1000),
|
296
|
-
created_at: Time.backward(36_400).iso8601,
|
297
|
-
updated_at: Time.backward(2).iso8601
|
296
|
+
created_at: Time.backward(days: 36_400).iso8601,
|
297
|
+
updated_at: Time.backward(days: 2).iso8601
|
298
298
|
}
|
299
299
|
}
|
300
300
|
}
|