superp-phone 1.1
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.
- data/LICENSE +20 -0
- data/Readme.rdoc +153 -0
- data/data/phone_countries.yml +1683 -0
- data/lib/country.rb +120 -0
- data/lib/phone.rb +218 -0
- data/lib/support.rb +78 -0
- data/test/countries/au_test.rb +48 -0
- data/test/countries/ba_test.rb +9 -0
- data/test/countries/be_test.rb +120 -0
- data/test/countries/ca_test.rb +20 -0
- data/test/countries/de_test.rb +18 -0
- data/test/countries/fr_test.rb +22 -0
- data/test/countries/gb_test.rb +262 -0
- data/test/countries/hr_test.rb +75 -0
- data/test/countries/hu_test.rb +12 -0
- data/test/countries/in_test.rb +45 -0
- data/test/countries/nl_test.rb +383 -0
- data/test/countries/pt_test.rb +129 -0
- data/test/countries/rs_test.rb +15 -0
- data/test/countries/se_test.rb +478 -0
- data/test/countries/si_test.rb +19 -0
- data/test/countries/ua_test.rb +17 -0
- data/test/countries/us_test.rb +24 -0
- data/test/countries/za_test.rb +19 -0
- data/test/extension_test.rb +30 -0
- data/test/phone_test.rb +137 -0
- data/test/test_helper.rb +37 -0
- metadata +105 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## Slovenia
|
4
|
+
class SITest < Phoner::TestCase
|
5
|
+
def test_local
|
6
|
+
#Maribor
|
7
|
+
parse_test('+ 386 2 23 46 611', '386', '2', '2346611')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_local_2
|
11
|
+
# Koper
|
12
|
+
parse_test('+ 386 5 23 46 611', '386', '5', '2346611', "Slovenia", false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_mobile
|
16
|
+
# Mobitel
|
17
|
+
parse_test('+386 51 258999', '386', '51', '258999', "Slovenia", true)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## Ukraine
|
4
|
+
class UATest < Phoner::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
parse_test('+380 57 711 22 33', '380', '57', '7112233', "Ukraine", false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mobile
|
11
|
+
parse_test('+380-50-111-22-33', '380', '50', '1112233', "Ukraine", true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_mobile2
|
15
|
+
parse_test('+380-66-042-22-01', '380', '66', '0422201', "Ukraine", true)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## United States
|
4
|
+
class USTest < Phoner::TestCase
|
5
|
+
|
6
|
+
def test_local
|
7
|
+
parse_test('+1 251 123 4567', '1', '251', '1234567', 'United States')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_tollfree
|
11
|
+
parse_test('+1 800 555 3456', '1', '800', '5553456', 'United States')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_long_with_default_country_code
|
15
|
+
Phoner::Phone.default_country_code = '1'
|
16
|
+
parse_test('2069735100', '1', '206', '9735100', 'United States')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_short_with_default_country_code_and_area_code
|
20
|
+
Phoner::Phone.default_country_code = '1'
|
21
|
+
Phoner::Phone.default_area_code = '206'
|
22
|
+
parse_test('9735100', '1', '206', '9735100', 'United States')
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
## South Africa
|
4
|
+
class ZATest < Phoner::TestCase
|
5
|
+
def test_local
|
6
|
+
# Telkom
|
7
|
+
parse_test('+27 11 555 5555', '27', '11', '5555555', "South Africa", false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_mobile
|
11
|
+
# Vodacom
|
12
|
+
parse_test('+27 82 555 5555', '27', '82', '5555555', "South Africa", true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_tollfree
|
16
|
+
# Telkom
|
17
|
+
parse_test('+27 800 123 321', '27', '800', '123321', "South Africa", false)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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 = Phoner::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 = Phoner::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 = Phoner::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
|
+
def test_validation_keeps_extension
|
26
|
+
number = "555-555-1212 ext 1234"
|
27
|
+
Phoner::Phone.valid?(number)
|
28
|
+
assert_equal "555-555-1212 ext 1234", number
|
29
|
+
end
|
30
|
+
end
|
data/test/phone_test.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class PhoneTest < Phoner::TestCase
|
4
|
+
|
5
|
+
def test_is_mobile
|
6
|
+
assert Phoner::Phone.is_mobile?("918124452900")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_number_without_country_code_initialize
|
10
|
+
Phoner::Phone.default_country_code = nil
|
11
|
+
|
12
|
+
assert_raise RuntimeError do
|
13
|
+
pn = Phoner::Phone.new '5125486', '91'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_number_without_country_and_area_code_initialize
|
18
|
+
Phoner::Phone.default_country_code = nil
|
19
|
+
Phoner::Phone.default_area_code = nil
|
20
|
+
|
21
|
+
assert_raise RuntimeError do
|
22
|
+
pn = Phoner::Phone.new '451588'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_number_with_default_area_code_initialize
|
27
|
+
Phoner::Phone.default_country_code = '385'
|
28
|
+
Phoner::Phone.default_area_code = '47'
|
29
|
+
|
30
|
+
pn = Phoner::Phone.new '451588'
|
31
|
+
assert pn.number == '451588'
|
32
|
+
assert pn.area_code == '47'
|
33
|
+
assert pn.country_code == '385'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_number_with_default_country_code_initialize
|
37
|
+
Phoner::Phone.default_country_code = '386'
|
38
|
+
|
39
|
+
pn = Phoner::Phone.new '5125486', '91'
|
40
|
+
assert pn.number == '5125486'
|
41
|
+
assert pn.area_code == '91'
|
42
|
+
assert pn.country_code == '386'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_number_with_country_code_initialize
|
46
|
+
Phoner::Phone.default_country_code = '387'
|
47
|
+
|
48
|
+
pn = Phoner::Phone.new '5125486', '91', '385'
|
49
|
+
assert pn.number == '5125486'
|
50
|
+
assert pn.area_code == '91'
|
51
|
+
assert pn.country_code == '385'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_parse_empty
|
55
|
+
assert_equal Phoner::Phone.parse(''), nil
|
56
|
+
assert_equal Phoner::Phone.parse(nil), nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_parse_short_without_special_characters_without_country
|
60
|
+
Phoner::Phone.default_country_code = nil
|
61
|
+
|
62
|
+
assert_nil Phoner::Phone.parse "0915125486"
|
63
|
+
|
64
|
+
assert_raise RuntimeError do
|
65
|
+
Phoner::Phone.parse! "0915125486"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_parse_short_with_special_characters_without_country
|
70
|
+
Phoner::Phone.default_country_code = nil
|
71
|
+
|
72
|
+
assert_nil Phoner::Phone.parse "091/512-5486"
|
73
|
+
|
74
|
+
assert_raise RuntimeError do
|
75
|
+
Phoner::Phone.parse! "091/512-5486"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_to_s
|
80
|
+
Phoner::Phone.default_country_code = nil
|
81
|
+
pn = Phoner::Phone.new '5125486', '91', '385'
|
82
|
+
assert pn.to_s == '+385915125486'
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_to_s_without_country_code
|
86
|
+
Phoner::Phone.default_country_code = '385'
|
87
|
+
pn = Phoner::Phone.new '5125486', '91'
|
88
|
+
assert pn.format("0%a%n") == '0915125486'
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_format_special_with_country_code
|
92
|
+
Phoner::Phone.default_country_code = nil
|
93
|
+
pn = Phoner::Phone.new '5125486', '91', '385'
|
94
|
+
assert pn.format("+ %c (%a) %n") == '+ 385 (91) 5125486'
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_format_special_without_country_code
|
98
|
+
Phoner::Phone.default_country_code = '385'
|
99
|
+
pn = Phoner::Phone.new '5125486', '91'
|
100
|
+
assert_equal pn.format("%A/%f-%l"), '091/512-5486'
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_format_with_symbol_specifier
|
104
|
+
Phoner::Phone.default_country_code = nil
|
105
|
+
pn = Phoner::Phone.new '5125486', '91', '385'
|
106
|
+
assert_equal pn.format(:europe), '+385 (0) 91 512 5486'
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_valid
|
110
|
+
assert_equal Phoner::Phone.valid?('915125486', :country_code => '385'), true
|
111
|
+
assert_equal Phoner::Phone.valid?('385915125486'), true
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_doesnt_validate
|
115
|
+
assert_equal Phoner::Phone.valid?('asdas'), false
|
116
|
+
assert_equal Phoner::Phone.valid?('38591512548678'), false
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_comparison_true
|
120
|
+
pn1 = Phoner::Phone.new '5125486', '91', '385'
|
121
|
+
pn2 = Phoner::Phone.new '5125486', '91', '385'
|
122
|
+
assert pn1 == pn2
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_comparison_false
|
126
|
+
pn1 = Phoner::Phone.new '5125486', '91', '385'
|
127
|
+
pn2 = Phoner::Phone.new '1234567', '91', '385'
|
128
|
+
assert pn1 != pn2
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_parse_number_without_international_code
|
132
|
+
assert_equal (Phoner::Phone.parse "90123456"), nil
|
133
|
+
assert_equal (Phoner::Phone.parse "90123456", :country_code => '47').format(:default), "+4790123456"
|
134
|
+
assert_equal (Phoner::Phone.parse "90123456", :country_code => '47', :area_code => '').format(:default), "+4790123456"
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'phone'
|
7
|
+
|
8
|
+
def parse_test(raw, country_code, area_code, number, country_name = nil, is_mobile = nil)
|
9
|
+
pn = Phoner::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
|
+
if country_name
|
16
|
+
assert_equal pn.country.name, country_name
|
17
|
+
end
|
18
|
+
|
19
|
+
unless is_mobile.nil?
|
20
|
+
assert_equal is_mobile, pn.is_mobile?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class Phoner::TestCase < Test::Unit::TestCase
|
26
|
+
|
27
|
+
def setup
|
28
|
+
Phoner::Phone.default_country_code = nil
|
29
|
+
Phoner::Phone.default_area_code = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_test
|
33
|
+
klass = self.class.to_s
|
34
|
+
ancestors = (self.class.ancestors - [self.class]).collect { |ancestor| ancestor.to_s }
|
35
|
+
super unless klass =~ /TestCase/ or ancestors.first =~ /TestCase/
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: superp-phone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomislav Car
|
9
|
+
- Todd Eichel
|
10
|
+
- Don Morrison
|
11
|
+
- Wesley Moxam
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
16
|
+
dependencies: []
|
17
|
+
description: Release for https://github.com/wmoxam/phone fork
|
18
|
+
email:
|
19
|
+
- tomislav@infinum.hr
|
20
|
+
- todd@toddeichel.com
|
21
|
+
- elskwid@gmail.com
|
22
|
+
- wesley.moxam@gmail.com
|
23
|
+
executables: []
|
24
|
+
extensions: []
|
25
|
+
extra_rdoc_files:
|
26
|
+
- Readme.rdoc
|
27
|
+
- LICENSE
|
28
|
+
files:
|
29
|
+
- Readme.rdoc
|
30
|
+
- LICENSE
|
31
|
+
- data/phone_countries.yml
|
32
|
+
- lib/phone.rb
|
33
|
+
- lib/country.rb
|
34
|
+
- lib/support.rb
|
35
|
+
- test/extension_test.rb
|
36
|
+
- test/phone_test.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
- test/countries/au_test.rb
|
39
|
+
- test/countries/ba_test.rb
|
40
|
+
- test/countries/be_test.rb
|
41
|
+
- test/countries/ca_test.rb
|
42
|
+
- test/countries/de_test.rb
|
43
|
+
- test/countries/fr_test.rb
|
44
|
+
- test/countries/gb_test.rb
|
45
|
+
- test/countries/hr_test.rb
|
46
|
+
- test/countries/hu_test.rb
|
47
|
+
- test/countries/in_test.rb
|
48
|
+
- test/countries/nl_test.rb
|
49
|
+
- test/countries/pt_test.rb
|
50
|
+
- test/countries/rs_test.rb
|
51
|
+
- test/countries/se_test.rb
|
52
|
+
- test/countries/si_test.rb
|
53
|
+
- test/countries/ua_test.rb
|
54
|
+
- test/countries/us_test.rb
|
55
|
+
- test/countries/za_test.rb
|
56
|
+
homepage: http://github.com/superp/phone
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --main
|
61
|
+
- Readme.rdoc
|
62
|
+
- --inline-source
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.24
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Phone number parsing, validation and formatting
|
84
|
+
test_files:
|
85
|
+
- test/extension_test.rb
|
86
|
+
- test/phone_test.rb
|
87
|
+
- test/test_helper.rb
|
88
|
+
- test/countries/au_test.rb
|
89
|
+
- test/countries/ba_test.rb
|
90
|
+
- test/countries/be_test.rb
|
91
|
+
- test/countries/ca_test.rb
|
92
|
+
- test/countries/de_test.rb
|
93
|
+
- test/countries/fr_test.rb
|
94
|
+
- test/countries/gb_test.rb
|
95
|
+
- test/countries/hr_test.rb
|
96
|
+
- test/countries/hu_test.rb
|
97
|
+
- test/countries/in_test.rb
|
98
|
+
- test/countries/nl_test.rb
|
99
|
+
- test/countries/pt_test.rb
|
100
|
+
- test/countries/rs_test.rb
|
101
|
+
- test/countries/se_test.rb
|
102
|
+
- test/countries/si_test.rb
|
103
|
+
- test/countries/ua_test.rb
|
104
|
+
- test/countries/us_test.rb
|
105
|
+
- test/countries/za_test.rb
|