ffaker 2.19.0 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
data/ffaker.gemspec CHANGED
@@ -9,7 +9,6 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.name = 'ffaker'
11
11
  s.version = FFaker::VERSION
12
- s.date = '2021-08-17'
13
12
  s.required_ruby_version = '>= 2.5'
14
13
 
15
14
  s.license = 'MIT'
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FFaker
4
+ module Number
5
+ extend ModuleUtils
6
+ extend self
7
+
8
+ def number(digits: 1)
9
+ FFaker.numerify(generate_pattern(digits)).to_i
10
+ end
11
+
12
+ def decimal(whole_digits: 1, fractional_digits: 1)
13
+ whole_part_pattern = generate_pattern(whole_digits)
14
+ fractional_part_pattern = generate_pattern(fractional_digits).reverse
15
+ FFaker.numerify("#{whole_part_pattern}.#{fractional_part_pattern}").to_f
16
+ end
17
+
18
+ private
19
+
20
+ def generate_pattern(digits)
21
+ raise ArgumentError.new('Digits cannot be less than 1') if digits < 1
22
+
23
+ "#{fetch_sample(1..9)}#{"#" * (digits - 1)}"
24
+ end
25
+ end
26
+ end
@@ -24,15 +24,17 @@ module FFaker
24
24
  number MOBILE_PHONE_PREFIXES
25
25
  end
26
26
 
27
+ private
28
+
27
29
  def number(prefixes)
28
- p = [
29
- COUNTRY_PREFIX.sample,
30
- prefixes.sample,
30
+ pattern = [
31
+ fetch_sample(COUNTRY_PREFIX),
32
+ fetch_sample(prefixes),
31
33
  random_space,
32
- PHONE_NUMBER.sample
33
- ].join('')
34
+ fetch_sample(PHONE_NUMBER)
35
+ ].join
34
36
 
35
- FFaker.numerify p
37
+ FFaker.numerify(pattern)
36
38
  end
37
39
 
38
40
  def random_space
data/lib/ffaker.rb CHANGED
@@ -173,6 +173,7 @@ module FFaker
173
173
  autoload :NameUA, 'ffaker/name_ua'
174
174
  autoload :NameVN, 'ffaker/name_vn'
175
175
  autoload :NatoAlphabet, 'ffaker/nato_alphabet'
176
+ autoload :Number, 'ffaker/number'
176
177
  autoload :PhoneNumber, 'ffaker/phone_number'
177
178
  autoload :PhoneNumberAU, 'ffaker/phone_number_au'
178
179
  autoload :PhoneNumberBR, 'ffaker/phone_number_br'
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FFaker
4
- VERSION = '2.19.0'
4
+ VERSION = '2.20.0'
5
5
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class TestNumber < Test::Unit::TestCase
6
+ include DeterministicHelper
7
+
8
+ assert_methods_are_deterministic(FFaker::Number, :number, :decimal)
9
+
10
+ def setup
11
+ @tester = FFaker::Number
12
+ end
13
+
14
+ def test_number
15
+ assert @tester.number.is_a?(Integer)
16
+ assert @tester.number.digits.count == 1
17
+ assert @tester.number(digits: 3).digits.count == 3
18
+ assert_match(/\d/, @tester.number.to_s)
19
+ assert_match(/\d{3}/, @tester.number(digits: 3).to_s)
20
+ end
21
+
22
+ def test_number_when_invalid_argument
23
+ assert_raise(ArgumentError.new('Digits cannot be less than 1')) { @tester.number(digits: 0) }
24
+ end
25
+
26
+ def test_decimal
27
+ assert @tester.decimal.is_a?(Float)
28
+
29
+ whole_digits = rand(2..5)
30
+ fractional_digits = rand(2..5)
31
+ decimal = @tester.decimal(whole_digits: whole_digits, fractional_digits: fractional_digits)
32
+ assert decimal.to_s.split('.').first.size == whole_digits
33
+ assert decimal.to_s.split('.').last.size == fractional_digits
34
+ end
35
+
36
+ def test_decimal_when_invalid_argument
37
+ assert_raise(ArgumentError.new('Digits cannot be less than 1')) do
38
+ @tester.decimal(whole_digits: 0)
39
+ end
40
+
41
+ assert_raise(ArgumentError.new('Digits cannot be less than 1')) do
42
+ @tester.decimal(fractional_digits: 0)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helper'
4
+
5
+ class TestPhoneNumberIT < Test::Unit::TestCase
6
+ include DeterministicHelper
7
+
8
+ assert_methods_are_deterministic(
9
+ FFaker::PhoneNumberIT,
10
+ :phone_number, :home_phone_number, :mobile_phone_number
11
+ )
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.0
4
+ version: 2.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/ffaker/ffaker/graphs/contributors
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-17 00:00:00.000000000 Z
12
+ date: 2021-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -573,6 +573,7 @@ files:
573
573
  - lib/ffaker/name_ua.rb
