phony 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTI2YjZiNDBhODQ4NWQ1NTIzNmNlODllOTY3N2UyZTRhM2MxNmM1MQ==
5
- data.tar.gz: !binary |-
6
- M2UwYmM0ZmNjMjMwNWE1YTE5ZTY5YjNiOWY4ZjU4ZGI4ZDM4Y2Q5Mw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZjM2MzVlMGU3ODM4NmFmMmM0MGFjZjc5ZTk2Y2UxMmI0NjBjNDQzN2E3MWVh
10
- ZmU1Y2NjMDE1ZTU2YWY3ZGM4MzI5ZDJlMjY0YTBhYjUwNDk4NDQ3Zjc4Zjcz
11
- NDE4NmQ2MGJhYzk3N2RlNDEzNzUwYmNlOGRiYjE4Y2JiNGUxODA=
12
- data.tar.gz: !binary |-
13
- MjM0NjU1MDNkYjA2YTU2MjBmYTU4ZmM4ZTMxYmUxNTNiNjgwOGViYjE2ODM3
14
- MjNlZmJiZTE4YTk3ZTkwNjUwYjYzOThkODRkM2E3ZjNjMDVhZTkwYzg0Zjkx
15
- YzJlZmU0ZDRjOGQzNzVlNDMyZTY1NmM3NTI0OTU5NWQ1N2YwOWM=
2
+ SHA1:
3
+ metadata.gz: 3760bfc4fdec14fa4c466bce49cb8511e1e2acae
4
+ data.tar.gz: 9cca82ff693ac209e595f10eee22071efc46c313
5
+ SHA512:
6
+ metadata.gz: 58960e8e161f56e7d9c551ffcea11371f1d0a6264d18c4640bf020c0dbb23bb3e6880959ffca17894eff35b921e168a4058a24465b2483fb1c864cd51903fe93
7
+ data.tar.gz: e6476901e1e58b17da77613f2b1bbeaef380e1e6cad9ac9ac8762f50454a8770d5977c6755560e250969ba06e7ead4f7028e45b0a05b7a5bded917b9003757b6
@@ -67,6 +67,8 @@ Phony.define do
67
67
 
68
68
  # Belgium.
69
69
  #
70
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
71
+ #
70
72
  country '32', match(/^(70|800|90\d)\d+$/) >> split(3,3) | # Service
71
73
  match(/^(4[789]\d)\d{6}$/) >> split(6) | # Mobile
72
74
  one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
@@ -1,108 +1,104 @@
1
1
  # Brazilian phone numbers.
2
2
  #
3
- # http://www.anatel.gov.br/hotsites/CodigosNacionaisLocalidade/TelefoneCelular-CodigosDeArea.htm
4
- #
5
- # Note: São Paulo recently added an extra 9 digit to all mobile phones in the 11 area code
6
3
  #
