phone 1.2.3 → 1.3.0.beta0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.document +3 -0
  3. data/.gitignore +5 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +14 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.md +50 -0
  8. data/Gemfile +11 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +183 -0
  11. data/Rakefile +38 -0
  12. data/data/{phone_countries.yml → phone/countries.yml} +16 -14
  13. data/lib/phone.rb +75 -53
  14. data/lib/phone/country.rb +45 -0
  15. data/lib/{errors.rb → phone/errors.rb} +0 -0
  16. data/lib/phone/version.rb +4 -0
  17. data/phone.gemspec +25 -0
  18. data/test/countries/au_test.rb +11 -11
  19. data/test/countries/ba_test.rb +4 -4
  20. data/test/countries/be_test.rb +12 -11
  21. data/test/countries/de_test.rb +7 -7
  22. data/test/countries/es_test.rb +33 -0
  23. data/test/countries/fr_test.rb +5 -5
  24. data/test/countries/gb_test.rb +42 -41
  25. data/test/countries/hr_test.rb +14 -14
  26. data/test/countries/hu_test.rb +5 -5
  27. data/test/countries/ie_test.rb +20 -0
  28. data/test/countries/nl_test.rb +43 -43
  29. data/test/countries/nz_test.rb +8 -0
  30. data/test/countries/pt_test.rb +18 -18
  31. data/test/countries/rs_test.rb +7 -7
  32. data/test/countries/se_test.rb +44 -43
  33. data/test/countries/si_test.rb +7 -7
  34. data/test/countries/ua_test.rb +4 -4
  35. data/test/countries/us_test.rb +6 -6
  36. data/test/countries/uy_test.rb +22 -0
  37. data/test/countries/za_test.rb +4 -4
  38. data/test/extension_test.rb +3 -3
  39. data/test/helper.rb +41 -0
  40. data/test/phone_test.rb +99 -53
  41. data/test_usa_phones_with_extensions.csv +99 -0
  42. metadata +112 -30
  43. data/LICENSE +0 -19
  44. data/Readme.rdoc +0 -126
  45. data/lib/country.rb +0 -36
  46. data/lib/support.rb +0 -78
  47. data/test/test_helper.rb +0 -15
@@ -1,16 +1,16 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
1
+ require "helper"
2
2
 
3
3
  ## United States
4
- class USTest < Test::Unit::TestCase
5
-
4
+ class USTest < Minitest::Test
5
+
6
6
  def test_local
7
7
  parse_test('+1 555 123 4567', '1', '555', '1234567')
8
8
  end
9
-
9
+
10
10
  def test_tollfree
11
11
  parse_test('+1 800 555 3456', '1', '800', '5553456')
12
12
  end
13
-
13
+
14
14
  def test_long_with_default_country_code
15
15
  Phoner::Phone.default_country_code = '1'
16
16
  parse_test('2069735100', '1', '206', '9735100')
@@ -20,5 +20,5 @@ class USTest < Test::Unit::TestCase
20
20
  Phoner::Phone.default_country_code = '1'
21
21
  Phoner::Phone.default_area_code = '206'
22
22
  parse_test('9735100', '1', '206', '9735100')
23
- end
23
+ end
24
24
  end
@@ -0,0 +1,22 @@
1
+ require "helper"
2
+
3
+ ## Uruguay
4
+ # source: http://en.wikipedia.org/wiki/Telephone_numbers_in_Uruguay
5
+ class UYTest < Minitest::Test
6
+
7
+ # 02 Montevideo
8
+ def test_montevideo
9
+ parse_test('+598 2 1234567', '598', '2', '1234567')
10
+ end
11
+
12
+ # 042 Maldonado
13
+ def test_maldonado
14
+ parse_test('+598 42 123456', '598', '42', '123456')
15
+ end
16
+
17
+ # 09 Mobile phones
18
+ def test_mobile_phones
19
+ parse_test('+598 99 570110', '598', '99', '570110')
20
+ end
21
+
22
+ end
@@ -1,8 +1,8 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
1
+ require "helper"
2
2
 