574
574
  - lib/ffaker/name_vn.rb
575
575
  - lib/ffaker/nato_alphabet.rb
576
+ - lib/ffaker/number.rb
576
577
  - lib/ffaker/phone_number.rb
577
578
  - lib/ffaker/phone_number_au.rb
578
579
  - lib/ffaker/phone_number_br.rb
@@ -771,6 +772,7 @@ files:
771
772
  - test/test_name_ua.rb
772
773
  - test/test_name_vn.rb
773
774
  - test/test_nato_alphabet.rb
775
+ - test/test_number.rb
774
776
  - test/test_phone_number.rb
775
777
  - test/test_phone_number_au.rb
776
778
  - test/test_phone_number_br.rb
@@ -779,6 +781,7 @@ files:
779
781
  - test/test_phone_number_de.rb
780
782
  - test/test_phone_number_fr.rb
781
783
  - test/test_phone_number_id.rb
784
+ - test/test_phone_number_it.rb
782
785
  - test/test_phone_number_ja.rb
783
786
  - test/test_phone_number_kr.rb
784
787
  - test/test_phone_number_mx.rb
@@ -837,191 +840,193 @@ signing_key:
837
840
  specification_version: 2
838
841
  summary: Ffaker generates dummy data.
839
842
  test_files:
840
- - test/test_identification_es_cl.rb
841
- - test/test_phone_number_au.rb
842
- - test/test_vehicle.rb
843
- - test/test_name_de.rb
844
- - test/test_education_cn.rb
845
- - test/test_color_pl.rb
846
- - test/test_phone_number_se.rb
847
- - test/test_name_se.rb
848
- - test/test_conference.rb
849
- - test/test_phone_number_tw.rb
850
- - test/test_lorem_ru.rb
843
+ - test/test_guid.rb
844
+ - test/test_address_mx.rb
845
+ - test/test_healthcare_ru.rb
846
+ - test/test_address_ch_de.rb
847
+ - test/test_name_gr.rb
848
+ - test/test_phone_number_cu.rb
849
+ - test/test_name_kr.rb
850
+ - test/test_gender_pl.rb
851
+ - test/test_address_gr.rb
852
+ - test/test_boolean.rb
853
+ - test/test_job_vn.rb
851
854
  - test/test_freedom_ipsum.rb
852
- - test/test_job_ja.rb
853
- - test/test_time.rb
855
+ - test/test_gender_kr.rb
856
+ - test/test_sport_pl.rb
857
+ - test/test_ffaker.rb
858
+ - test/test_name_id.rb
859
+ - test/test_bank.rb
860
+ - test/test_gender_it.rb
861
+ - test/test_locale.rb
862
+ - test/test_phone_number_id.rb
863
+ - test/test_address_it.rb
864
+ - test/test_address_fi.rb
865
+ - test/test_game.rb
854
866
  - test/helper.rb
855
- - test/test_movie.rb
867
+ - test/test_bacon_ipsum.rb
868
+ - test/test_name_ar.rb
869
+ - test/test_lorem_ar.rb
870
+ - test/test_phone_number_sg.rb
856
871
  - test/test_address_ja.rb
857
- - test/test_gender_jp.rb
858
- - test/test_color_ua.rb
859
- - test/test_animal_pl.rb
860
- - test/test_food_pl.rb
861
- - test/test_name_es.rb
862
- - test/test_identification_br.rb
863
- - test/test_gender_pl.rb
864
- - test/test_job_cn.rb
865
- - test/test_name_mx.rb
866
- - test/test_address_kr.rb
867
- - test/test_phone_number_fr.rb
868
- - test/test_address_se.rb
869
- - test/test_internet.rb
870
- - test/test_units.rb
871
- - test/test_job.rb
872
- - test/test_name_ja.rb
873
- - test/test_lorem_ua.rb
874
- - test/test_gender_ru.rb
872
+ - test/test_name_vn.rb
873
+ - test/test_company_fr.rb
875
874
  - test/test_gender.rb