7
- ndcs = [
8
-
9
- '11', #Sao Paulo
10
- '12', #Sao Paulo
11
- '13', #Sao Paulo
12
- '14', #Sao Paulo
13
- '15', #Sao Paulo
14
- '16', #Sao Paulo
15
- '17', #Sao Paulo
16
- '18', #Sao Paulo
17
- '19', #Sao Paulo
18
-
19
- '21', #Rio de Janeiro
20
- '22', #Rio de Janeiro
21
-
22
- '24', #Rio de Janeiro
23
-
24
-
25
- '27', #Espírito Santo
26
- '28', #Espírito Santo
27
-
28
-
29
- '31', #Minas Gerais
30
- '32', #Minas Gerais
31
- '33', #Minas Gerais
32
- '34', #Minas Gerais
33
- '35', #Minas Gerais
34
- '36', #Minas Gerais
35
- '37', #Minas Gerais
36
- '38', #Minas Gerais
37
-
38
-
39
- '41', #Paraná
40
- '42', #Paraná
41
- '43', #Paraná
42
- '44', #Paraná
43
- '45', #Paraná
44
- '46', #Paraná
45
- '47', #Santa Catarina
46
- '48', #Santa Catarina
47
- '49', #Santa Catarina
48
-
49
- '51', #Rio Grande do Sul
50
- '52', #Rio Grande do Sul
51
- '53', #Rio Grande do Sul
52
- '54', #Rio Grande do Sul
53
- '55', #Rio Grande do Sul
54
-
55
- '61', #Distrito Federal
56
- '62', #Goiânia
57
- '63', #Tocantins
58
- '64', #Goiânia
59
- '65', #Mato Grosso
60
- '66', #Mato Grosso
61
- '67', #Mato Grosso do Sul
62
- '68', #Acre
63
- '69', #Rondônia
64
-
65
- '71', #Bahia
66
- '72', #Bahia
67
- '73', #Bahia
68
- '74', #Bahia
69
- '75', #Bahia
70
-
71
- '77', #Bahia
72
- '78', #Bahia
73
- '79', #Sergipe
74
-
75
- '81', #Pernambuco
76
- '82', #Alagoas
77
- '83', #Paraíba
78
- '84', #Rio Grande do Norte
79
- '85', #Ceará
80
- '86', #Piauí
81
- '87', #Pernambuco
82
- '88', #Ceará
83
- '89', #Piauí
84
-
85
- '91', #Pará
86
- '92', #Amazonas
87
- '93', #Pará
88
- '94', #Pará
89
- '95', #Roraima
90
- '96', #Amapá
91
- '97', #Amazonas
92
- '98', #Maranhão
93
- '99', #Maranhão
4
+ # NDC Reference
5
+ # http://www.anatel.gov.br/hotsites/CodigosNacionaisLocalidade/TelefoneCelular-CodigosDeArea.htm
94
6
 
95
- ]
96
- service = %w{ 100, 128, 190 191 192 193 194 197 198 199 } # State specific numbers were not added. See http://www.brasil.gov.br/navegue_por/aplicativos/agenda
7
+ # 11 #Sao Paulo
8
+ # 12 #Sao Paulo
9
+ # 13 #Sao Paulo
10
+ # 14 #Sao Paulo
11
+ # 15 #Sao Paulo
12
+ # 16 #Sao Paulo
13
+ # 17 #Sao Paulo
14
+ # 18 #Sao Paulo
15
+ # 19 #Sao Paulo
16
+ #
17
+ # 21 #Rio de Janeiro
18
+ # 22 #Rio de Janeiro
19
+ #
20
+ # 24 #Rio de Janeiro
21
+ #
22
+ # 27 #Espírito Santo
23
+ # 28 #Espírito Santo
24
+ #
25
+ # 31 #Minas Gerais
26
+ # 32 #Minas Gerais
27
+ # 33 #Minas Gerais
28
+ # 34 #Minas Gerais
29
+ # 35 #Minas Gerais
30
+ # 36 #Minas Gerais
31
+ # 37 #Minas Gerais
32
+ # 38 #Minas Gerais
33
+ #
34
+ # 41 #Paraná
35
+ # 42 #Paraná
36
+ # 43 #Paraná
37
+ # 44 #Paraná
38
+ # 45 #Paraná
39
+ # 46 #Paraná
40
+ # 47 #Santa Catarina
41
+ # 48 #Santa Catarina
42
+ # 49 #Santa Catarina
43
+ #
44
+ # 51 #Rio Grande do Sul
45
+ # 52 #Rio Grande do Sul
46
+ # 53 #Rio Grande do Sul
47
+ # 54 #Rio Grande do Sul
48
+ # 55 #Rio Grande do Sul
49
+ #
50
+ # 61 #Distrito Federal
51
+ # 62 #Goiânia
52
+ # 63 #Tocantins
53
+ # 64 #Goiânia
54
+ # 65 #Mato Grosso
55
+ # 66 #Mato Grosso
56
+ # 67 #Mato Grosso do Sul
57
+ # 68 #Acre
58
+ # 69 #Rondônia
59
+ #
60
+ # 71 #Bahia
61
+ # 72 #Bahia
62
+ # 73 #Bahia
63
+ # 74 #Bahia
64
+ # 75 #Bahia
65
+ #
66
+ # 77 #Bahia
67
+ # 78 #Bahia
68
+ # 79 #Sergipe
69
+ #
70
+ # 81 #Pernambuco
71
+ # 82 #Alagoas
72
+ # 83 #Paraíba
73
+ # 84 #Rio Grande do Norte
74
+ # 85 #Ceará
75
+ # 86 #Piauí
76
+ # 87 #Pernambuco
77
+ # 88 #Ceará
78
+ # 89 #Piauí
79
+ #
80
+ # 91 #Pará
81
+ # 92 #Amazonas
82
+ # 93 #Pará
83
+ # 94 #Pará
84
+ # 95 #Roraima
85
+ # 96 #Amapá
86
+ # 97 #Amazonas
87
+ # 98 #Maranhão
88
+ # 99 #Maranhão
89
+
90
+ ndcs = /(11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|36|37|38|41|42|43|44|45|46|47|48|49|51|52|53|54|55|61|62|63|64|65|66|67|68|69|71|72|73|74|75|77|78|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)\d{8}/
91
+
92
+ service = %w{ 100 128 190 191 192 193 194 197 198 199 } # State specific numbers were not added. See http://www.brasil.gov.br/navegue_por/aplicativos/agenda
97
93
 