3
3
  ## South Africa
4
- class ZATest < Test::Unit::TestCase
5
-
4
+ class ZATest < Minitest::Test
5
+
6
6
  def test_local
7
7
  # Telkom
8
8
  parse_test('+27 11 555 5555', '27', '11', '5555555')
@@ -17,5 +17,5 @@ class ZATest < Test::Unit::TestCase
17
17
  # Telkom
18
18
  parse_test('+27 800 123 321', '27', '800', '123321')
19
19
  end
20
-
20
+
21
21
  end
@@ -1,11 +1,11 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
1
+ require "helper"
2
2
 
3
- class ExtensionTest < Test::Unit::TestCase
3
+ class ExtensionTest < Minitest::Test
4
4
 
5
5
  def test_parse_usa_long_with_simple_extension
6
6
  pn = Phoner::Phone.parse "+1 2069735100 x143"
7
7
 
8
- assert_not_nil pn, %Q{parse should pass}
8
+ refute_nil pn, %Q{parse should pass}
9
9
  assert_equal '9735100', pn.number
10
10
  assert_equal '206', pn.area_code
11
11
  assert_equal '1', pn.country_code
@@ -0,0 +1,41 @@
1
+ require "rubygems"
2
+
3
+ begin
4
+ require "bundler"
5
+ rescue LoadError => e
6
+ STDERR.puts e.message
7
+ STDERR.puts "Run `gem install bundler` to install Bundler."
8
+ exit e.status_code
9
+ end
10
+
11
+ begin
12
+ Bundler.setup(:default, :development, :test)
13
+ rescue Bundler::BundlerError => e
14
+ STDERR.puts e.message
15
+ STDERR.puts "Run `bundle install` to install missing gems."
16
+ exit e.status_code
17
+ end
18
+
19
+ require "phone"
20
+ require "minitest/autorun"
21
+
22
+ class Minitest::Test
23
+ def setup
24
+ Phoner::Phone.default_country_code = nil
25
+ Phoner::Phone.default_area_code = nil
26
+ end
27
+
28
+ def teardown
29
+ Phoner::Phone.default_country_code = nil
30
+ Phoner::Phone.default_area_code = nil
31
+ end
32
+ end
33
+
34
+ def parse_test(raw, country_code, area_code, number)
35
+ pn = Phoner::Phone.parse(raw)
36
+
37
+ refute_nil pn, %Q{parse should pass}
38
+ assert_equal country_code, pn.country_code
39
+ assert_equal area_code, pn.area_code
40
+ assert_equal number, pn.number
41
+ end
@@ -1,119 +1,166 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
1
+ require "helper"
2
2
 
3
- class PhoneTest < Test::Unit::TestCase
4
-
5
- def test_number_without_country_code_initialize
3
+ class PhoneTest < Minitest::Test
4
+
5
+ def test_with_nil_number_initialize
6
+ assert_raises Phoner::BlankNumberError do
7
+ pn = Phoner::Phone.new nil
8
+ end
9
+ end
10
+
11
+ def test_with_empty_number_initialize
12
+ assert_raises Phoner::BlankNumberError do
13
+ pn = Phoner::Phone.new ""
14
+ end
15
+ end
16
+
17
+ def test_number_without_country_code_initialize
6
18
  Phoner::Phone.default_country_code = nil
7
19
 
8
- assert_raise Phoner::CountryCodeError do
20
+ assert_raises Phoner::CountryCodeError do
9
21
  pn = Phoner::Phone.new '5125486', '91'
10
22
  end
11
23
  end
12
-
13
- def test_number_without_country_and_area_code_initialize
24
+
25
+ def test_number_without_country_and_area_code_initialize
14
26
  Phoner::Phone.default_country_code = nil
15
27
  Phoner::Phone.default_area_code = nil