876
- - test/test_course_mathematiques.rb
877
- - test/test_phone_number_br.rb
878
- - test/test_job_br.rb
875
+ - test/test_cheesy_lingo.rb
876
+ - test/test_geolocation.rb
877
+ - test/test_name_th.rb
878
+ - test/test_lorem_pl.rb
879
+ - test/test_address_ru.rb
879
880
  - test/test_filesystem.rb
881
+ - test/test_name_pl.rb
882
+ - test/test_animal_pl.rb
883
+ - test/test_name_ga.rb
884
+ - test/test_address_br.rb
885
+ - test/test_name_de.rb
886
+ - test/test_address.rb
887
+ - test/test_phone_number_pl.rb
888
+ - test/test_phone_number_br.rb
889
+ - test/test_phone_number_tw.rb
890
+ - test/test_hipster_ipsum.rb
891
+ - test/test_nato_alphabet.rb
892
+ - test/test_name_nl.rb
893
+ - test/test_lorem.rb
880
894
  - test/test_sport_ru.rb
881
- - test/test_healthcare_ru.rb
882
- - test/test_address_ua.rb
895
+ - test/test_movie.rb
896
+ - test/test_aws.rb
897
+ - test/test_html_ipsum.rb
898
+ - test/test_phone_number_au.rb
899
+ - test/test_color_pl.rb
900
+ - test/test_lorem_cn.rb
901
+ - test/test_job_cn.rb
902
+ - test/test_name_th_en.rb
903
+ - test/test_lorem_it.rb
904
+ - test/test_identification_es_cl.rb
905
+ - test/test_name_fr.rb
883
906
  - test/test_lorem_kr.rb
884
907
  - test/test_youtube.rb
885
- - test/test_guid.rb
886
- - test/test_name_cs.rb
887
- - test/test_name_ua.rb
908
+ - test/test_identification_pl.rb
909
+ - test/test_address_ch.rb
910
+ - test/test_course_philosophie.rb
911
+ - test/test_ssn.rb
912
+ - test/test_job_kr.rb
913
+ - test/test_address_de.rb
914
+ - test/test_unique_utils.rb
915
+ - test/test_code.rb
916
+ - test/test_name_es.rb
917
+ - test/test_phone_number.rb
918
+ - test/test_phone_number_ru.rb
919
+ - test/test_phone_number_fr.rb
920
+ - test/test_name_sn.rb
921
+ - test/test_company.rb
922
+ - test/test_address_nl.rb
923
+ - test/test_address_ca.rb
924
+ - test/test_number.rb
925
+ - test/test_phone_number_nl.rb
926
+ - test/test_gender_id.rb
927
+ - test/test_address_fr.rb
928
+ - test/test_book.rb
929
+ - test/test_identification_kr.rb
930
+ - test/test_phone_number_se.rb
931
+ - test/test_phone_number_sn.rb
932
+ - test/test_gender_ru.rb
933
+ - test/test_string.rb
934
+ - test/test_lorem_ru.rb
935
+ - test/test_address_in.rb
936
+ - test/test_lorem_br.rb
888
937
  - test/test_ssn_mx.rb
938
+ - test/test_sem_ver.rb
939
+ - test/test_address_ua.rb
940
+ - test/test_name_cn.rb
941
+ - test/test_color_ua.rb
942
+ - test/test_identification_es.rb
943
+ - test/test_currency.rb
944
+ - test/test_lorem_fr.rb
945
+ - test/test_education_cn.rb
946
+ - test/test_identification_it.rb
889
947
  - test/test_name_kh.rb
890
- - test/test_address_ch_de.rb
891
- - test/test_phone_number_ua.rb
892
- - test/test_address_ru.rb
893
- - test/test_code.rb
894
- - test/test_address_gr.rb
895
- - test/test_name_kr.rb
896
- - test/test_identification_co.rb
897
- - test/test_address_it.rb
898
- - test/test_healthcare_ipsum.rb
948
+ - test/test_name_mx.rb
949
+ - test/test_sport_us.rb
950
+ - test/test_job_it.rb
899
951
  - test/test_lorem_ja.rb
