ffaker 1.31.0 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/ffaker.gemspec +11 -3
  4. data/lib/ffaker.rb +2 -2
  5. data/lib/ffaker/address.rb +4 -6
  6. data/lib/ffaker/address_au.rb +26 -29
  7. data/lib/ffaker/address_br.rb +2 -2
  8. data/lib/ffaker/address_ca.rb +7 -3
  9. data/lib/ffaker/address_da.rb +6 -9
  10. data/lib/ffaker/address_de.rb +1 -3
  11. data/lib/ffaker/address_fi.rb +3 -3
  12. data/lib/ffaker/address_fr.rb +6 -6
  13. data/lib/ffaker/address_nl.rb +2 -2
  14. data/lib/ffaker/address_se.rb +3 -4
  15. data/lib/ffaker/address_uk.rb +3 -3
  16. data/lib/ffaker/address_us.rb +4 -4
  17. data/lib/ffaker/company.rb +4 -4
  18. data/lib/ffaker/company_it.rb +3 -4
  19. data/lib/ffaker/company_se.rb +2 -3
  20. data/lib/ffaker/currency.rb +16 -0
  21. data/lib/ffaker/data/address_ca/city +181 -0
  22. data/lib/ffaker/data/currency/currency_code +169 -0
  23. data/lib/ffaker/data/currency/currency_name +169 -0
  24. data/lib/ffaker/data/lorem_kr/words +47 -0
  25. data/lib/ffaker/education.rb +8 -7
  26. data/lib/ffaker/geolocation.rb +1 -1
  27. data/lib/ffaker/html_ipsum.rb +1 -1
  28. data/lib/ffaker/identification.rb +3 -3
  29. data/lib/ffaker/identification_es.rb +2 -3
  30. data/lib/ffaker/identification_es_co.rb +4 -3
  31. data/lib/ffaker/identification_mx.rb +4 -5
  32. data/lib/ffaker/internet.rb +7 -7
  33. data/lib/ffaker/internet_se.rb +8 -8
  34. data/lib/ffaker/job_fr.rb +1 -1
  35. data/lib/ffaker/lorem_kr.rb +36 -0
  36. data/lib/ffaker/movie.rb +6 -7
  37. data/lib/ffaker/name.rb +3 -3
  38. data/lib/ffaker/name_br.rb +2 -2
  39. data/lib/ffaker/name_cs.rb +11 -14
  40. data/lib/ffaker/name_da.rb +2 -1
  41. data/lib/ffaker/name_de.rb +2 -2
  42. data/lib/ffaker/name_fr.rb +1 -1
  43. data/lib/ffaker/name_ga.rb +1 -1
  44. data/lib/ffaker/name_it.rb +1 -1
  45. data/lib/ffaker/name_mx.rb +3 -3
  46. data/lib/ffaker/name_nb.rb +2 -2
  47. data/lib/ffaker/name_nl.rb +2 -2
  48. data/lib/ffaker/name_ru.rb +19 -18
  49. data/lib/ffaker/name_se.rb +2 -2
  50. data/lib/ffaker/name_sn.rb +2 -2
  51. data/lib/ffaker/nato_alphabet.rb +2 -2
  52. data/lib/ffaker/phone_number_cu.rb +133 -0
  53. data/lib/ffaker/phone_number_fr.rb +5 -5
  54. data/lib/ffaker/phone_number_it.rb +3 -3
  55. data/lib/ffaker/phone_number_nl.rb +6 -9
  56. data/lib/ffaker/phone_number_se.rb +12 -13
  57. data/lib/ffaker/product.rb +6 -6
  58. data/lib/ffaker/ssn_se.rb +2 -2
  59. data/lib/ffaker/string.rb +6 -6
  60. data/lib/ffaker/time.rb +2 -2
  61. data/lib/ffaker/unit.rb +13 -14
  62. data/lib/ffaker/unit_english.rb +35 -38
  63. data/lib/ffaker/unit_metric.rb +26 -30
  64. data/lib/ffaker/utils/array_utils.rb +1 -1
  65. data/lib/ffaker/vehicle.rb +7 -8
  66. data/test/test_address_ca.rb +4 -0
  67. data/test/test_identification_co.rb +7 -13
  68. data/test/test_lorem_kr.rb +47 -0
  69. data/test/test_name_cn.rb +9 -1
  70. data/test/test_phone_number_cu.rb +86 -0
  71. data/test/test_ssn_se.rb +6 -7
  72. metadata +13 -3
  73. data/lib/ffaker/course_fr.rb +0 -22
