phone 0.9.9.1 → 0.9.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.rdoc +27 -8
- data/data/phone_countries.yml +11 -12
- data/lib/phone.rb +49 -13
- data/lib/phone_country.rb +0 -2
- data/lib/support.rb +78 -0
- data/test/countries/au_test.rb +49 -0
- data/test/countries/ba_test.rb +10 -0
- data/test/countries/be_test.rb +116 -0
- data/test/countries/de_test.rb +14 -0
- data/test/countries/fr_test.rb +18 -0
- data/test/countries/gb_test.rb +196 -0
- data/test/countries/hr_test.rb +76 -0
- data/test/countries/hu_test.rb +10 -0
- data/test/countries/nl_test.rb +383 -0
- data/test/countries/rs_test.rb +17 -0
- data/test/countries/se_test.rb +478 -0
- data/test/countries/si_test.rb +21 -0
- data/test/countries/ua_test.rb +18 -0
- data/test/countries/us_test.rb +24 -0
- data/test/countries/za_test.rb +21 -0
- data/test/extension_test.rb +25 -0
- data/test/phone_test.rb +1 -102
- data/test/test_helper.rb +9 -0
- metadata +55 -18
- data/test/phone_country_test.rb +0 -124
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## Slovenia
|
4
|
+
class SITest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
#Maribor
|
8
|
+
parse_test('+ 386 2 23 46 611', '386', '2', '2346611')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_local_2
|
12
|
+
# Koper
|
13
|
+
parse_test('+ 386 5 23 46 611', '386', '5', '2346611')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_mobile
|
17
|
+
# Mobitel
|
18
|
+
parse_test('+386 51 258999', '386', '51', '258999')
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## Ukraine
|
4
|
+
class UATest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
parse_test('+380 57 711 22 33', '380', '57', '7112233')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mobile
|
11
|
+
parse_test('+380-50-111-22-33', '380', '50', '1112233')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_mobile2
|
15
|
+
parse_test('+380-66-042-22-01', '380', '66', '0422201')
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## United States
|
4
|
+
class USTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
parse_test('+1 555 123 4567', '1', '555', '1234567')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_tollfree
|
11
|
+
parse_test('+1 800 555 3456', '1', '800', '5553456')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_long_with_default_country_code
|
15
|
+
Phone.default_country_code = '1'
|
16
|
+
parse_test('2069735100', '1', '206', '9735100')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_short_with_default_country_code_and_area_code
|
20
|
+
Phone.default_country_code = '1'
|
21
|
+
Phone.default_area_code = '206'
|
22
|
+
parse_test('9735100', '1', '206', '9735100')
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## South Africa
|
4
|
+
class ZATest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
# Telkom
|
8
|
+
parse_test('+27 11 555 5555', '27', '11', '5555555')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_mobile
|
12
|
+
# Vodacom
|
13
|
+
parse_test('+27 82 555 5555', '27', '82', '5555555')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_tollfree
|
17
|
+
# Telkom
|
18
|
+
parse_test('+27 800 123 321', '27', '800', '123321')
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class ExtensionTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse_usa_long_with_simple_extension
|
6
|
+
pn = Phone.parse "+1 2069735100 x143"
|
7
|
+
|
8
|
+
assert_not_nil pn, %Q{parse should pass}
|
9
|
+
assert_equal '9735100', pn.number
|
10
|
+
assert_equal '206', pn.area_code
|
11
|
+
assert_equal '1', pn.country_code
|
12
|
+
assert_equal '143', pn.extension
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_to_s_with_extension
|
16
|
+
pn = Phone.new '5125486', '91', '385', '143'
|
17
|
+
assert_equal '+385915125486x143', pn.format(:default_with_extension)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_format_with_extension
|
21
|
+
pn = Phone.new '5125486', '91', '385', '143'
|
22
|
+
assert_equal '(091)/512-5486 x 143', pn.format('(%A)/%f-%l x %x')
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/phone_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
2
|
|
3
3
|
class PhoneTest < Test::Unit::TestCase
|
4
4
|
|
@@ -52,46 +52,6 @@ class PhoneTest < Test::Unit::TestCase
|
|
52
52
|
assert_equal Phone.parse(nil), nil
|
53
53
|
end
|
54
54
|
|
55
|
-
def test_parse_long_without_special_characters
|
56
|
-
pn = Phone.parse "+385915125486"
|
57
|
-
|
58
|
-
assert_equal pn.number, '5125486'
|
59
|
-
assert_equal pn.area_code, '91'
|
60
|
-
assert_equal pn.country_code, '385'
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_parse_zagreb_long_without_special_characters
|
64
|
-
pn = Phone.parse "+38513668734"
|
65
|
-
|
66
|
-
assert_equal pn.number, '3668734'
|
67
|
-
assert_equal pn.area_code, '1'
|
68
|
-
assert_equal pn.country_code, '385'
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_parse_long_with_special_characters
|
72
|
-
pn = Phone.parse "+ 385 (91) 512 / 5486 "
|
73
|
-
|
74
|
-
assert pn.number == '5125486'
|
75
|
-
assert pn.area_code == '91'
|
76
|
-
assert pn.country_code == '385'
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_parse_long_with_leading_zeros
|
80
|
-
pn = Phone.parse "00385915125486"
|
81
|
-
|
82
|
-
assert pn.number == '5125486'
|
83
|
-
assert pn.area_code == '91'
|
84
|
-
assert pn.country_code == '385'
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_parse_zagreb_long_with_leading_zeros
|
88
|
-
pn = Phone.parse "0038513668734"
|
89
|
-
|
90
|
-
assert pn.number == '3668734'
|
91
|
-
assert pn.area_code == '1'
|
92
|
-
assert pn.country_code == '385'
|
93
|
-
end
|
94
|
-
|
95
55
|
def test_parse_short_without_special_characters_without_country
|
96
56
|
Phone.default_country_code = nil
|
97
57
|
|
@@ -100,45 +60,14 @@ class PhoneTest < Test::Unit::TestCase
|
|
100
60
|
end
|
101
61
|
end
|
102
62
|
|
103
|
-
def test_parse_short_without_special_characters_with_country
|
104
|
-
Phone.default_country_code = '385'
|
105
|
-
|
106
|
-
pn = Phone.parse "044885047"
|
107
|
-
|
108
|
-
assert_equal pn.number, '885047'
|
109
|
-
assert_equal pn.area_code, '44'
|
110
|
-
assert pn.country_code == '385'
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_parse_zagreb_short_without_special_characters_with_country
|
114
|
-
Phone.default_country_code = '385'
|
115
|
-
|
116
|
-
pn = Phone.parse "013668734"
|
117
|
-
|
118
|
-
assert_equal pn.number, '3668734'
|
119
|
-
assert_equal pn.area_code, '1'
|
120
|
-
assert_equal pn.country_code, '385'
|
121
|
-
end
|
122
|
-
|
123
63
|
def test_parse_short_with_special_characters_without_country
|
124
64
|
Phone.default_country_code = nil
|
125
65
|
|
126
66
|
assert_raise RuntimeError do
|
127
67
|
pn = Phone.parse "091/512-5486"
|
128
68
|
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_parse_long_with_zero_in_brackets
|
132
|
-
Phone.default_country_code = nil
|
133
|
-
|
134
|
-
pn = Phone.parse '+385 (0)1 366 8111'
|
135
|
-
assert_equal pn.country_code, '385'
|
136
|
-
assert_equal pn.area_code, '1'
|
137
|
-
assert_equal pn.number, '3668111'
|
138
69
|
end
|
139
70
|
|
140
|
-
|
141
|
-
|
142
71
|
def test_to_s
|
143
72
|
Phone.default_country_code = nil
|
144
73
|
pn = Phone.new '5125486', '91', '385'
|
@@ -174,34 +103,4 @@ class PhoneTest < Test::Unit::TestCase
|
|
174
103
|
assert_equal Phone.valid?('385915125486'), false
|
175
104
|
end
|
176
105
|
|
177
|
-
def test_validates
|
178
|
-
Phone.default_country_code = nil
|
179
|
-
assert_equal Phone.valid?('00385915125486'), true
|
180
|
-
assert_equal Phone.valid?('+385915125486'), true
|
181
|
-
assert_equal Phone.valid?('+385 (91) 512 5486'), true
|
182
|
-
assert_equal Phone.valid?('+38547451588'), true
|
183
|
-
|
184
|
-
Phone.default_country_code = '385'
|
185
|
-
assert_equal Phone.valid?('0915125486'), true
|
186
|
-
assert_equal Phone.valid?('091/512-5486'), true
|
187
|
-
assert_equal Phone.valid?('091/512-5486'), true
|
188
|
-
assert_equal Phone.valid?('091 512 54 86'), true
|
189
|
-
assert_equal Phone.valid?('091-512-54-86'), true
|
190
|
-
assert_equal Phone.valid?('047/451-588'), true
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_has_default_country_code
|
194
|
-
Phone.default_country_code = '385'
|
195
|
-
|
196
|
-
assert_equal Phone.parse('+38547451588').has_default_country_code?, true
|
197
|
-
assert_equal Phone.parse('+38647451588').has_default_country_code?, false
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_has_default_area_code
|
201
|
-
Phone.default_country_code = '385'
|
202
|
-
Phone.default_area_code = '47'
|
203
|
-
|
204
|
-
assert_equal Phone.parse('047/451-588').has_default_area_code?, true
|
205
|
-
assert_equal Phone.parse('032/336-1456').has_default_area_code?, false
|
206
|
-
end
|
207
106
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,3 +4,12 @@ require 'rubygems'
|
|
4
4
|
|
5
5
|
require 'test/unit'
|
6
6
|
require 'phone'
|
7
|
+
|
8
|
+
def parse_test(raw, country_code, area_code, number)
|
9
|
+
pn = Phone.parse(raw)
|
10
|
+
|
11
|
+
assert_not_nil pn, %Q{parse should pass}
|
12
|
+
assert_equal pn.country_code, country_code
|
13
|
+
assert_equal pn.area_code, area_code
|
14
|
+
assert_equal pn.number, number
|
15
|
+
end
|
metadata
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 37
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 9
|
10
|
+
- 3
|
11
|
+
version: 0.9.9.3
|
5
12
|
platform: ruby
|
6
13
|
authors:
|
7
14
|
- Tomislav Car
|
8
15
|
- Todd Eichel
|
16
|
+
- Don Morrison
|
9
17
|
autorequire:
|
10
18
|
bindir: bin
|
11
19
|
cert_chain: []
|
12
20
|
|
13
|
-
date: 2010-
|
21
|
+
date: 2010-07-30 00:00:00 +02:00
|
14
22
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
17
|
-
name: activesupport
|
18
|
-
type: :runtime
|
19
|
-
version_requirement:
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: "0"
|
25
|
-
version:
|
23
|
+
dependencies: []
|
24
|
+
|
26
25
|
description: Phone number parsing, validation and formatting.
|
27
26
|
email:
|
28
27
|
- tomislav@infinum.hr
|
29
28
|
- todd@toddeichel.com
|
29
|
+
- elskwid@gmail.com
|
30
30
|
executables: []
|
31
31
|
|
32
32
|
extensions: []
|
@@ -40,9 +40,25 @@ files:
|
|
40
40
|
- data/phone_countries.yml
|
41
41
|
- lib/phone.rb
|
42
42
|
- lib/phone_country.rb
|
43
|
+
- lib/support.rb
|
44
|
+
- test/extension_test.rb
|
43
45
|
- test/phone_test.rb
|
44
|
-
- test/phone_country_test.rb
|
45
46
|
- test/test_helper.rb
|
47
|
+
- test/countries/au_test.rb
|
48
|
+
- test/countries/ba_test.rb
|
49
|
+
- test/countries/be_test.rb
|
50
|
+
- test/countries/de_test.rb
|
51
|
+
- test/countries/fr_test.rb
|
52
|
+
- test/countries/gb_test.rb
|
53
|
+
- test/countries/hr_test.rb
|
54
|
+
- test/countries/hu_test.rb
|
55
|
+
- test/countries/nl_test.rb
|
56
|
+
- test/countries/rs_test.rb
|
57
|
+
- test/countries/se_test.rb
|
58
|
+
- test/countries/si_test.rb
|
59
|
+
- test/countries/ua_test.rb
|
60
|
+
- test/countries/us_test.rb
|
61
|
+
- test/countries/za_test.rb
|
46
62
|
has_rdoc: true
|
47
63
|
homepage: http://github.com/carr/phone
|
48
64
|
licenses: []
|
@@ -56,25 +72,46 @@ rdoc_options:
|
|
56
72
|
require_paths:
|
57
73
|
- lib
|
58
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
59
76
|
requirements:
|
60
77
|
- - ">="
|
61
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
62
82
|
version: "0"
|
63
|
-
version:
|
64
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
65
85
|
requirements:
|
66
86
|
- - ">="
|
67
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
68
91
|
version: "0"
|
69
|
-
version:
|
70
92
|
requirements: []
|
71
93
|
|
72
94
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.7
|
74
96
|
signing_key:
|
75
97
|
specification_version: 3
|
76
98
|
summary: Phone number parsing, validation and formatting
|
77
99
|
test_files:
|
100
|
+
- test/extension_test.rb
|
78
101
|
- test/phone_test.rb
|
79
|
-
- test/phone_country_test.rb
|
80
102
|
- test/test_helper.rb
|
103
|
+
- test/countries/au_test.rb
|
104
|
+
- test/countries/ba_test.rb
|
105
|
+
- test/countries/be_test.rb
|
106
|
+
- test/countries/de_test.rb
|
107
|
+
- test/countries/fr_test.rb
|
108
|
+
- test/countries/gb_test.rb
|
109
|
+
- test/countries/hr_test.rb
|
110
|
+
- test/countries/hu_test.rb
|
111
|
+
- test/countries/nl_test.rb
|
112
|
+
- test/countries/rs_test.rb
|
113
|
+
- test/countries/se_test.rb
|
114
|
+
- test/countries/si_test.rb
|
115
|
+
- test/countries/ua_test.rb
|
116
|
+
- test/countries/us_test.rb
|
117
|
+
- test/countries/za_test.rb
|
data/test/phone_country_test.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class PhoneCountryTest < Test::Unit::TestCase
|
4
|
-
def test_parse_germany_local
|
5
|
-
pn = Phone.parse('+49 714 1605832')
|
6
|
-
|
7
|
-
assert_equal pn.country_code, '49'
|
8
|
-
assert_equal pn.area_code, '714'
|
9
|
-
assert_equal pn.number, '1605832'
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_parse_germany_mobile
|
13
|
-
pn = Phone.parse('+49 162 3499558')
|
14
|
-
|
15
|
-
assert_equal pn.country_code, '49'
|
16
|
-
assert_equal pn.area_code, '162'
|
17
|
-
assert_equal pn.number, '3499558'
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_parse_hungary_mobile
|
21
|
-
pn = Phone.parse('+36 30 5517999')
|
22
|
-
|
23
|
-
assert_equal pn.country_code, '36'
|
24
|
-
assert_equal pn.area_code, '30'
|
25
|
-
assert_equal pn.number, '5517999'
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_parse_slovenia_local
|
29
|
-
#Maribor
|
30
|
-
pn = Phone.parse '+ 386 2 23 46 611'
|
31
|
-
|
32
|
-
assert_equal pn.country_code, '386'
|
33
|
-
assert_equal pn.area_code, '2'
|
34
|
-
assert_equal pn.number, '2346611'
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_parse_slovenia_local_2
|
38
|
-
# Koper
|
39
|
-
pn = Phone.parse '+ 386 5 23 46 611'
|
40
|
-
|
41
|
-
assert_equal pn.country_code, '386'
|
42
|
-
assert_equal pn.area_code, '5'
|
43
|
-
assert_equal pn.number, '2346611'
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_parse_slovenia_mobile
|
47
|
-
# Mobitel
|
48
|
-
pn = Phone.parse('+386 51 258999')
|
49
|
-
|
50
|
-
assert_equal pn.country_code, '386'
|
51
|
-
assert_equal pn.area_code, '51'
|
52
|
-
assert_equal pn.number, '258999'
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_parse_serbia_local
|
56
|
-
# Beograd
|
57
|
-
pn = Phone.parse('+381 11 24 33 836')
|
58
|
-
|
59
|
-
assert_equal pn.country_code, '381'
|
60
|
-
assert_equal pn.area_code, '11'
|
61
|
-
assert_equal pn.number, '2433836'
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def test_parse_serbia_mobile
|
66
|
-
# mts
|
67
|
-
pn = Phone.parse('+381 648542987')
|
68
|
-
|
69
|
-
assert_equal pn.country_code, '381'
|
70
|
-
assert_equal pn.area_code, '64'
|
71
|
-
assert_equal pn.number, '8542987'
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_parse_bosnia_local
|
75
|
-
pn = Phone.parse '+387 33 25 02 33'
|
76
|
-
|
77
|
-
assert_equal pn.country_code, '387'
|
78
|
-
assert_equal pn.area_code, '33'
|
79
|
-
assert_equal pn.number, '250233'
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_parse_south_africa_local
|
83
|
-
# Telkom
|
84
|
-
pn = Phone.parse('+27 11 555 5555')
|
85
|
-
|
86
|
-
assert_equal pn.country_code, '27'
|
87
|
-
assert_equal pn.area_code, '11'
|
88
|
-
assert_equal pn.number, '5555555'
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_parse_south_africa_mobile
|
92
|
-
# Vodacom
|
93
|
-
pn = Phone.parse('+27 82 555 5555')
|
94
|
-
|
95
|
-
assert_equal pn.country_code, '27'
|
96
|
-
assert_equal pn.area_code, '82'
|
97
|
-
assert_equal pn.number, '5555555'
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_parse_south_africa_tollfree
|
101
|
-
# Telkom
|
102
|
-
pn = Phone.parse('+27 800 123 321')
|
103
|
-
|
104
|
-
assert_equal pn.country_code, '27'
|
105
|
-
assert_equal pn.area_code, '800'
|
106
|
-
assert_equal pn.number, '123321'
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_parse_france_local
|
110
|
-
pn = Phone.parse('+33 4 75 06 07 07')
|
111
|
-
|
112
|
-
assert_equal pn.country_code, '33'
|
113
|
-
assert_equal pn.area_code, '4'
|
114
|
-
assert_equal pn.number, '75060707'
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_parse_france_mobile
|
118
|
-
pn = Phone.parse('+33 6 11 22 33 44')
|
119
|
-
|
120
|
-
assert_equal pn.country_code, '33'
|
121
|
-
assert_equal pn.area_code, '6'
|
122
|
-
assert_equal pn.number, '11223344'
|
123
|
-
end
|
124
|
-
end
|