phony 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -5,6 +5,8 @@ h2. Description
5
5
  This gem can normalize, format and split E164 numbers.
6
6
  "More about E164 numbers in this Wiki":http://en.wikipedia.org/wiki/E.164.
7
7
 
8
+ The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
9
+
8
10
  Currently handles Afghan, Austrian, Australian, Belgian, Brazilian, Chilean, Chinese, Czech, Danish, Dutch, Egyptian, French, German, Greek, Hungarian, Italian, Malaysian, (The) Netherlands, New Zealand, Norwegian, Peruvian, Polish, Russian, Romanian, South African, South Korean, Spanish, Swedish, Swiss, Turkish, Liechtenstein, US, Venezuelan numbers.
9
11
  And to some extend, all others. Just try if it works for you.
10
12
 
data/lib/phony.rb CHANGED
@@ -13,6 +13,7 @@ require File.expand_path '../phony/country', __FILE__
13
13
  #
14
14
  require File.expand_path '../phony/countries/all_other', __FILE__
15
15
  require File.expand_path '../phony/countries/austria', __FILE__
16
+ require File.expand_path '../phony/countries/belgium', __FILE__
16
17
  require File.expand_path '../phony/countries/chile', __FILE__
17
18
  require File.expand_path '../phony/countries/china', __FILE__
18
19
  require File.expand_path '../phony/countries/egypt', __FILE__
@@ -23,6 +24,7 @@ require File.expand_path '../phony/countries/italy', __FILE__
23
24
  require File.expand_path '../phony/countries/malaysia', __FILE__
24
25
  require File.expand_path '../phony/countries/netherlands', __FILE__
25
26
  require File.expand_path '../phony/countries/peru', __FILE__
27
+ require File.expand_path '../phony/countries/portugal', __FILE__
26
28
  require File.expand_path '../phony/countries/romania', __FILE__
27
29
  require File.expand_path '../phony/countries/south_korea', __FILE__
28
30
  require File.expand_path '../phony/countries/sweden', __FILE__
@@ -46,9 +46,7 @@ module Phony
46
46
 
47
47
  '30' => Countries::Greece,
48
48
  '31' => Countries::Netherlands,