data/lib/ffaker/string.rb CHANGED
@@ -7,12 +7,12 @@ module Faker
7
7
 
8
8
  BACKSLASH = '\\'
9
9
 
10
- LOWERS = k(('a'..'z').to_a)
11
- UPPERS = k(('A'..'Z').to_a)
12
- LETTERS = k(LOWERS + UPPERS)
13
- NUMBERS = k(('0'..'9').to_a)
14
- WORD_CHARS = k(LETTERS + NUMBERS + ['_'])
15
- SPACES = k([" ", "\t"])
10
+ LOWERS = [*'a'..'z']
11
+ UPPERS = [*'A'..'Z']
12
+ LETTERS = LOWERS + UPPERS
13
+ NUMBERS = [*'0'..'9']
14
+ WORD_CHARS = LETTERS + NUMBERS + ['_']
15
+ SPACES = [" ", "\t"]
16
16
  ESCAPEABLE_CHARS = '\\', '/', '.', '(', ')', '[', ']', '{', '}'
17
17
 
18
18
  def from_regexp(exp)
data/lib/ffaker/time.rb CHANGED
@@ -5,6 +5,8 @@ module Faker
5
5
  extend ModuleUtils
6
6
  extend self
7
7
 
8
+ MONTHS = %w(January February March April May June July August September October November December)
9
+
8
10
  def month
9
11
  MONTHS.sample
10
12
  end
@@ -24,7 +26,5 @@ module Faker
24
26
  end
25
27
  date.strftime "%Y-%m-%d %T %z"
26
28
  end
27
-
28
- MONTHS = k %w(January February March April May June July August September October November December)
29
29
  end
30
30
  end
data/lib/ffaker/unit.rb CHANGED
@@ -7,6 +7,19 @@ module Faker
7
7
  extend ModuleUtils
8
8
  extend self
9
9
 
10
+ TIME_UNITS = [
11
+ {name: 'Years', abbreviation: 'yr'},
12
+ {name: 'Days', abbreviation: 'd'},
13
+ {name: 'Hours', abbreviation: 'Minutes'},
14
+ {name: 'Seconds', abbreviation: 's'},
15
+ {name: 'Milliseconds', abbreviation: 'msec'}
16
+ ]
17
+ TEMPERATURE_UNITS = [
18
+ {name: 'Kelvin', abbreviation: 'K'},
19
+ {name: 'Celsius', abbreviation: 'C'},
20
+ {name: 'Fahrenheit', abbreviation: 'F'}
21
+ ]
22
+
10
23
  def time_name
11
24
  time.name
12
25
  end
@@ -32,19 +45,5 @@ module Faker
32
45
  def temperature
33
46
  OpenStruct.new TEMPERATURE_UNITS.sample
34
47
  end
35
-
36
- TIME_UNITS = k [
37
- {:name => 'Years', :abbreviation => 'yr'},
38
- {:name => 'Days', :abbreviation => 'd'},
39
- {:name => 'Hours', :abbreviation => 'Minutes'},
40
- {:name => 'Seconds', :abbreviation => 's'},
41
- {:name => 'Milliseconds', :abbreviation => 'msec'}
42
- ]
43
-
44
- TEMPERATURE_UNITS = k [
45
- {:name => 'Kelvin', :abbreviation => 'K'},
46
- {:name => 'Celsius', :abbreviation => 'C'},
47
- {:name => 'Fahrenheit', :abbreviation => 'F'}
48
- ]
49
48
  end