900
- - test/test_name_ga.rb
901
- - test/test_identification_pl.rb
902
- - test/test_module_utils.rb
903
- - test/test_animal_cn.rb
952
+ - test/test_food.rb
953
+ - test/test_company_it.rb
954
+ - test/test_internet.rb
955
+ - test/test_food_pl.rb
956
+ - test/test_color.rb
957
+ - test/test_avatar.rb
958
+ - test/test_time.rb
959
+ - test/test_address_id.rb
960
+ - test/test_address_kr.rb
961
+ - test/test_phone_number_de.rb
962
+ - test/test_tweet.rb
963
+ - test/test_job_ja.rb
964
+ - test/test_name_se.rb
904
965
  - test/test_phone_number_mx.rb
905
- - test/test_string.rb
966
+ - test/test_address_da.rb
967
+ - test/test_name_cs.rb
968
+ - test/test_address_ch_fr.rb
969
+ - test/test_gender_jp.rb
970
+ - test/test_dizzle_ipsum.rb
971
+ - test/test_name_it.rb
972
+ - test/test_address_sn.rb
973
+ - test/test_name_ja.rb
974
+ - test/test_gender_cn.rb
975
+ - test/test_company_cn.rb
976
+ - test/test_units.rb
977
+ - test/test_company_ja.rb
978
+ - test/test_name.rb
979
+ - test/test_job_fr.rb
980
+ - test/test_identification_es_mx.rb
906
981
  - test/test_address_uk.rb
907
- - test/test_gender_id.rb
908
- - test/test_address.rb
909
- - test/test_gender_it.rb
910
- - test/test_html_ipsum.rb
911
- - test/test_phone_number_cu.rb
912
- - test/test_boolean.rb
913
- - test/test_gender_br.rb
914
- - test/test_phone_number_de.rb
915
- - test/test_phone_number.rb
916
- - test/test_name_ar.rb
917
- - test/test_sem_ver.rb
982
+ - test/test_phone_number_da.rb
918
983
  - test/test_address_ch_it.rb
919
- - test/test_company_fr.rb
920
- - test/test_airline.rb
921
- - test/test_address_ch.rb
984
+ - test/test_job.rb
985
+ - test/test_address_us.rb
986
+ - test/test_address_se.rb
987
+ - test/test_name_ua.rb
988
+ - test/test_ssn_se.rb
989
+ - test/test_units_metric.rb
990
+ - test/test_identification_co.rb
991
+ - test/test_animal_cn.rb
992
+ - test/test_gender_ja.rb
993
+ - test/test_animal_us.rb
922
994
  - test/test_education.rb
923
- - test/test_name_cn.rb
924
- - test/test_units_english.rb
925
- - test/test_animal_es.rb
926
- - test/test_nato_alphabet.rb
927
- - test/test_phone_number_nl.rb
928
- - test/test_name_sn.rb
929
995
  - test/test_phone_number_kr.rb
930
- - test/test_phone_number_ru.rb
931
- - test/test_gender_ja.rb
932
- - test/test_lorem_ar.rb
933
- - test/test_address_mx.rb
934
- - test/test_hipster_ipsum.rb
935
- - test/test_name_nb.rb
936
- - test/test_name_vn.rb
937
- - test/test_phone_number_id.rb
938
- - test/test_bank.rb
939
- - test/test_address_fr.rb
996
+ - test/test_products.rb
997
+ - test/test_animal_es.rb
998
+ - test/test_address_pl.rb
999
+ - test/test_vehicle.rb
1000
+ - test/test_gender_br.rb
940
1001
  - test/test_name_tw.rb
