faker 2.1.0 → 2.5.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 +171 -3
- data/README.md +5 -5
- data/lib/faker.rb +56 -1
- data/lib/faker/blockchain/aeternity.rb +70 -0
- data/lib/faker/blockchain/bitcoin.rb +26 -0
- data/lib/faker/blockchain/ethereum.rb +10 -0
- data/lib/faker/blockchain/tezos.rb +62 -6
- data/lib/faker/books/book.rb +36 -0
- data/lib/faker/books/culture_series.rb +49 -0
- data/lib/faker/books/dune.rb +66 -5
- data/lib/faker/books/lovecraft.rb +210 -7
- data/lib/faker/creature/animal.rb +9 -0
- data/lib/faker/creature/cat.rb +27 -0
- data/lib/faker/creature/dog.rb +72 -0
- data/lib/faker/creature/horse.rb +18 -0
- data/lib/faker/default/address.rb +25 -5
- data/lib/faker/default/alphanumeric.rb +56 -7
- data/lib/faker/default/app.rb +55 -1
- data/lib/faker/default/appliance.rb +18 -0
- data/lib/faker/default/artist.rb +9 -0
- data/lib/faker/default/avatar.rb +43 -1
- data/lib/faker/default/bank.rb +10 -2
- data/lib/faker/default/boolean.rb +16 -1
- data/lib/faker/default/chile_rut.rb +12 -2
- data/lib/faker/default/chuck_norris.rb +1 -1
- data/lib/faker/default/code.rb +16 -3
- data/lib/faker/default/commerce.rb +17 -3
- data/lib/faker/default/company.rb +10 -2
- data/lib/faker/default/crypto_coin.rb +15 -3
- data/lib/faker/default/date.rb +94 -5
- data/lib/faker/default/demographic.rb +5 -1
- data/lib/faker/default/dessert.rb +27 -0
- data/lib/faker/default/device.rb +54 -0
- data/lib/faker/default/driving_licence.rb +10 -4
- data/lib/faker/default/electrical_components.rb +27 -0
- data/lib/faker/default/file.rb +19 -2
- data/lib/faker/default/fillmurray.rb +9 -1
- data/lib/faker/default/finance.rb +5 -1
- data/lib/faker/default/gender.rb +18 -0
- data/lib/faker/default/greek_philosophers.rb +18 -0
- data/lib/faker/default/hacker.rb +59 -1
- data/lib/faker/default/hipster.rb +45 -6
- data/lib/faker/default/house.rb +18 -0
- data/lib/faker/default/id_number.rb +48 -3
- data/lib/faker/default/industry_segments.rb +36 -0
- data/lib/faker/default/internet.rb +97 -13
- data/lib/faker/default/invoice.rb +16 -3
- data/lib/faker/default/json.rb +19 -2
- data/lib/faker/default/lorem.rb +81 -10
- data/lib/faker/default/lorem_flickr.rb +38 -5
- data/lib/faker/default/lorem_pixel.rb +10 -1
- data/lib/faker/default/markdown.rb +6 -1
- data/lib/faker/default/marketing.rb +9 -0
- data/lib/faker/default/measurement.rb +40 -8
- data/lib/faker/default/military.rb +45 -0
- data/lib/faker/default/name.rb +5 -1
- data/lib/faker/default/nation.rb +48 -5
- data/lib/faker/default/nato_phonetic_alphabet.rb +9 -0
- data/lib/faker/default/nhs.rb +5 -1
- data/lib/faker/default/number.rb +180 -11
- data/lib/faker/default/omniauth.rb +92 -9
- data/lib/faker/default/phone_number.rb +5 -1
- data/lib/faker/default/placeholdit.rb +11 -1
- data/lib/faker/default/programming_language.rb +18 -0
- data/lib/faker/default/relationship.rb +5 -1
- data/lib/faker/default/restaurant.rb +54 -2
- data/lib/faker/default/science.rb +27 -0
- data/lib/faker/default/source.rb +59 -3
- data/lib/faker/default/string.rb +5 -1
- data/lib/faker/default/stripe.rb +20 -4
- data/lib/faker/default/subscription.rb +45 -0
- data/lib/faker/default/superhero.rb +45 -0
- data/lib/faker/default/time.rb +114 -4
- data/lib/faker/default/twitter.rb +32 -18
- data/lib/faker/default/types.rb +27 -5
- data/lib/faker/default/vehicle.rb +17 -4
- data/lib/faker/default/world_cup.rb +11 -2
- data/lib/faker/games/dota.rb +52 -1
- data/lib/faker/games/elder_scrolls.rb +72 -0
- data/lib/faker/games/fallout.rb +37 -0
- data/lib/faker/games/game.rb +27 -0
- data/lib/faker/games/half_life.rb +27 -0
- data/lib/faker/games/heroes.rb +27 -0
- data/lib/faker/games/heroes_of_the_storm.rb +36 -0
- data/lib/faker/games/league_of_legends.rb +54 -0
- data/lib/faker/games/myst.rb +45 -0
- data/lib/faker/games/overwatch.rb +27 -0
- data/lib/faker/games/pokemon.rb +27 -0
- data/lib/faker/games/sonic_the_hedgehog.rb +27 -0
- data/lib/faker/games/super_smash_bros.rb +18 -0
- data/lib/faker/games/witcher.rb +54 -0
- data/lib/faker/games/world_of_warcraft.rb +18 -0
- data/lib/faker/games/zelda.rb +37 -1
- data/lib/faker/japanese_media/dragon_ball.rb +9 -0
- data/lib/faker/japanese_media/one_piece.rb +54 -0
- data/lib/faker/japanese_media/sword_art_online.rb +36 -0
- data/lib/faker/movies/back_to_the_future.rb +28 -0
- data/lib/faker/movies/ghostbusters.rb +28 -0
- data/lib/faker/movies/harry_potter.rb +54 -0
- data/lib/faker/movies/hitchhikers_guide_to_the_galaxy.rb +69 -0
- data/lib/faker/movies/hobbit.rb +37 -0
- data/lib/faker/movies/lebowski.rb +27 -0
- data/lib/faker/movies/lord_of_the_rings.rb +28 -0
- data/lib/faker/movies/movie.rb +9 -0
- data/lib/faker/movies/princess_bride.rb +19 -0
- data/lib/faker/movies/star_wars.rb +100 -4
- data/lib/faker/movies/v_for_vendetta.rb +29 -0
- data/lib/faker/music/grateful_dead.rb +18 -0
- data/lib/faker/music/phish.rb +9 -0
- data/lib/faker/music/rock_band.rb +9 -0
- data/lib/faker/music/umphreys_mcgee.rb +9 -0
- data/lib/faker/sports/basketball.rb +36 -0
- data/lib/faker/sports/football.rb +45 -0
- data/lib/faker/tv_shows/aqua_teen_hunger_force.rb +9 -0
- data/lib/faker/tv_shows/bojack_horseman.rb +28 -0
- data/lib/faker/tv_shows/breaking_bad.rb +18 -0
- data/lib/faker/tv_shows/buffy.rb +45 -0
- data/lib/faker/tv_shows/community.rb +19 -0
- data/lib/faker/tv_shows/dr_who.rb +78 -2
- data/lib/faker/tv_shows/dumb_and_dumber.rb +28 -0
- data/lib/faker/tv_shows/family_guy.rb +28 -0
- data/lib/faker/tv_shows/friends.rb +27 -0
- data/lib/faker/tv_shows/game_of_thrones.rb +46 -0
- data/lib/faker/tv_shows/hey_arnold.rb +27 -0
- data/lib/faker/tv_shows/how_i_met_your_mother.rb +37 -0
- data/lib/faker/tv_shows/michael_scott.rb +13 -0
- data/lib/faker/tv_shows/new_girl.rb +19 -0
- data/lib/faker/tv_shows/parks_and_rec.rb +18 -0
- data/lib/faker/tv_shows/rick_and_morty.rb +28 -0
- data/lib/faker/tv_shows/ru_paul.rb +18 -0
- data/lib/faker/tv_shows/seinfeld.rb +28 -0
- data/lib/faker/tv_shows/silicon_valley.rb +75 -0
- data/lib/faker/tv_shows/simpsons.rb +28 -0
- data/lib/faker/tv_shows/south_park.rb +19 -0
- data/lib/faker/tv_shows/star_trek.rb +36 -0
- data/lib/faker/tv_shows/stargate.rb +28 -0
- data/lib/faker/tv_shows/stranger_things.rb +19 -0
- data/lib/faker/tv_shows/the_expanse.rb +36 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +28 -0
- data/lib/faker/tv_shows/the_it_crowd.rb +37 -0
- data/lib/faker/tv_shows/the_thick_of_it.rb +28 -0
- data/lib/faker/tv_shows/twin_peaks.rb +28 -0
- data/lib/faker/tv_shows/venture_bros.rb +38 -0
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en-CA.yml +1 -1
- data/lib/locales/en-TH.yml +360 -0
- data/lib/locales/en.yml +0 -49
- data/lib/locales/en/color.yml +1 -1
- data/lib/locales/en/dr_who.yml +1 -1
- data/lib/locales/en/science.yml +1 -1
- data/lib/locales/ja.yml +8 -9
- data/lib/locales/th.yml +380 -0
- metadata +39 -20
@@ -5,23 +5,56 @@ module Faker
|
|
5
5
|
class << self
|
6
6
|
SUPPORTED_COLORIZATIONS = %w[red green blue].freeze
|
7
7
|
|
8
|
-
|
8
|
+
# rubocop:disable Metrics/ParameterLists
|
9
|
+
def image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: [], match_all: false)
|
10
|
+
# rubocop:enable Metrics/ParameterLists
|
11
|
+
warn_for_deprecated_arguments do |keywords|
|
12
|
+
keywords << :size if legacy_size != NOT_GIVEN
|
13
|
+
keywords << :search_terms if legacy_search_terms != NOT_GIVEN
|
14
|
+
keywords << :match_all if legacy_match_all != NOT_GIVEN
|
15
|
+
end
|
16
|
+
|
9
17
|
build_url(size, nil, search_terms, match_all)
|
10
18
|
end
|
11
19
|
|
12
|
-
|
20
|
+
# rubocop:disable Metrics/ParameterLists
|
21
|
+
def grayscale_image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: ['all'], match_all: false)
|
22
|
+
# rubocop:enable Metrics/ParameterLists
|
23
|
+
warn_for_deprecated_arguments do |keywords|
|
24
|
+
keywords << :size if legacy_size != NOT_GIVEN
|
25
|
+
keywords << :search_terms if legacy_search_terms != NOT_GIVEN
|
26
|
+
keywords << :match_all if legacy_match_all != NOT_GIVEN
|
27
|
+
end
|
28
|
+
|
13
29
|
raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any?
|
14
30
|
|
15
31
|
build_url(size, 'g', search_terms, match_all)
|
16
32
|
end
|
17
33
|
|
18
|
-
|
34
|
+
# rubocop:disable Metrics/ParameterLists
|
35
|
+
def pixelated_image(legacy_size = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', search_terms: ['all'], match_all: false)
|
36
|
+
# rubocop:enable Metrics/ParameterLists
|
37
|
+
warn_for_deprecated_arguments do |keywords|
|
38
|
+
keywords << :size if legacy_size != NOT_GIVEN
|
39
|
+
keywords << :search_terms if legacy_search_terms != NOT_GIVEN
|
40
|
+
keywords << :match_all if legacy_match_all != NOT_GIVEN
|
41
|
+
end
|
42
|
+
|
19
43
|
raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any?
|
20
44
|
|
21
45
|
build_url(size, 'p', search_terms, match_all)
|
22
46
|
end
|
23
47
|
|
24
|
-
|
48
|
+
# rubocop:disable Metrics/ParameterLists
|
49
|
+
def colorized_image(legacy_size = NOT_GIVEN, legacy_color = NOT_GIVEN, legacy_search_terms = NOT_GIVEN, legacy_match_all = NOT_GIVEN, size: '300x300', color: 'red', search_terms: ['all'], match_all: false)
|
50
|
+
# rubocop:enable Metrics/ParameterLists
|
51
|
+
warn_for_deprecated_arguments do |keywords|
|
52
|
+
keywords << :size if legacy_size != NOT_GIVEN
|
53
|
+
keywords << :color if legacy_color != NOT_GIVEN
|
54
|
+
keywords << :search_terms if legacy_search_terms != NOT_GIVEN
|
55
|
+
keywords << :match_all if legacy_match_all != NOT_GIVEN
|
56
|
+
end
|
57
|
+
|
25
58
|
raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any?
|
26
59
|
raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color)
|
27
60
|
|
@@ -33,7 +66,7 @@ module Faker
|
|
33
66
|
def build_url(size, format, search_terms, match_all)
|
34
67
|
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
35
68
|
|
36
|
-
url_parts = ['
|
69
|
+
url_parts = ['https://loremflickr.com']
|
37
70
|
url_parts << format
|
38
71
|
url_parts += size.split('x')
|
39
72
|
url_parts << search_terms.compact.join(',') if search_terms.any?
|
@@ -18,7 +18,16 @@ module Faker
|
|
18
18
|
transport].freeze
|
19
19
|
|
20
20
|
# rubocop:disable Metrics/ParameterLists
|
21
|
-
def image(size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true)
|
21
|
+
def image(legacy_size = NOT_GIVEN, legacy_is_gray = NOT_GIVEN, legacy_category = NOT_GIVEN, legacy_number = NOT_GIVEN, legacy_text = NOT_GIVEN, legacy_secure = NOT_GIVEN, size: '300x300', is_gray: false, category: nil, number: nil, text: nil, secure: true)
|
22
|
+
warn_for_deprecated_arguments do |keywords|
|
23
|
+
keywords << :size if legacy_size != NOT_GIVEN
|
24
|
+
keywords << :is_gray if legacy_is_gray != NOT_GIVEN
|
25
|
+
keywords << :category if legacy_category != NOT_GIVEN
|
26
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
27
|
+
keywords << :text if legacy_text != NOT_GIVEN
|
28
|
+
keywords << :secure if legacy_secure != NOT_GIVEN
|
29
|
+
end
|
30
|
+
|
22
31
|
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
23
32
|
raise ArgumentError, "Supported categories are #{SUPPORTED_CATEGORIES.join(', ')}" unless category.nil? || SUPPORTED_CATEGORIES.include?(category)
|
24
33
|
raise ArgumentError, 'Category required when number is passed' if !number.nil? && category.nil?
|
@@ -59,7 +59,12 @@ module Faker
|
|
59
59
|
send(method_list[rand(0..method_list.length - 1)])
|
60
60
|
end
|
61
61
|
|
62
|
-
def sandwich(sentences: 3, repeat: 1)
|
62
|
+
def sandwich(legacy_sentences = NOT_GIVEN, legacy_repeat = NOT_GIVEN, sentences: 3, repeat: 1)
|
63
|
+
warn_for_deprecated_arguments do |keywords|
|
64
|
+
keywords << :sentences if legacy_sentences != NOT_GIVEN
|
65
|
+
keywords << :repeat if legacy_repeat != NOT_GIVEN
|
66
|
+
end
|
67
|
+
|
63
68
|
text_block = []
|
64
69
|
text_block << headers
|
65
70
|
repeat.times do
|
@@ -5,6 +5,15 @@ module Faker
|
|
5
5
|
flexible :marketing
|
6
6
|
|
7
7
|
class << self
|
8
|
+
##
|
9
|
+
# Produces the name of a video game console or platform.
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Faker::Marketing.buzzwords #=> "rubber meets the road"
|
15
|
+
#
|
16
|
+
# @faker.version 1.9.4
|
8
17
|
def buzzwords
|
9
18
|
fetch('marketing.buzzwords')
|
10
19
|
end
|
@@ -6,35 +6,67 @@ module Faker
|
|
6
6
|
ALL = 'all'
|
7
7
|
NONE = 'none'
|
8
8
|
|
9
|
-
def height(amount: rand(10))
|
9
|
+
def height(legacy_amount = NOT_GIVEN, amount: rand(10))
|
10
|
+
warn_for_deprecated_arguments do |keywords|
|
11
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
12
|
+
end
|
13
|
+
|
10
14
|
define_measurement_locale(amount, 'height')
|
11
15
|
end
|
12
16
|
|
13
|
-
def length(amount: rand(10))
|
17
|
+
def length(legacy_amount = NOT_GIVEN, amount: rand(10))
|
18
|
+
warn_for_deprecated_arguments do |keywords|
|
19
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
20
|
+
end
|
21
|
+
|
14
22
|
define_measurement_locale(amount, 'length')
|
15
23
|
end
|
16
24
|
|
17
|
-
def volume(amount: rand(10))
|
25
|
+
def volume(legacy_amount = NOT_GIVEN, amount: rand(10))
|
26
|
+
warn_for_deprecated_arguments do |keywords|
|
27
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
28
|
+
end
|
29
|
+
|
18
30
|
define_measurement_locale(amount, 'volume')
|
19
31
|
end
|
20
32
|
|
21
|
-
def weight(amount: rand(10))
|
33
|
+
def weight(legacy_amount = NOT_GIVEN, amount: rand(10))
|
34
|
+
warn_for_deprecated_arguments do |keywords|
|
35
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
36
|
+
end
|
37
|
+
|
22
38
|
define_measurement_locale(amount, 'weight')
|
23
39
|
end
|
24
40
|
|
25
|
-
def metric_height(amount: rand(10))
|
41
|
+
def metric_height(legacy_amount = NOT_GIVEN, amount: rand(10))
|
42
|
+
warn_for_deprecated_arguments do |keywords|
|
43
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
44
|
+
end
|
45
|
+
|
26
46
|
define_measurement_locale(amount, 'metric_height')
|
27
47
|
end
|
28
48
|
|
29
|
-
def metric_length(amount: rand(10))
|
49
|
+
def metric_length(legacy_amount = NOT_GIVEN, amount: rand(10))
|
50
|
+
warn_for_deprecated_arguments do |keywords|
|
51
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
52
|
+
end
|
53
|
+
|
30
54
|
define_measurement_locale(amount, 'metric_length')
|
31
55
|
end
|
32
56
|
|
33
|
-
def metric_volume(amount: rand(10))
|
57
|
+
def metric_volume(legacy_amount = NOT_GIVEN, amount: rand(10))
|
58
|
+
warn_for_deprecated_arguments do |keywords|
|
59
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
60
|
+
end
|
61
|
+
|
34
62
|
define_measurement_locale(amount, 'metric_volume')
|
35
63
|
end
|
36
64
|
|
37
|
-
def metric_weight(amount: rand(10))
|
65
|
+
def metric_weight(legacy_amount = NOT_GIVEN, amount: rand(10))
|
66
|
+
warn_for_deprecated_arguments do |keywords|
|
67
|
+
keywords << :amount if legacy_amount != NOT_GIVEN
|
68
|
+
end
|
69
|
+
|
38
70
|
define_measurement_locale(amount, 'metric_weight')
|
39
71
|
end
|
40
72
|
|
@@ -3,22 +3,67 @@
|
|
3
3
|
module Faker
|
4
4
|
class Military < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces a rank in the U.S. Army.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::Military.army_rank #=> "Staff Sergeant"
|
13
|
+
#
|
14
|
+
# @faker.version 1.9.0
|
6
15
|
def army_rank
|
7
16
|
fetch('military.army_rank')
|
8
17
|
end
|
9
18
|
|
19
|
+
##
|
20
|
+
# Produces a rank in the U.S. Marines.
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Faker::Military.marines_rank #=> "Gunnery Sergeant"
|
26
|
+
#
|
27
|
+
# @faker.version 1.9.0
|
10
28
|
def marines_rank
|
11
29
|
fetch('military.marines_rank')
|
12
30
|
end
|
13
31
|
|
32
|
+
##
|
33
|
+
# Produces a rank in the U.S. Navy.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Faker::Military.navy_rank #=> "Seaman"
|
39
|
+
#
|
40
|
+
# @faker.version 1.9.0
|
14
41
|
def navy_rank
|
15
42
|
fetch('military.navy_rank')
|
16
43
|
end
|
17
44
|
|
45
|
+
##
|
46
|
+
# Produces a rank in the U.S. Air Force.
|
47
|
+
#
|
48
|
+
# @return [String]
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# Faker::Military.air_force_rank #=> "Captain"
|
52
|
+
#
|
53
|
+
# @faker.version 1.9.0
|
18
54
|
def air_force_rank
|
19
55
|
fetch('military.air_force_rank')
|
20
56
|
end
|
21
57
|
|
58
|
+
##
|
59
|
+
# Produces a U.S. Department of Defense Paygrade.
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# Faker::Military.dod_paygrade #=> "E-6"
|
65
|
+
#
|
66
|
+
# @faker.version 1.9.0
|
22
67
|
def dod_paygrade
|
23
68
|
fetch('military.dod_paygrade')
|
24
69
|
end
|
data/lib/faker/default/name.rb
CHANGED
@@ -46,7 +46,11 @@ module Faker
|
|
46
46
|
fetch('name.suffix')
|
47
47
|
end
|
48
48
|
|
49
|
-
def initials(number: 3)
|
49
|
+
def initials(legacy_number = NOT_GIVEN, number: 3)
|
50
|
+
warn_for_deprecated_arguments do |keywords|
|
51
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
52
|
+
end
|
53
|
+
|
50
54
|
(0...number).map { rand(65..90).chr }.join
|
51
55
|
end
|
52
56
|
end
|
data/lib/faker/default/nation.rb
CHANGED
@@ -4,27 +4,70 @@ module Faker
|
|
4
4
|
class Nation < Base
|
5
5
|
flexible :nation
|
6
6
|
class << self
|
7
|
-
|
7
|
+
##
|
8
|
+
# Produces a random nationality.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Faker::Nation.nationality #=> "Nepalese"
|
14
|
+
#
|
15
|
+
# @faker.version 1.9.0
|
8
16
|
def nationality
|
9
17
|
fetch('nation.nationality')
|
10
18
|
end
|
11
19
|
|
12
|
-
#
|
20
|
+
# rubocop:disable Style/AsciiComments
|
21
|
+
|
22
|
+
##
|
23
|
+
# Produces a random national flag emoji.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Faker::Nation.flag #=> "🇫🇮"
|
29
|
+
#
|
30
|
+
# @faker.version 1.9.0
|
13
31
|
def flag
|
14
32
|
sample(translate('faker.nation.flag')).pack('C*').force_encoding('utf-8')
|
15
33
|
end
|
34
|
+
# rubocop:enable Style/AsciiComments
|
16
35
|
|
17
|
-
|
36
|
+
##
|
37
|
+
# Produces a random national language.
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Faker::Nation.language #=> "Nepali"
|
43
|
+
#
|
44
|
+
# @faker.version 1.9.0
|
18
45
|
def language
|
19
46
|
fetch('nation.language')
|
20
47
|
end
|
21
48
|
|
22
|
-
|
49
|
+
##
|
50
|
+
# Produces a random capital city.
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
# Faker::Nation.capital_city #=> "Kathmandu"
|
56
|
+
#
|
57
|
+
# @faker.version 1.9.0
|
23
58
|
def capital_city
|
24
59
|
fetch('nation.capital_city')
|
25
60
|
end
|
26
61
|
|
27
|
-
|
62
|
+
##
|
63
|
+
# Produces a random national sport.
|
64
|
+
#
|
65
|
+
# @return [String]
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# Faker::Nation.national_sport #=> "dandi biyo"
|
69
|
+
#
|
70
|
+
# @faker.version 1.9.0
|
28
71
|
def national_sport
|
29
72
|
fetch('team.sport')
|
30
73
|
end
|
@@ -3,6 +3,15 @@
|
|
3
3
|
module Faker
|
4
4
|
class NatoPhoneticAlphabet < Base
|
5
5
|
class << self
|
6
|
+
##
|
7
|
+
# Produces a code word from the NATO phonetic alphabet.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Faker::NatoPhoneticAlphabet.code_word #=> "Hotel"
|
13
|
+
#
|
14
|
+
# @faker.version 1.9.0
|
6
15
|
def code_word
|
7
16
|
fetch('nato_phonetic_alphabet.code_word')
|
8
17
|
end
|
data/lib/faker/default/nhs.rb
CHANGED
@@ -15,7 +15,11 @@ module Faker
|
|
15
15
|
.join('')
|
16
16
|
end
|
17
17
|
|
18
|
-
def check_digit(number: 0)
|
18
|
+
def check_digit(legacy_number = NOT_GIVEN, number: 0)
|
19
|
+
warn_for_deprecated_arguments do |keywords|
|
20
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
21
|
+
end
|
22
|
+
|
19
23
|
sum = 0
|
20
24
|
number.to_s.chars.each_with_index do |digit, idx|
|
21
25
|
position = idx + 1
|
data/lib/faker/default/number.rb
CHANGED
@@ -3,19 +3,61 @@
|
|
3
3
|
module Faker
|
4
4
|
class Number < Base
|
5
5
|
class << self
|
6
|
-
|
6
|
+
##
|
7
|
+
# Produce a random number.
|
8
|
+
#
|
9
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
10
|
+
# @return [Integer]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Faker::Number.number(digits: 10) #=> 1968353479
|
14
|
+
#
|
15
|
+
# @faker.version 1.0.0
|
16
|
+
def number(legacy_digits = NOT_GIVEN, digits: 10)
|
17
|
+
warn_for_deprecated_arguments do |keywords|
|
18
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
19
|
+
end
|
20
|
+
|
7
21
|
return if digits < 1
|
8
|
-
return 0 if digits == 1
|
22
|
+
return rand(0..9).round if digits == 1
|
9
23
|
|
10
24
|
# Ensure the first digit is not zero
|
11
25
|
([non_zero_digit] + generate(digits - 1)).join.to_i
|
12
26
|
end
|
13
27
|
|
14
|
-
|
28
|
+
##
|
29
|
+
# Produce a random number with a leading zero.
|
30
|
+
#
|
31
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
32
|
+
# @return [String]
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# Faker::Number.leading_zero_number(digits: 10) #=> "0669336915"
|
36
|
+
#
|
37
|
+
# @faker.version 1.0.0
|
38
|
+
def leading_zero_number(legacy_digits = NOT_GIVEN, digits: 10)
|
39
|
+
warn_for_deprecated_arguments do |keywords|
|
40
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
41
|
+
end
|
42
|
+
|
15
43
|
'0' + (2..digits).collect { digit }.join
|
16
44
|
end
|
17
45
|
|
18
|
-
|
46
|
+
##
|
47
|
+
# Produce a number with a number of digits, preserves leading zeroes.
|
48
|
+
#
|
49
|
+
# @param digits [Integer] Number of digits that the generated number should have.
|
50
|
+
# @return [String]
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# Faker::Number.decimal_part(digits: 2) #=> "09"
|
54
|
+
#
|
55
|
+
# @faker.version 1.0.0
|
56
|
+
def decimal_part(legacy_digits = NOT_GIVEN, digits: 10)
|
57
|
+
warn_for_deprecated_arguments do |keywords|
|
58
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
59
|
+
end
|
60
|
+
|
19
61
|
num = ''
|
20
62
|
if digits > 1
|
21
63
|
num = non_zero_digit
|
@@ -24,7 +66,24 @@ module Faker
|
|
24
66
|
leading_zero_number(digits: digits) + num.to_s
|
25
67
|
end
|
26
68
|
|
27
|
-
|
69
|
+
##
|
70
|
+
# Produces a float.
|
71
|
+
#
|
72
|
+
# @param l_digits [Integer] Number of digits that the generated decimal should have to the left of the decimal point.
|
73
|
+
# @param r_digits [Integer] Number of digits that the generated decimal should have to the right of the decimal point.
|
74
|
+
# @return [Float]
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# Faker::Number.decimal(l_digits: 2) #=> 11.88
|
78
|
+
# Faker::Number.decimal(l_digits: 3, r_digits: 3) #=> 181.843
|
79
|
+
#
|
80
|
+
# @faker.version 1.0.0
|
81
|
+
def decimal(legacy_l_digits = NOT_GIVEN, legacy_r_digits = NOT_GIVEN, l_digits: 5, r_digits: 2)
|
82
|
+
warn_for_deprecated_arguments do |keywords|
|
83
|
+
keywords << :l_digits if legacy_l_digits != NOT_GIVEN
|
84
|
+
keywords << :r_digits if legacy_r_digits != NOT_GIVEN
|
85
|
+
end
|
86
|
+
|
28
87
|
l_d = number(digits: l_digits)
|
29
88
|
r_d = if r_digits == 1
|
30
89
|
generate(r_digits)
|
@@ -36,42 +95,152 @@ module Faker
|
|
36
95
|
"#{l_d}.#{r_d}".to_f
|
37
96
|
end
|
38
97
|
|
98
|
+
##
|
99
|
+
# Produces a non-zero single-digit integer.
|
100
|
+
#
|
101
|
+
# @return [Integer]
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# Faker::Number.non_zero_digit #=> 8
|
105
|
+
#
|
106
|
+
# @faker.version 1.0.0
|
39
107
|
def non_zero_digit
|
40
108
|
rand(1..9)
|
41
109
|
end
|
42
110
|
|
111
|
+
##
|
112
|
+
# Produces a single-digit integer.
|
113
|
+
#
|
114
|
+
# @return [Integer]
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# Faker::Number.digit #=> 1
|
118
|
+
#
|
119
|
+
# @faker.version 1.0.0
|
43
120
|
def digit
|
44
121
|
rand(10)
|
45
122
|
end
|
46
123
|
|
47
|
-
|
124
|
+
##
|
125
|
+
# Produces a number in hexadecimal format.
|
126
|
+
#
|
127
|
+
# @param digits [Integer] Number of digits in the he
|
128
|
+
# @return [String]
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# Faker::Number.hexadecimal(digits: 3) #=> "e74"
|
132
|
+
#
|
133
|
+
# @faker.version 1.0.0
|
134
|
+
def hexadecimal(legacy_digits = NOT_GIVEN, digits: 6)
|
135
|
+
warn_for_deprecated_arguments do |keywords|
|
136
|
+
keywords << :digits if legacy_digits != NOT_GIVEN
|
137
|
+
end
|
138
|
+
|
48
139
|
hex = ''
|
49
140
|
digits.times { hex += rand(15).to_s(16) }
|
50
141
|
hex
|
51
142
|
end
|
52
143
|
|
53
|
-
|
144
|
+
##
|
145
|
+
# Produces a float given a mean and standard deviation.
|
146
|
+
#
|
147
|
+
# @param mean [Integer]
|
148
|
+
# @param standard_deviation [Integer, Float]
|
149
|
+
# @return [Float]
|
150
|
+
#
|
151
|
+
# @example
|
152
|
+
# Faker::Number.normal(mean: 50, standard_deviation: 3.5) #=> 47.14669604069156
|
153
|
+
#
|
154
|
+
# @faker.version 1.0.0
|
155
|
+
def normal(legacy_mean = NOT_GIVEN, legacy_standard_deviation = NOT_GIVEN, mean: 1, standard_deviation: 1)
|
156
|
+
warn_for_deprecated_arguments do |keywords|
|
157
|
+
keywords << :mean if legacy_mean != NOT_GIVEN
|
158
|
+
keywords << :standard_deviation if legacy_standard_deviation != NOT_GIVEN
|
159
|
+
end
|
160
|
+
|
54
161
|
theta = 2 * Math::PI * rand
|
55
162
|
rho = Math.sqrt(-2 * Math.log(1 - rand))
|
56
163
|
scale = standard_deviation * rho
|
57
164
|
mean + scale * Math.cos(theta)
|
58
165
|
end
|
59
166
|
|
60
|
-
|
167
|
+
##
|
168
|
+
# Produces a number between two provided values. Boundaries are inclusive.
|
169
|
+
#
|
170
|
+
# @param from [Integer] The lowest number to include.
|
171
|
+
# @param to [Integer] The highest number to include.
|
172
|
+
# @return [Integer]
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# Faker::Number.between(from: 1, to: 10) #=> 7
|
176
|
+
#
|
177
|
+
# @faker.version 1.0.0
|
178
|
+
def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 1.00, to: 5000.00)
|
179
|
+
warn_for_deprecated_arguments do |keywords|
|
180
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
181
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
182
|
+
end
|
183
|
+
|
61
184
|
Faker::Base.rand_in_range(from, to)
|
62
185
|
end
|
63
186
|
|
64
|
-
|
187
|
+
##
|
188
|
+
# Produces a number within two provided values. Boundaries are inclusive or exclusive depending on the range passed.
|
189
|
+
#
|
190
|
+
# @param range [Range] The range from which to generate a number.
|
191
|
+
# @return [Integer]
|
192
|
+
#
|
193
|
+
# @example
|
194
|
+
# Faker::Number.within(range: 1..10) #=> 7
|
195
|
+
#
|
196
|
+
# @faker.version 1.0.0
|
197
|
+
def within(legacy_range = NOT_GIVEN, range: 1.00..5000.00)
|
198
|
+
warn_for_deprecated_arguments do |keywords|
|
199
|
+
keywords << :range if legacy_range != NOT_GIVEN
|
200
|
+
end
|
201
|
+
|
65
202
|
between(from: range.min, to: range.max)
|
66
203
|
end
|
67
204
|
|
68
|
-
|
205
|
+
##
|
206
|
+
# Produces a positive float.
|
207
|
+
#
|
208
|
+
# @param from [Integer] The lower boundary.
|
209
|
+
# @param to [Integer] The higher boundary.
|
210
|
+
# @return [Float]
|
211
|
+
#
|
212
|
+
# @example
|
213
|
+
# Faker::Number.positive #=> 235.59238499107653
|
214
|
+
#
|
215
|
+
# @faker.version 1.0.0
|
216
|
+
def positive(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 1.00, to: 5000.00)
|
217
|
+
warn_for_deprecated_arguments do |keywords|
|
218
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
219
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
220
|
+
end
|
221
|
+
|
69
222
|
random_number = between(from: from, to: to)
|
70
223
|
|
71
224
|
greater_than_zero(random_number)
|
72
225
|
end
|
73
226
|
|
74
|
-
|
227
|
+
##
|
228
|
+
# Produces a negative float.
|
229
|
+
#
|
230
|
+
# @param from [Integer] The lower boundary.
|
231
|
+
# @param to [Integer] The higher boundary.
|
232
|
+
# @return [Float]
|
233
|
+
#
|
234
|
+
# @example
|
235
|
+
# Faker::Number.negative #=> -4480.042585669558
|
236
|
+
#
|
237
|
+
# @faker.version 1.0.0
|
238
|
+
def negative(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: -5000.00, to: -1.00)
|
239
|
+
warn_for_deprecated_arguments do |keywords|
|
240
|
+
keywords << :from if legacy_from != NOT_GIVEN
|
241
|
+
keywords << :to if legacy_to != NOT_GIVEN
|
242
|
+
end
|
243
|
+
|
75
244
|
random_number = between(from: from, to: to)
|
76
245
|
|
77
246
|
less_than_zero(random_number)
|