50
49
  end
@@ -10,6 +10,41 @@ module Faker
10
10
  extend ModuleUtils
11
11
  extend self
12
12
 
13
+ LENGTH_UNITS = [
14
+ { name: "inch", abbreviation: "in"},
15
+ { name: "foot", abbreviation: "ft"},
16
+ { name: "yard", abbreviation: "yd"},
17
+ { name: "furlong", abbreviation: "fur"},
18
+ { name: "mile", abbreviation: "m"}
19
+ ]
20
+ MASS_UNITS = [
21
+ { name: "grains", abbreviation: "gr"},
22
+ { name: "ounces", abbreviation: "oz"},
23
+ { name: "pounds", abbreviation: "lb" },
24
+ { name: "hundredweight", abbreviation: "cwt"},
25
+ { name: "ton", abbreviation: "t" }
26
+ ]
27
+ LIQUID_UNITS = [
28
+ { name: "fluid ounce", abbreviation: "fl oz"},
29
+ { name: "gill", abbreviation: "gi"},
30
+ { name: "pint", abbreviation: "pt"},
31
+ { name: "quart", abbreviation: "qt"}
32
+ ]
33
+ VOLUME_UNITS = [
34
+ { name: "cubic inch", abbreviation: "CI"},
35
+ { name: "cubic foot", abbreviation: "CFT"},
36
+ { name: "cubic yard", abbreviation: "CY"}
37
+ ]
38
+ AREA_UNITS = [
39
+ { name: "square inch", abbreviation: "sq. in"},
40
+ { name: "square foot", abbreviation: "sq ft"},
41
+ { name: "square yard", abbreviation: "sq yd"},
42
+ { name: "acre", abbreviation: "ac"},
43
+ { name: "section", abbreviation: "s"},
44
+ { name: "square mile", abbreviation: "sq mi"},
45
+ { name: "township", abbreviation: "Twp"}
46
+ ]
47
+
13
48
  def mass_name
14
49
  mass.name
15
50
  end
@@ -72,43 +107,5 @@ module Faker
72
107
  OpenStruct.new AREA_UNITS.sample
73
108
  end
74
109
 
75
- LENGTH_UNITS = k [
76
- { :name =>"inch", :abbreviation => "in"},
77
- { :name =>"foot", :abbreviation => "ft"},
78
- { :name =>"yard", :abbreviation => "yd"},
79
- { :name =>"furlong", :abbreviation => "fur"},
80
- { :name =>"mile", :abbreviation => "m"}
81
- ]
82
-
83
- MASS_UNITS = k [
84
- { :name => "grains", :abbreviation => "gr"},
85
- { :name => "ounces", :abbreviation => "oz"},
86
- { :name => "pounds", :abbreviation => "lb" },
87
- { :name => "hundredweight", :abbreviation => "cwt"},
88
- { :name => "ton", :abbreviation => "t" }
89
- ]
90
-
91
- LIQUID_UNITS = k [
92
- { :name => "fluid ounce", :abbreviation => "fl oz"},
93
- { :name => "gill", :abbreviation => "gi"},
94
- { :name => "pint", :abbreviation => "pt"},
95
- { :name => "quart", :abbreviation => "qt"}
96
- ]
97
-
98
- VOLUME_UNITS = k [
99
- { :name =>"cubic inch", :abbreviation => "CI"},
100
- { :name =>"cubic foot", :abbreviation => "CFT"},
101
- { :name =>"cubic yard", :abbreviation => "CY"}
102
- ]
103
-
104
- AREA_UNITS = k [
105
- { :name =>"square inch", :abbreviation => "sq. in"},
106
- { :name =>"square foot", :abbreviation => "sq ft"},
107
- { :name =>"square yard", :abbreviation => "sq yd"},
108
- { :name =>"acre", :abbreviation => "ac"},
109
- { :name =>"section", :abbreviation => "s"},
110
- { :name =>"square mile", :abbreviation => "sq mi"},
111
- { :name =>"township", :abbreviation => "Twp"}
112
- ]
113
110
  end
