elskwid-phone 0.9.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,106 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class PhoneTest < Test::Unit::TestCase
4
+
5
+ def test_number_without_country_code_initialize
6
+ Phone.default_country_code = nil
7
+
8
+ assert_raise RuntimeError do
9
+ pn = Phone.new '5125486', '91'
10
+ end
11
+ end
12
+
13
+ def test_number_without_country_and_area_code_initialize
14
+ Phone.default_country_code = nil
15
+ Phone.default_area_code = nil
16
+
17
+ assert_raise RuntimeError do
18
+ pn = Phone.new '451588'
19
+ end
20
+ end
21
+
22
+ def test_number_with_default_area_code_initialize
23
+ Phone.default_country_code = '385'
24
+ Phone.default_area_code = '47'
25
+
26
+ pn = Phone.new '451588'
27
+ assert pn.number == '451588'
28
+ assert pn.area_code == '47'
29
+ assert pn.country_code == '385'
30
+ end
31
+
32
+ def test_number_with_default_country_code_initialize
33
+ Phone.default_country_code = '386'
34
+
35
+ pn = Phone.new '5125486', '91'
36
+ assert pn.number == '5125486'
37
+ assert pn.area_code == '91'
38
+ assert pn.country_code == '386'
39
+ end
40
+
41
+ def test_number_with_country_code_initialize
42
+ Phone.default_country_code = '387'
43
+
44
+ pn = Phone.new '5125486', '91', '385'
45
+ assert pn.number == '5125486'
46
+ assert pn.area_code == '91'
47
+ assert pn.country_code == '385'
48
+ end
49
+
50
+ def test_parse_empty
51
+ assert_equal Phone.parse(''), nil
52
+ assert_equal Phone.parse(nil), nil
53
+ end
54
+
55
+ def test_parse_short_without_special_characters_without_country
56
+ Phone.default_country_code = nil
57
+
58
+ assert_raise RuntimeError do
59
+ pn = Phone.parse "0915125486"
60
+ end
61
+ end
62
+
63
+ def test_parse_short_with_special_characters_without_country
64
+ Phone.default_country_code = nil
65
+
66
+ assert_raise RuntimeError do
67
+ pn = Phone.parse "091/512-5486"
68
+ end
69
+ end
70
+
71
+ def test_to_s
72
+ Phone.default_country_code = nil
73
+ pn = Phone.new '5125486', '91', '385'
74
+ assert pn.to_s == '+385915125486'
75
+ end
76
+
77
+ def test_to_s_without_country_code
78
+ Phone.default_country_code = '385'
79
+ pn = Phone.new '5125486', '91'
80
+ assert pn.format("0%a%n") == '0915125486'
81
+ end
82
+
83
+ def test_format_special_with_country_code
84
+ Phone.default_country_code = nil
85
+ pn = Phone.new '5125486', '91', '385'
86
+ assert pn.format("+ %c (%a) %n") == '+ 385 (91) 5125486'
87
+ end
88
+
89
+ def test_format_special_without_country_code
90
+ Phone.default_country_code = '385'
91
+ pn = Phone.new '5125486', '91'
92
+ assert_equal pn.format("%A/%f-%l"), '091/512-5486'
93
+ end
94
+
95
+ def test_format_with_symbol_specifier
96
+ Phone.default_country_code = nil
97
+ pn = Phone.new '5125486', '91', '385'
98
+ assert_equal pn.format(:europe), '+385 (0) 91 512 5486'
99
+ end
100
+
101
+ def test_doesnt_validate
102
+ assert_equal Phone.valid?('asdas'), false
103
+ assert_equal Phone.valid?('385915125486'), false
104
+ end
105
+
106
+ end
@@ -0,0 +1,15 @@
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)
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 ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elskwid-phone
3
+ version: !ruby/object:Gem::Version
4
+ hash: 39
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 9
10
+ - 2
11
+ version: 0.9.9.2
12
+ platform: ruby
13
+ authors:
14
+ - Tomislav Car
15
+ - Todd Eichel
16
+ - Don Morrison
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2010-07-29 00:00:00 -07:00
22
+ default_executable:
23
+ dependencies: []
24
+
25
+ description: Phone number parsing, validation and formatting.
26
+ email:
27
+ - tomislav@infinum.hr
28
+ - todd@toddeichel.com
29
+ - elskwid@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - Readme.rdoc
36
+ - LICENSE
37
+ files:
38
+ - Readme.rdoc
39
+ - LICENSE
40
+ - data/phone_countries.yml
41
+ - lib/phone.rb
42
+ - lib/phone_country.rb
43
+ - lib/support.rb
44
+ - test/extension_test.rb
45
+ - test/phone_test.rb
46
+ - test/test_helper.rb
47
+ - test/countries/ba_test.rb
48
+ - test/countries/de_test.rb
49
+ - test/countries/fr_test.rb
50
+ - test/countries/gb_test.rb
51
+ - test/countries/hr_test.rb
52
+ - test/countries/hu_test.rb
53
+ - test/countries/rs_test.rb
54
+ - test/countries/se_test.rb
55
+ - test/countries/si_test.rb
56
+ - test/countries/ua_test.rb
57
+ - test/countries/us_test.rb
58
+ - test/countries/za_test.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/elskwid/phone
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - Readme.rdoc
67
+ - --inline-source
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Phone number parsing, validation and formatting
96
+ test_files:
97
+ - test/extension_test.rb
98
+ - test/phone_test.rb
99
+ - test/test_helper.rb
100
+ - test/countries/ba_test.rb
101
+ - test/countries/de_test.rb
102
+ - test/countries/fr_test.rb
103
+ - test/countries/gb_test.rb
104
+ - test/countries/hr_test.rb
105
+ - test/countries/hu_test.rb
106
+ - test/countries/rs_test.rb
107
+ - test/countries/se_test.rb
108
+ - test/countries/si_test.rb
109
+ - test/countries/ua_test.rb
110
+ - test/countries/us_test.rb
111
+ - test/countries/za_test.rb