16
28
 
17
- assert_raise Phoner::AreaCodeError do
29
+ assert_raises Phoner::AreaCodeError do
18
30
  pn = Phoner::Phone.new '451588'
19
31
  end
20
- end
21
-
22
- def test_number_with_default_area_code_initialize
32
+ end
33
+
34
+ def test_number_with_default_area_code_initialize
23
35
  Phoner::Phone.default_country_code = '385'
24
- Phoner::Phone.default_area_code = '47'
25
-
36
+ Phoner::Phone.default_area_code = '47'
37
+
26
38
  pn = Phoner::Phone.new '451588'
27
39
  assert pn.number == '451588'
28
- assert pn.area_code == '47'
29
- assert pn.country_code == '385'
30
- end
31
-
40
+ assert pn.area_code == '47'
41
+ assert pn.country_code == '385'
42
+ end
43
+
32
44
  def test_number_with_default_country_code_initialize
33
45
  Phoner::Phone.default_country_code = '386'
34
-
46
+
35
47
  pn = Phoner::Phone.new '5125486', '91'
36
48
  assert pn.number == '5125486'
37
- assert pn.area_code == '91'
38
- assert pn.country_code == '386'
39
- end
40
-
49
+ assert pn.area_code == '91'
50
+ assert pn.country_code == '386'
51
+ end
52
+
41
53
  def test_number_with_country_code_initialize
42
54
  Phoner::Phone.default_country_code = '387'
43
-
55
+
44
56
  pn = Phoner::Phone.new '5125486', '91', '385'
45
57
  assert pn.number == '5125486'
46
58
  assert pn.area_code == '91'
47
59
  assert pn.country_code == '385'
48
- end
49
-
60
+ end
61
+
50
62
  def test_parse_empty
51
63
  assert_equal Phoner::Phone.parse(''), nil
52
64
  assert_equal Phoner::Phone.parse(nil), nil
53
65
  end
54
-
66
+
67
+ def test_parse_with_special_characters_with_country
68
+ pn = Phoner::Phone.parse "+1 545-545-5454"
69
+ assert "1", pn.country_code
70
+ assert "545", pn.area_code
71
+ assert "5455454", pn.number
72
+ end
73
+
74
+ def test_parse_with_extension
75
+ pn = Phoner::Phone.parse"+1 545-545-5454 ext. 4307"
76
+ assert "1", pn.country_code
77
+ assert "545", pn.area_code
78
+ assert "5455454", pn.number
79
+ assert "4307", pn.extension
80
+ end
81
+
55
82
  def test_parse_short_without_special_characters_without_country
56
83
  Phoner::Phone.default_country_code = nil
57
84
 
58
- assert_raise Phoner::CountryCodeError do
85
+ assert_raises Phoner::CountryCodeError do
59
86
  pn = Phoner::Phone.parse "0915125486"
60
87
  end
61
- end
62
-
88
+ end
89
+
63
90
  def test_parse_short_with_special_characters_without_country
64
91
  Phoner::Phone.default_country_code = nil
65
92
 
66
- assert_raise Phoner::CountryCodeError do
93
+ assert_raises Phoner::CountryCodeError do
67
94
  pn = Phoner::Phone.parse "091/512-5486"
68
95
  end
69
96
  end
70
-
97
+
71
98
  def test_to_s
72
- Phoner::Phone.default_country_code = nil
99
+ Phoner::Phone.default_country_code = nil
73
100
  pn = Phoner::Phone.new '5125486', '91', '385'
74
101
  assert pn.to_s == '+385915125486'
75
- end
76
-
102
+ end
103
+
77
104
  def test_to_s_without_country_code
78
- Phoner::Phone.default_country_code = '385'
105
+ Phoner::Phone.default_country_code = '385'
79
106
  pn = Phoner::Phone.new '5125486', '91'
80
107
  assert pn.format("0%a%n") == '0915125486'