114
111
  end
@@ -10,6 +10,32 @@ module Faker
10
10
  extend ModuleUtils
11
11
  extend self
12
12
 
13
+ LENGTH_UNITS = [
14
+ { name: "millimeters", abbreviation: "mm"},
15
+ { name: "centimeters", abbreviation: "cm"},
16
+ { name: "meters", abbreviation: "m"},
17
+ { name: "kilometers", abbreviation: "km"}
18
+ ]
19
+ MASS_UNITS = [
20
+ { name: "gram", abbreviation: "g"},
21
+ { name: "kilogram", abbreviation: "kg" },
22
+ { name: "metric ton", abbreviation: "mt"}
23
+ ]
24
+ LIQUID_UNITS = [
25
+ { name: "milliliters", abbreviation: "ml"},
26
+ { name: "liters", abbreviation: "L"}
27
+ ]
28
+ VOLUME_UNITS = [
29
+ { name: " cubic centimeters", abbreviation: "cm^3"},
30
+ { name: "cubic meters", abbreviation: "m^3"}
31
+ ]
32
+ AREA_UNITS = [
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
+ ]
38
+
13
39
  def mass_name
14
40
  mass.name
15
41
  end
@@ -71,35 +97,5 @@ module Faker
71
97
  def area
72
98
  OpenStruct.new AREA_UNITS.sample
73
99
  end
74
-
75
- LENGTH_UNITS = k [
76
- { :name =>"millimeters", :abbreviation => "mm"},
77
- { :name =>"centimeters", :abbreviation => "cm"},
78
- { :name =>"meters", :abbreviation => "m"},
79
- { :name =>"kilometers", :abbreviation => "km"}
80
- ]
81
-
82
- MASS_UNITS = k [
83
- { :name => "gram", :abbreviation => "g"},
84
- { :name => "kilogram", :abbreviation => "kg" },
85
- { :name => "metric ton", :abbreviation => "mt"}
86
- ]
87
-
88
- LIQUID_UNITS = k [
89
- { :name => "milliliters", :abbreviation => "ml"},
90
- { :name => "liters", :abbreviation => "L"}
91
- ]
92
-
93
- VOLUME_UNITS = k [
94
- { :name => " cubic centimeters", :abbreviation => "cm^3"},
95
- { :name => "cubic meters", :abbreviation => "m^3"}
96
- ]
97
-
98
- AREA_UNITS = k [
99
- { :name => "centimeters squared", :abbreviation => "cm^2"},
100
- { :name => "meters squared", :abbreviation => "m^2"},
101
- { :name => "hectares", :abbreviation => "ha"},
102
- { :name => "kilometers", :abbreviation => "km" }
103
- ]
104
100
  end
105
101
  end
@@ -17,7 +17,7 @@ module Faker
17
17
  end
18
18
 
19
19
  def self.freeze_all(array)
20
- array.each { |e| e.freeze }
20
+ array.each(&:freeze)
21
21
  array.freeze
22
22
  array
23
23
  end
@@ -5,6 +5,13 @@ module Faker
5
5
  extend ModuleUtils
6
6
  extend self
7
7
 