941
- - test/test_identification_it.rb
942
- - test/test_name_th_en.rb
943
- - test/test_sports.rb
944
- - test/test_food.rb
945
- - test/test_address_br.rb
946
- - test/test_address_in.rb
947
- - test/test_array_utils.rb
948
- - test/test_address_ca.rb
949
- - test/test_tweet.rb
950
- - test/test_address_de.rb
951
- - test/test_color.rb
952
- - test/test_name_ph.rb
953
- - test/test_job_kr.rb
954
- - test/test_company_cn.rb
955
- - test/test_name_it.rb
956
- - test/test_name_nl.rb
957
- - test/test_phone_number_sn.rb
958
- - test/test_job_vn.rb
959
- - test/test_sport_us.rb
960
- - test/test_gender_kr.rb
961
- - test/test_locale.rb
962
- - test/test_name_pl.rb
1002
+ - test/test_airline.rb
1003
+ - test/test_internet_se.rb
1004
+ - test/test_phone_number_it.rb
1005
+ - test/test_identification_br.rb
963
1006
  - test/test_music.rb
964
- - test/test_book.rb
965
- - test/test_bacon_ipsum.rb
966
- - test/test_address_pl.rb
967
- - test/test_job_it.rb
968
- - test/test_course_philosophie.rb
969
- - test/test_address_us.rb
970
- - test/test_lorem_br.rb
971
- - test/test_image.rb
972
1007
  - test/test_skill.rb
973
- - test/test_geolocation.rb
974
- - test/test_gender_cn.rb
975
- - test/test_cheesy_lingo.rb
976
- - test/test_unique_utils.rb
977
- - test/test_company.rb
978
- - test/test_phone_number_sg.rb
979
- - test/test_identification_kr.rb
980
- - test/test_aws.rb
981
- - test/test_address_sn.rb
982
- - test/test_phone_number_pl.rb
983
- - test/test_lorem_it.rb
984
- - test/test_address_ch_fr.rb
985
- - test/test_lorem_fr.rb
986
- - test/test_game.rb
987
- - test/test_name_fr.rb
988
- - test/test_animal.rb
989
- - test/test_address_da.rb
990
- - test/test_lorem_cn.rb
991
- - test/test_lorem_ie.rb
992
1008
  - test/test_identification.rb
993
- - test/test_name_th.rb
994
- - test/test_name_da.rb
1009
+ - test/test_venue.rb
1010
+ - test/test_animal.rb
1011
+ - test/test_healthcare_ipsum.rb
1012
+ - test/test_conference.rb
995
1013
  - test/test_company_se.rb
996
- - test/test_name_ru.rb
997
- - test/test_ssn_se.rb
998
- - test/test_internet_se.rb
999
- - test/test_address_fi.rb
1000
- - test/test_ssn.rb
1001
- - test/test_products.rb
1014
+ - test/test_name_nb.rb
1002
1015
  - test/test_identification_in.rb
1016
+ - test/test_module_utils.rb
1017
+ - test/test_array_utils.rb
1018
+ - test/test_units_english.rb
1019
+ - test/test_name_br.rb
1020
+ - test/test_phone_number_ua.rb
1021
+ - test/test_lorem_ie.rb
1022
+ - test/test_name_ru.rb
1023
+ - test/test_sports.rb
1024
+ - test/test_lorem_ua.rb
1025
+ - test/test_name_ph.rb
1026
+ - test/test_name_da.rb
1027
+ - test/test_job_br.rb
1003
1028
  - test/test_identification_tw.rb
1004
- - test/test_venue.rb
1005
- - test/test_sport_pl.rb
1006
- - test/test_identification_es_mx.rb
1007
- - test/test_identification_es.rb
1008
- - test/test_avatar.rb
1009
- - test/test_units_metric.rb
1010
- - test/test_ffaker.rb
1011
- - test/test_currency.rb
1012
- - test/test_animal_us.rb
1013
- - test/test_name_id.rb
1014
- - test/test_name.rb
1015
- - test/test_dizzle_ipsum.rb
1016
- - test/test_lorem_pl.rb
1017
- - test/test_phone_number_da.rb
1018
- - test/test_address_au.rb
1019
- - test/test_lorem.rb
1020
- - test/test_company_ja.rb
1029
+ - test/test_image.rb
1021
1030
  - test/test_phone_number_ja.rb
1022
- - test/test_job_fr.rb
1023
- - test/test_address_nl.rb
1024
- - test/test_address_id.rb
1025
- - test/test_name_br.rb
1026
- - test/test_company_it.rb
1027
- - test/test_name_gr.rb
1031
+ - test/test_course_mathematiques.rb
1032
+ - test/test_address_au.rb