81
108
  end
82
-
109
+
83
110
  def test_format_special_with_country_code
84
- Phoner::Phone.default_country_code = nil
111
+ Phoner::Phone.default_country_code = nil
85
112
  pn = Phoner::Phone.new '5125486', '91', '385'
86
113
  assert pn.format("+ %c (%a) %n") == '+ 385 (91) 5125486'
87
- end
88
-
114
+ end
115
+
89
116
  def test_format_special_without_country_code
90
- Phoner::Phone.default_country_code = '385'
117
+ Phoner::Phone.default_country_code = '385'
91
118
  pn = Phoner::Phone.new '5125486', '91'
92
119
  assert_equal pn.format("%A/%f-%l"), '091/512-5486'
93
- end
94
-
120
+ end
121
+
95
122
  def test_format_with_symbol_specifier
96
- Phoner::Phone.default_country_code = nil
123
+ Phoner::Phone.default_country_code = nil
97
124
  pn = Phoner::Phone.new '5125486', '91', '385'
98
125
  assert_equal pn.format(:europe), '+385 (0) 91 512 5486'
99
- end
100
-
126
+ end
127
+
128
+ def test_validity
129
+ assert true, Phoner::Phone.valid?("+17788827175")
130
+ end
131
+
132
+ def test_successful_validity_wont_alter_parameter
133
+ number = "+17755551212"
134
+ Phoner::Phone.valid?(number)
135
+ assert_equal "+17755551212", number
136
+ end
137
+
138
+ def test_failing_validity_wont_alter_parameter
139
+ number = "ABC123"
140
+ Phoner::Phone.valid?(number)
141
+ assert_equal "ABC123", number
142
+ end
143
+
144
+ def test_validity_with_country_code
145
+ assert true, Phoner::Phone.valid?("7788827175", :country_code => "1")
146
+ end
147
+
101
148
  def test_doesnt_validate
102
149
  assert_equal Phoner::Phone.valid?('asdas'), false
103
150
  assert_equal Phoner::Phone.valid?('385915125486'), false
104
151
  end
105
-
152
+
106
153
  def test_comparison_true
107
- pn1 = Phoner::Phone.new '5125486', '91', '385'
108
- pn2 = Phoner::Phone.new '5125486', '91', '385'
154
+ pn1 = Phoner::Phone.new '5125486', '91', '385'
155
+ pn2 = Phoner::Phone.new '5125486', '91', '385'
109
156
  assert pn1 == pn2
110
157
  end
111
-
158
+
112
159
  def test_comparison_false
113
- pn1 = Phoner::Phone.new '5125486', '91', '385'
114
- pn2 = Phoner::Phone.new '1234567', '91', '385'
160
+ pn1 = Phoner::Phone.new '5125486', '91', '385'
161
+ pn2 = Phoner::Phone.new '1234567', '91', '385'
115
162
  assert pn1 != pn2
116
- end
163
+ end
117
164
 
118
165
  def test_find_by_country_isocode
119
166
  Phoner::Country.load
@@ -121,5 +168,4 @@ class PhoneTest < Test::Unit::TestCase
121
168
  assert_equal Phoner::Country.find_by_country_isocode('xx'), nil
122
169
  assert_equal Phoner::Country.find_by_country_isocode('bla'), nil
123
170
  end
124
-
125
171
  end