8
+ DRIVETRAINS = %w(4WD 4X4 AWD FWD RWD)
9
+ YEARS = [*'1900'.."#{Date.today.year+1}"]
10
+ COLOR_PREFIXES = k(%w(
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
+
8
15
  def base_color
9
16
  Faker::Color.name
10
17
  end
@@ -38,13 +45,5 @@ module Faker
38
45
  def year
39
46
  YEARS.sample
40
47
  end
41
-
42
- DRIVETRAINS = k(%w(4WD 4X4 AWD FWD RWD))
43
- YEARS = k('1900'.."#{Date.today.year+1}")
44
- COLOR_PREFIXES = k(%w(
45
- beautiful bright calm dangerous dark dull fast magnetic magnificent majestic melodic metallic
46
- mundane mute mysterious new pleasant pretty resonant royal slate soft tranquil vibrant weak
47
- ))
48
-
49
48
  end
50
49
  end
@@ -11,6 +11,10 @@ class TestAddressCA < Test::Unit::TestCase
11
11
  assert_match /[A-Z][A-Z]/, Faker::AddressCA.province_abbr
12
12
  end
13
13
 
14
+ def test_city
15
+ assert Faker::AddressCA::CITY.include?(Faker::AddressCA.city)
16
+ end
17
+
14
18
  def test_postal_code
15
19
  assert_match /[A-Z]\d[A-Z]\W\d[A-Z]\d/, Faker::AddressCA.postal_code
16
20
  end
@@ -7,32 +7,26 @@ class TestFakerIdentificationESCO < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_drivers_license
10
- # pattern \d{6,14}
11
- assert_match /\d{6,14}/, @tester.drivers_license
12
- assert @tester.drivers_license.length.between?(6,14)
10
+ assert_match(/\A\d{6,14}\z/, @tester.drivers_license)
13
11
  end
14
12
 
15
13
  def test_id
16
- assert @tester.method_defined? :id
14
+ assert @tester.method_defined?(:id)
17
15
  end
18
16
 
19
17
  def test_gender
20
- assert_match /(Hombre|Mujer)/, @tester.gender
18
+ assert_match(/\A(Hombre|Mujer)\z/, @tester.gender)
21
19
  end
22
20
 
23
21
  def test_category
24
- assert_match /^([a][1-2]|[bc][1-3])$/i, @tester.driver_license_category
22
+ assert_match(/\A([a][1-2]|[bc][1-3])\z/i, @tester.driver_license_category)
25
23
  end
26
24
 
27
25
  def test_blood_type
28
- assert_match /^(a|b|o|ab)[\+|\-]$/i, @tester.blood_type
26
+ assert_match(/\A(a|b|o|ab)[+-]\z/i, @tester.blood_type)
29
27
  end
30
28
 
31
29
  def test_expedition_date
32
- test_today = Date.today
33
- # 1 today is bigger than result
34
- # 0 today is the same day as result
35
- # -1 today is smaller than expected
36
- assert_equal(1, test_today <=> @tester.expedition_date)
30
+ assert(Date.today >= @tester.expedition_date)
37
31
  end
38
- end
32
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ class TestLoremKR < Test::Unit::TestCase
6
+ KOREAN_SENTENCE_MATCHER = /\A[ .가-힣]+\z/
7
+ KOREAN_WORDS_MATCHER = /\A[ 가-힣]+\z/
8
+ KOREAN_WORD_MATCHER = /\A[가-힣]+\z/
9
+ def setup
10
+ @tester = Faker::LoremKR
11
+ end
12
+
13
+ def test_paragraph
14
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.paragraph
15
+ end
16
+
17
+ def test_sentence
18
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.sentence
19
+ assert_nothing_thrown do
20
+ 100.times { Faker::Lorem.sentence 0 }
21
+ end
22
+ end
23
+
24
+ def test_phrase
25
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.phrase
26
+ end
27
+
28
+ def test_paragraphs
29
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.paragraphs.join(" ")
30
+ end
31
+
32
+ def test_sentences
33
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.sentences.join(" ")
34
+ end
35
+
36
+ def test_phrases
37
+ assert_match KOREAN_SENTENCE_MATCHER, @tester.phrases.join(" ")
38
+ end
39
+
40
+ def test_words
41
+ assert_match KOREAN_WORDS_MATCHER, @tester.words.join(" ")
42
+ end
43
+
44
+ def test_word
45
+ assert_match KOREAN_WORD_MATCHER, @tester.word
46
+ end
47
+ end
data/test/test_name_cn.rb CHANGED
@@ -8,6 +8,14 @@ class TestFakerNameCN < Test::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_name
11
- assert Faker::NameCN.name.length > 2
11
+ assert_match(/\A.{2,}\z/, @tester.name)
12
+ end
13
+
14
+ def test_first_name
15
+ assert_match(/\A.{1,2}\z/, @tester.first_name)
16
+ end
17
+
18
+ def test_last_name
19
+ assert_match(/\A.{1,5}\z/, @tester.last_name)
12
20
  end
13
21
  end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ # Author: Luilver<luilver@gmail.com>
6
+ class TestPhoneNumberCU < Test::Unit::TestCase
7
+ def setup
8
+ @tester = Faker::PhoneNumberCU
9
+ end
10
+
11
+ # Prefix format test
12
+ #
13
+ def test_mobile_phone_prefix
14
+ assert Faker::PhoneNumberCU::MobileOperatorsPrefix.include?(
15
+ @tester.mobile_phone_prefix)
16
+ end
17
+
18
+ def test_home_work_phone_prefix
19
+ assert Faker::PhoneNumberCU::HomeWorkOperatorsPrefix.include?(
20
+ @tester.home_work_phone_prefix)
21
+ end
22
+
23
+ def test_phone_prefix
24
+ 10.times do
25
+ assert Faker::PhoneNumberCU::OperatorsPrefix.include?(
26
+ @tester.phone_prefix)
27
+ end
28
+ end
29
+
30
+ # General format test
31
+ #
32
+ def test_mobile_phone_number
33
+ assert_match /05 \d{3} \d{4}/,
34
+ Faker::PhoneNumberCU.mobile_phone_number
35
+ end
36
+
37
+ def test_home_work_phone_number
38
+ assert_match /\(0(7\) \d{3}|\d{2}\) \d{2}) \d{4}/,
39
+ Faker::PhoneNumberCU.home_work_phone_number
40
+ end
41
+
42
+ def test_general_phone_number
43
+ 10.times do
44
+ assert_match /((05|\(07\)) \d{3}|\(0\d{2}\) \d{2}) \d{4}/,
45
+ Faker::PhoneNumberCU.general_phone_number
46
+ end
47
+ end
48
+
49
+ # International format tests
50
+ #
51
+ def test_international_mobile_phone_number
52
+ assert_match /(00|\+)535 \d{3} \d{4}/,
53
+ Faker::PhoneNumberCU.international_mobile_phone_number
54
+ end
55
+
56
+ def test_international_home_work_phone_number
57
+ assert_match /(00|\+)53(7 \d{3}|\d{2} \d{2}) \d{4}/,
58
+ Faker::PhoneNumberCU.international_home_work_phone_number
59
+ end
60
+
61
+ def test_international_phone_number
62
+ 10.times do
63
+ assert_match /(00|\+)53((5|7) \d{3}|\d{2} \d{2}) \d{4}/,
64
+ Faker::PhoneNumberCU.international_phone_number
65
+ end
66
+ end
67
+
68
+ # E.164 format tests
69
+ #
70
+ def test_e164_mobile_phone_number
71
+ assert_match /535\d{7}/,
72
+ Faker::PhoneNumberCU.e164_mobile_phone_number
73
+ end
74
+
75
+ def test_e164_home_work_phone_number
76
+ assert_match /53(7\d{7}|\d{2}\d{6})/,
77
+ Faker::PhoneNumberCU.e164_home_work_phone_number
78
+ end
79
+
80
+ def test_e164_phone_number
81
+ 10.times do
82
+ assert_match /53((5|7)\d{7}|\d{2}\d{6})/,
83
+ Faker::PhoneNumberCU.e164_phone_number
84
+ end
85
+ end
86
+ end