98
94
  special_numbers_3_4 = %w{ 0800 }
99
95
  special_numbers_4 = %w{ 3003 4004 4020 }
100
96
 
101
97
  Phony.define do
102
- country '55', match(/^(11|12|13|14|15|16|17|18|19|21|22|24|27|28)9\d+$/) >> split(5,4) |
98
+ country '55', match(/^(11|12|13|14|15|16|17|18|19|21|22|24|27|28)9\d{8}$/) >> split(5,4) |
99
+ match(ndcs) >> split(4,4) |
103
100
  one_of(special_numbers_3_4) >> split(3,4) |
104
101
  one_of(special_numbers_4) >> split(4) |
105
- one_of(service) >> split(3,3) |
106
- one_of(ndcs) >> split(4,4) |
107
- fixed(3) >> split(4,4)
102
+ one_of(service) >> split(3) |
103
+ fixed(3) >> split(3)
108
104
  end
@@ -16,8 +16,13 @@ Phony.define do
16
16
  /\A\d{5}\z/ => [3,2],
17
17
  /\A\d+\z/ => [3,3]) |
18
18
  one_of(%w(72)) >> split(3,3) | # ISP
19
- one_of(%w(60 61 62 63 66 68 69)) >> matched_split(
20
- /\A\d{3}\z/ => [3],
19
+ one_of(%w(60 61 62 63 68 69)) >> matched_split(
20
+ /\A\d{3}\z/ => [3],
21
+ /\A\d{7}\z/ => [3,4],
22
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
23
+ one_of(%w(66)) >> matched_split(
24
+ /\A\d{3}\z/ => [3],
25
+ /\A\d{6}\z/ => [3,3],
21
26
  /\A\d{7}\z/ => [3,4],
22
27
  /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
23
28
  one_of(%w(64 65)) >> matched_split(
data/lib/phony/country.rb CHANGED
@@ -24,8 +24,9 @@ module Phony
24
24
  # TODO Rewrite.
25
25
  #
26
26
  def with cc, options = {}
27
- @cc = cc
28
- @invalid_ndcs = options[:invalid_ndcs] || []
27
+ @cc = cc
28
+ @countrify_regex = /\A(?!#{@cc})/
29
+ @invalid_ndcs = options[:invalid_ndcs] || []
29
30
  end
30
31
 
31
32
  # A number is split with the code handlers as given in the initializer.
@@ -68,7 +69,7 @@ module Phony
68
69
  countrify! number || number
69
70
  end
70
71
  def countrify! number
71
- number.sub! /\A(?!#{@cc})/, @cc
72
+ number.sub! @countrify_regex, @cc
72
73
  end
73
74
 
74
75
  # Removes 0s from partially normalized numbers
@@ -26,9 +26,9 @@ module Phony
26
26
 
27
27
  # Try for all possible mapped.
28
28
  #
29
- @mapped_ndc_min_length.upto(@mapped_ndc_max_length) do |i|
30
- sized_ndcs = @ndcs[i]
31
- return [@zero, presumed_code, national_number] unless sized_ndcs && !sized_ndcs.include?(presumed_code)
29
+ @mapped_ndc_min_length.upto @mapped_ndc_max_length do |i|
30
+ ndcs_of_size_i = @ndcs[i]
31
+ return [@zero, presumed_code, national_number] unless ndcs_of_size_i && !ndcs_of_size_i.include?(presumed_code)
32
32
  presumed_code << national_number.slice!(0..0)
33
33
  end
34
34
 
@@ -45,10 +45,6 @@ module Phony
45
45
 
46
46
  private
47
47
 
48
- # def restructure ndc_map
49
- # optimize ndc_map.values.flatten
50
- # end
51
-
52
48
  # Optimizes and restructures the given ndcs array.
53
49
  #
54
50
  def optimize ndc_ary
@@ -628,7 +628,8 @@ describe 'plausibility' do
628
628
  '+381 9 123 4567',
629
629
  '+381 60 123',
630
630
  '+381 60 123 456 7890',
631
- '+381 70 123 456']
631
+ '+381 70 123 456',
632
+ '+381 66 12 1234']
632
633
  it_is_correct_for 'Sierra Leone', :samples => '+232 42 393 972'
633
634
  it_is_correct_for 'Solomon Islands', :samples => '+677 97851'
634
635
  it_is_correct_for 'Somali Democratic Republic', :samples => ['+252 1034 123 45',
@@ -105,6 +105,8 @@ describe 'country descriptions' do
105
105
  it_splits '5511981231234', ['55', '11', '98123', '1234'] # São Paulo's 9 digits mobile
106
106
  it_splits '552181231234', ['55', '21', '8123', '1234']
107
107
  it_splits '5521981231234', ['55', '21', '98123', '1234'] # Rio de Janeiro's 9 digits mobile
108
+ it_splits '551931311234', ['55', '19', '3131', '1234'] # Rio de Janeiro's 9 digits mobile
109
+ it_splits '5519991311234', ['55', '19', '99131', '1234'] # Rio de Janeiro's 9 digits mobile
108
110
 
109
111
  context "special states with 9 in mobile" do
110
112
  %w{ 11 12 13 14 15 16 17 18 19 21 22 24 27 28}.each do |state_code|
@@ -118,6 +120,11 @@ describe 'country descriptions' do
118
120
  it_splits '5540209999', ['55', '4020', '9999']
119
121
  it_splits '5540048999', ['55', '4004', '8999']
120
122
  end
123
+
124
+ context "service numbers" do
125
+ it_splits '55100', ['55', '100', ""]
126
+ it_splits '55199', ['55', '199', ""]
127
+ end
121
128
  end
122
129
  describe 'Cambodia' do
123
130
  it_splits '85512236142', ["855", "12", "236", "142"] # mobile (Mobitel)
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-09 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: ! 'Fast international phone number (E164 standard) normalizing, splitting
13
+ description: 'Fast international phone number (E164 standard) normalizing, splitting
14
14
  and formatting. Lots of formatting options: International (+.., 00..), national
15
15
  (0..), and local).'
16
16
  email: florian.hanke+phony@gmail.com
@@ -19,6 +19,9 @@ extensions: []
19
19
  extra_rdoc_files:
20
20
  - README.textile
21
21
  files:
22
+ - README.textile
23
+ - lib/phony.rb
24
+ - lib/phony/countries.rb
22
25
  - lib/phony/countries/austria.rb
23
26
  - lib/phony/countries/bangladesh.rb
24
27
  - lib/phony/countries/belarus.rb
@@ -55,7 +58,6 @@ files:
55
58
  - lib/phony/countries/united_kingdom.rb
56
59
  - lib/phony/countries/uruguay.rb
57
60
  - lib/phony/countries/zimbabwe.rb
58
- - lib/phony/countries.rb
59
61
  - lib/phony/country.rb
60
62
  - lib/phony/country_codes.rb
61
63
  - lib/phony/dsl.rb
@@ -70,8 +72,6 @@ files:
70
72
  - lib/phony/national_splitters/variable.rb
71
73
  - lib/phony/trunk_code.rb
72
74
  - lib/phony/vanity.rb
73
- - lib/phony.rb
74
- - README.textile
75
75
  - spec/functional/normalize_spec.rb
76
76
  - spec/functional/plausibility_spec.rb
77
77
  - spec/lib/phony/countries_spec.rb
@@ -97,17 +97,17 @@ require_paths:
97
97
  - lib
98
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ! '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ! '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.0.3
110
+ rubygems_version: 2.2.0
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Fast international phone number (E164 standard) normalizing, splitting and