@@ -0,0 +1,99 @@
1
+ 601-867-5000 ext 75292
2
+ (334)821-2223 Ext. 107
3
+ (863) 983-6171 ext: 0055
4
+ 601-987-3995 ext 10
5
+ (512) 473-3200Ext2396
6
+ (727) 558-5010 ext: 0112
7
+ (904) 360-5611 ext: 5611
8
+ (937) 255-7204Ext337
9
+ 228-374-5022 ext 5386
10
+ (205)987-3500 Ext. 205-32
11
+ (607) 273-8588x402
12
+ (205)328-3330 Ext. 802-59
13
+ (407) 251-2452 ext: 0146
14
+ 502-564-8110 xt 312
15
+ (828) 698-3923x13
16
+ (608)836-7433 Ext. 5147
17
+ (1-808)935-3222 Ext. 2#
18
+ (770)420-3179 Ext. x 179
19
+ (415) 558-8669x218
20
+ (205)879-6330 Ext. 731-50
21
+ (205)987-5995 Ext. 802-58
22
+ (609) 924-2200Ext10
23
+ (312) 440-4373x12
24
+ (978) 369-9602x457
25
+ 1-602-264-1774 # 135
26
+ 502-564-8890 x4340
27
+ 502-564-5550 x4569
28
+ (480)437-2600 Ext. VM123
29
+ (850) 245-4131 ext: 3506
30
+ 601-354-6161 ext 103
31
+ (414)778-5400 Ext. 127
32
+ (262)338-4475 Ext. #16
33
+ (602) 264-1774 extention # 135
34
+ (314) 361-3221x107
35
+ (800) 255-5747x46
36
+ 410-514-7336 TDDTTY + Voice
37
+ (617) 695-2300x393
38
+ 1-334-386-8800 Ext. 107
39
+ (928)634-9536 Ext. 143
40
+ 502-573-1555 x266
41
+ (978) 927-8000x246
42
+ (920) 887-4600Ext340
43
+ 502-564-1404 x4536
44
+ (850) 245-6774 ext: 4774
45
+ (718) 852-3000 Ext 269
46
+ 228-374-5022 ext 5022
47
+ 502-564-0105 x10260
48
+ (850) 000-0000 ext: 00000000
49
+ (979) 233-1616x306
50
+ (207) 333-3267x224
51
+ (561) 625-5122 ext: 687
52
+ (386) 961-7414 ext: 7414
53
+ (262)549-2249 Ext. 104
54
+ (205)322-7500 Ext. BECKYS
55
+ (303)858-8100 Ext. n.a.
56
+ (937) 255-7204x337
57
+ 601-944-4830 ext 104
58
+ 228-432-1056 ext 104
59
+ (209) 586-1495Ext104
60
+ 502-564-8139 : 4645
61
+ (602) 264-1774 ext is 135
62
+ (602) 264-1774Ext135
63
+ 502-564-7822 x4212
64
+ (609) 921-8808Ext3
65
+ (703) 739-7900x222
66
+ (609) 758-2241x144
67
+ (970)223-6500 Ext. X6510
68
+ (734) 485-2000Ext255
69
+ (904) 620-4424 ext: 8614424
70
+ (904) 827-2520 ext: 2520
71
+ (978) 774-1050x251
72
+ (541) 343-0123x2269
73
+ (608)277-2752 Ext. 2752
74
+ (203) 869-6786x335
75
+ 502-564-5981 x272
76
+ 606-878-5908 x6085
77
+ 502-564-2257 x3464
78
+ (205)871-1911 Ext. (205)
79
+ 502-564-7770 x3965
80
+ (608)374-2130 Ext. 28
81
+ (850) 410-9660 ext: 9240
82
+ 601-987-6837 ext 102
83
+ (414)529-1101 Ext. 153
84
+ (209) 586-1495x104
85
+ (520)408-1885 Ext. # 227
86
+ 601-605-5388 ext 100
87
+ (352) 375-8484 ext: 0174
88
+ 15025645981x225
89
+ (602) 264-1774 X 135
90
+ (205)803-1499 Ext. 414-03
91
+ (651) 459-4121x203
92
+ +61 3 9811 2400
93
+ (262)681-2020 Ext. 6682
94
+ 601-944-4845 ext 118
95
+ 384-1100 VOICE MAIL:3004
96
+ (205)251-1267 Ext. 802-09
97
+ (410) 280-2038Ext11
98
+ 502-564-3170 x190
99
+ 15025646734x4420