49
- '32' => fixed(1, # Belgium
50
- :local_format => [3, 4]
51
- ),
49
+ '32' => Countries::Belgium,
52
50
  '33' => fixed(1, # France
53
51
  :local_format => [2, 2, 2, 2],
54
52
  :service_ndcs => %w{8}
@@ -82,9 +80,9 @@ module Phony
82
80
  '47' => fixed(4, # Norway
83
81
  :local_format => [4]
84
82
  ),
85
- '48' => fixed(2, # Poland (Republic of)
86
- :local_format => [1, 3, 3] # Approximation. Correct would be 48-xxx-xxx-xxx
87
- ),
83
+ '48' => fixed(3, # Poland (Republic of)
84
+ :local_format => [3, 3] # Although the NDCs are 2 digits, the representation is 3 digits.
85
+ ), # Note: http://wapedia.mobi/en/Telephone_numbers_in_Poland, mobile not yet correct
88
86
  '49' => Countries::Germany,
89
87
 
90
88
  '51' => Countries::Peru,
@@ -222,7 +220,7 @@ module Phony
222
220
  '299' => fixed(2), # Greenland
223
221
 
224
222
  '350' => fixed(2), # Gibraltar
225
- '351' => fixed(2), # Portugal
223
+ '351' => Countries::Portugal, # Portugal
226
224
  '352' => fixed(2), # Luxembourg
227
225
  '353' => fixed(2), # Ireland
228
226
  '354' => fixed(2), # Iceland
@@ -0,0 +1,60 @@
1
+ # Belgium uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
2
+ #
3
+ # Taken from: http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
4
+ #
5
+ Phony::Countries::Belgium = Phony::Country.configured :local_format => [3, 5],
6
+ :ndc_fallback_length => 2,
7
+ :ndc_mapping => {
8
+ :landline => [
9
+ '2', # Brussels (Bruxelles/Brussel)
10
+ '3', # Antwerpen (Antwerp), Sint-Niklaas
11
+ '4', # Liège (Luik), Voeren (Fourons)
12
+ '9', # Gent (Ghent/Gand)
13
+ ],
14
+ :mobile => [
15
+ '470', # Mobistar
16
+ '471', # Mobistar
17
+ '472', # Mobistar
18
+ '473', # Mobistar
19
+ '474', # Mobistar
20
+ '475', # Mobistar
21
+ '476', # Mobistar
22
+ '477', # Mobistar
23
+ '478', # Mobistar
24
+ '479', # Mobistar
25
+ '480', # Base
26
+ '481', # Base
27
+ '482', # Base
28
+ '483', # Base
29
+ '484', # Base
30
+ '485', # Base
31
+ '486', # Base
32
+ '487', # Base
33
+ '488', # Base
34
+ '489', # Base
35
+ '490', # Proximus
36
+ '491', # Proximus
37
+ '492', # Proximus
38
+ '493', # Proximus
39
+ '494', # Proximus
40
+ '495', # Proximus
41
+ '496', # Proximus
42
+ '497', # Proximus
43
+ '498', # Proximus
44
+ '499', # Proximus
45
+ ],
46
+ :service => [
47
+ '70', # Specialty numbers, i.e. bus information or bank information
48
+ '800', # Tollfree
49
+ '900', # Premium
50
+ '901', # Premium
51
+ '902', # Premium
52
+ '903', # Premium
53
+ '904', # Premium
54
+ '905', # Premium
55
+ '906', # Premium
56
+ '907', # Premium
57
+ '908', # Premium
58
+ '909' # Premium
59
+ ]
60
+ }
@@ -2,6 +2,8 @@
2
2
  #
3
3
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Egypt
4
4
  #
5
+ # TODO If the fallback length is 2, why do I list length 2 landlines?
6
+ #
5
7
  Phony::Countries::Egypt = Phony::Country.configured :local_format => [8],
6
8
  :local_special_format => [7],
7
9
  :ndc_fallback_length => 2,
@@ -0,0 +1,15 @@
1
+ # Portuguese phone numbers.
2
+ #
3
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Portugal
4
+ #
5
+ Phony::Countries::Portugal = Phony::Country.configured :local_format => [3, 4],
6
+ :local_special_format => [3, 3],
7
+ :ndc_fallback_length => 3,
8
+ :ndc_mapping => {
9
+ :landline => [
10
+ '21', # Lisboa
11
+ '22', # Porto
12
+ ],
13
+ :mobile => ('90'..'99').to_a,
14
+ :service => %w{700 800} # Not exhaustive.
15
+ }
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe Phony::Countries::Belgium do
6
+
7
+ before(:each) do
8
+ @belgium = Phony::Countries::Belgium
9
+ end
10
+
11
+ describe "split" do
12
+ it "should handle Antwerpen" do
13
+ @belgium.split('35551212').should == ['3', '555', '1212']
14
+ end
15
+ it "should handle Brugge" do
16
+ @belgium.split('505551212').should == ['50', '555', '1212']
17
+ end
18
+ it "should handle Brussels" do
19
+ @belgium.split('25551212').should == ['2', '555', '1212']
20
+ end
21
+ it "should handle Gent" do
22
+ @belgium.split('95551914').should == ['9', '555', '1914']
23
+ end
24
+ it "should handle Liège" do
25
+ @belgium.split('45551414').should == ['4', '555', '1414']
26
+ end
27
+ it "should handle some mobile services" do
28
+ @belgium.split('475279584').should == ['475', '279584']
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phony::Countries::Portugal do
4
+
5
+ before(:each) do
6
+ @portugal = Phony::Countries::Portugal
7
+ end
8
+
9
+ describe "split" do
10
+ it "works with Lisboa" do
11
+ @portugal.split('211231234').should == ['21', '123', '1234']
12
+ end
13
+ it "works with Abrantes" do
14
+ @portugal.split('241123123').should == ['241', '123', '123']
15
+ end
16
+ it 'works with a mobile' do
17
+ @portugal.split('931231234').should == ['93', '123', '1234']
18
+ end
19
+ end
20
+
21
+ end
@@ -8,9 +8,17 @@ describe Phony do
8
8
  it 'handles afghan numbers' do
9
9
  Phony.split('93201234567').should == ['93', '20', '1234567'] # Kabul
10
10
  end
11
- it "should handle austrian numbers" do
11
+ it "handles austrian numbers" do
12
12
  Phony.split('43198110').should == ['43', '1', '98110']
13
13
  end
14
+ it 'handles belgian numbers' do
15
+ Phony.split('3235551212').should == ['32', '3', '555', '1212'] # Antwerpen
16
+ Phony.split('32505551212').should == ['32', '50', '555', '1212'] # Brugge
17
+ Phony.split('3225551212').should == ['32', '2', '555', '1212'] # Brussels
18
+ Phony.split('3295551914').should == ['32', '9', '555', '1914'] # Gent
19
+ Phony.split('3245551414').should == ['32', '4', '555', '1414'] # Liège
20
+ Phony.split('32475279584').should == ['32', '475', '279584'] # mobile
21
+ end
14
22
  it 'handles brazilian numbers' do
15
23
  Phony.split('551112341234').should == ['55', '11', '1234', '1234']
16
24
  end
@@ -31,14 +39,14 @@ describe Phony do
31
39
  Phony.split('31201234567').should == ['31', '20', '1234567']
32
40
  Phony.split('31222123456').should == ['31', '222', '123456']
33
41
  end
34
- it "should handle egyptian numbers" do
42
+ it "handles egyptian numbers" do
35
43
  Phony.split('20212345678').should == ['20', '2', '12345678']
36
44
  Phony.split('20951234567').should == ['20', '95', '1234567']
37
45
  end
38
- it "should handle french numbers" do
46
+ it "handles french numbers" do
39
47
  Phony.split('33112345678').should == ['33', '1', '12','34','56','78']
40
48
  end
41
- it "should handle german numbers" do
49
+ it "handles german numbers" do
42
50
  Phony.split('4930123456').should == ['49', '30', '123', '456']
43
51
  Phony.split('4976112345').should == ['49', '761', '123', '45']
44
52
  Phony.split('492041123456').should == ['49', '2041', '123', '456']
@@ -56,6 +64,7 @@ describe Phony do
56
64
  it 'handles malay numbers' do
57
65
  Phony.split('6082123456').should == ['60', '82', '123456'] # Kuching
58
66
  Phony.split('60312345678').should == ['60', '3', '12345678'] # Kuala Lumpur
67
+ Phony.split('60212345678').should == ['60', '2', '12345678'] # Singapore
59
68
  end
60
69
  it 'handles peruvian numbers' do
61
70
  Phony.split('51112341234').should == ['51', '1', '1234', '1234'] # Lima
@@ -63,7 +72,12 @@ describe Phony do
63
72
  Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
64
73
  end
65
74
  it "should handle polish numbers" do
66
- Phony.split('48121123123').should == ['48', '12', '1', '123', '123']
75
+ Phony.split('48123123123').should == ['48', '123', '123', '123']
76
+ end
77
+ it 'handles portuguese numbers' do
78
+ Phony.split('351211231234').should == ['351', '21', '123', '1234'] # Lisboa
79
+ Phony.split('351241123123').should == ['351', '241', '123', '123'] # Abrantes
80
+ Phony.split('351931231234').should == ['351', '93', '123', '1234'] # mobile
67
81
  end
68
82
  it 'handles romanian numbers' do
69
83
  Phony.split('40211231234').should == ['40', '21', '123', '1234'] # Bucureşti
@@ -300,7 +314,7 @@ describe Phony do
300
314
  performance_of { Phony.normalize(number) }.should < 0.0001
301
315
  end
302
316
  it 'is fast' do
303
- performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00015
317
+ performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00016
304
318
  end
305
319
  end
306
320
  describe 'formatted' do
@@ -309,7 +323,7 @@ describe Phony do
309
323
  performance_of { Phony.formatted(number) }.should < 0.000075
310
324
  end
311
325
  it 'is fast' do
312
- performance_of { @phone_numbers.each { |number| Phony.formatted(number) } }.should < 0.00015
326
+ performance_of { @phone_numbers.each { |number| Phony.formatted(number) } }.should < 0.00016
313
327
  end
314
328
  end
315
329
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 4
9
- version: 1.2.4
8
+ - 5
9
+ version: 1.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Florian Hanke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-01 00:00:00 +01:00
17
+ date: 2011-01-21 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -29,6 +29,7 @@ extra_rdoc_files:
29
29
  files:
30
30
  - lib/phony/countries/all_other.rb
31
31
  - lib/phony/countries/austria.rb
32
+ - lib/phony/countries/belgium.rb
32
33
  - lib/phony/countries/chile.rb
33
34
  - lib/phony/countries/china.rb
34
35
  - lib/phony/countries/egypt.rb
@@ -39,6 +40,7 @@ files:
39
40
  - lib/phony/countries/malaysia.rb
40
41
  - lib/phony/countries/netherlands.rb
41
42
  - lib/phony/countries/peru.rb
43
+ - lib/phony/countries/portugal.rb
42
44
  - lib/phony/countries/romania.rb
43
45
  - lib/phony/countries/south_korea.rb
44
46
  - lib/phony/countries/sweden.rb
@@ -52,10 +54,12 @@ files:
52
54
  - lib/phony.rb
53
55
  - README.textile
54
56
  - spec/lib/phony/countries/austria_spec.rb
57
+ - spec/lib/phony/countries/belgium_spec.rb
55
58
  - spec/lib/phony/countries/egypt_spec.rb
56
59
  - spec/lib/phony/countries/germany_spec.rb
57
60
  - spec/lib/phony/countries/greece_spec.rb
58
61
  - spec/lib/phony/countries/hungary_spec.rb
62
+ - spec/lib/phony/countries/portugal_spec.rb
59
63
  - spec/lib/phony/countries/switzerland_spec.rb
60
64
  - spec/lib/phony/country_codes_spec.rb
61
65
  - spec/lib/phony/country_spec.rb
@@ -99,10 +103,12 @@ specification_version: 3
99
103
  summary: Fast international phone number (E164 standard) normalizing, splitting and formatting.
100
104
  test_files:
101
105
  - spec/lib/phony/countries/austria_spec.rb
106
+ - spec/lib/phony/countries/belgium_spec.rb
102
107
  - spec/lib/phony/countries/egypt_spec.rb
103
108
  - spec/lib/phony/countries/germany_spec.rb
104
109
  - spec/lib/phony/countries/greece_spec.rb
105
110
  - spec/lib/phony/countries/hungary_spec.rb
111
+ - spec/lib/phony/countries/portugal_spec.rb
106
112
  - spec/lib/phony/countries/switzerland_spec.rb
107
113
  - spec/lib/phony/country_codes_spec.rb
108
114
  - spec/lib/phony/country_spec.rb