phony 2.1.4 → 2.2.0

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
- MWEzOThmOTg4NjE5ODMzYzI1Zjg5NWJhYmNkMzY2MjIwMzc5NDkxMQ==
5
- data.tar.gz: !binary |-
6
- MzBmODNjNmUxNmQ3ZWUxYjJjYTQ2N2FmMGVkZWEyZTlkYjI5ZGFhMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NGZiMDE5NWY0YmNiZDRiYWYxMDNjMTU3ZGEyYWViYTRkNmI1ZmFmODRjODgx
10
- MWIwN2M1OTBlY2E1MmU0ZWM1ZTVhZDgxODczNDZjY2IwMTU2YzFkODg3NWUz
11
- ZjAxNGJlODg2OWNkNjk2YWVkNDhiOTU4MTQ1ODE3MzQ2MjZjNmU=
12
- data.tar.gz: !binary |-
13
- ZmJjOTI5NzNjODU1YmI2YTdiMjU4ZjhiN2JhNzg2OGY3ZDkyZjNiNTNmNmUz
14
- Mzg5N2YyMWNhNmRhYTlmNzM5NDBlYWViZDgyMjg2ZDMzODcwNjM5NTZkN2Y5
15
- YzE0MDFkMjVkNDYwNzdjNDcwZDlhYTMzMWQ1OTI2ZDFjMzNhZDE=
2
+ SHA1:
3
+ metadata.gz: cab09437919d2b8ac9980c997aca16b6029bc14b
4
+ data.tar.gz: c764db5c678f5bc78c6a49180319b7647e7c39a1
5
+ SHA512:
6
+ metadata.gz: b6261b97af629e5f22fcfd53dff8c91decee37fa4ac50fec962cb065eab5e799ab33df8fe4c1997a22641a8facafa91af5a0f2a270a3c9a691d250f4f3411b71
7
+ data.tar.gz: 74e8df4cb1aa40c3416d8813a13d5e04639c54a0070293af51c792f60f5fecb914c2efdd8b5e8bc9aea79f7057c8597795ba935d17a2f4c855e7e7103cdce585
@@ -158,6 +158,6 @@ Phony.define do
158
158
  one_of(*service) >> split(3,3) |
159
159
  one_of(*mobile) >> split(3,4) |
160
160
  one_of(*ndcs_2digit) >> split(4,4) |
161
- one_of(*ndcs_3digit) >> split(3,4) |
161
+ one_of(*ndcs_3digit) >> split(6..7) |
162
162
  one_of(*ndcs_4digit) >> split(3,3)
163
163
  end
data/lib/phony/country.rb CHANGED
@@ -24,9 +24,8 @@ module Phony
24
24
  # TODO Rewrite.
25
25
  #
26
26
  def with cc, options = {}
27
- @cc = cc
28
- @countrify_regex = /\A(?!#{@cc})/
29
- @invalid_ndcs = options[:invalid_ndcs] || []
27
+ @cc = cc
28
+ @invalid_ndcs = options[:invalid_ndcs] || []
30
29
  end
31
30
 
32
31
  # A number is split with the code handlers as given in the initializer.
@@ -60,18 +59,6 @@ module Phony
60
59
  number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
61
60
  end
62
61
 
63
- # Adds the country code to the front
64
- # if it does not already start with it.
65
- #
66
- # Note: This won't be correct in some cases, but it is the best we can do.
67
- #
68
- def countrify number
69
- countrify! number || number
70
- end
71
- def countrify! number
72
- number.sub! @countrify_regex, @cc
73
- end
74
-
75
62
  # Removes 0s from partially normalized numbers
76
63
  # such as 410443643533.
77
64
  #
@@ -87,8 +74,6 @@ module Phony
87
74
  break result if result
88
75
  number
89
76
  end
90
- return unless normalized
91
- countrify! normalized
92
77
  normalized
93
78
  end
94
79
 
@@ -40,6 +40,18 @@ module Phony
40
40
  def clean! number
41
41
  number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
42
42
  end
43
+
44
+ # Adds the country code to the front
45
+ # if it does not already start with it.
46
+ #
47
+ # Note: This won't be correct in some cases, but it is the best we can do.
48
+ #
49
+ def countrify number, cc
50
+ countrify!(number, cc) || number
51
+ end
52
+ def countrify! number, cc
53
+ number.sub! /\A/, cc # @countrify_regex, @cc
54
+ end
43
55
 
44
56
  # 00 for the standard international call prefix.
45
57
  # http://en.wikipedia.org/wiki/List_of_international_call_prefixes
@@ -60,7 +72,8 @@ module Phony
60
72
  country, cc, number = split_cc number
61
73
  country
62
74
  end
63
- country.normalize number
75
+ number = country.normalize number
76
+ countrify! number, cc
64
77
  end
65
78
 
66
79
  # Splits this number into cc, ndc and locally split number parts.
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Issues' do
4
+
5
+ describe '#136' do
6
+
7
+ it 'is correct for country 39' do
8
+ Phony.normalize('+39 393 0000000').should == '393930000000'
9
+ end
10
+
11
+ it 'fixes #136' do
12
+ italia = Phony['39']
13
+ italia.normalize('363 000000').should == '363000000'
14
+ end
15
+
16
+ it 'is correct for country 46' do
17
+ Phony.normalize('+46 (0)46 222 0000').should == '46462220000'
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -162,9 +162,16 @@ describe 'plausibility' do
162
162
  end
163
163
  it 'is correct for Italian numbers' do
164
164
  Phony.plausible?('+39 06 1234 4567').should be_true
165
+
166
+ Phony.plausible?('+39 035 00000').should be_false
167
+ Phony.plausible?('+39 035 000000').should be_true
168
+ Phony.plausible?('+39 015 8407324').should be_true
169
+
170
+ Phony.plausible?('+39 0471 123 456').should be_true
171
+
172
+ # Mobile
165
173
  Phony.plausible?('+39 335 123 4567').should be_true
166
174
  Phony.plausible?('+39 335 123').should be_false
167
- Phony.plausible?('+39 0471 123 456').should be_true
168
175
  end
169
176
  it 'is correct for German numbers' do
170
177
  Phony.plausible?('+49 209 169 - 0').should be_true # Gelsenkirchen
@@ -339,8 +339,8 @@ describe 'country descriptions' do
339
339
  it_splits '390612341234', ['39', '06', '1234', '1234'] # Roma
340
340
  it_splits '390288838883', ['39', '02', '8883', '8883'] # Milano
341
341
  it_splits '390141595661', ['39', '0141', '595', '661'] # Asti
342
- it_splits '3903123391', ['39', '031', '233', '91'] # Como
343
- it_splits '390909709511', ['39', '090', '970', '9511'] # Barcellona
342
+ it_splits '3903123391', ['39', '031', '23391'] # Como
343
+ it_splits '390909709511', ['39', '090', '9709511'] # Barcellona
344
344
  it_splits '390471811353', ['39', '0471', '811', '353'] # Bolzano
345
345
  end
346
346
  describe 'Japan' do
@@ -34,7 +34,7 @@ describe Phony::Country do
34
34
  end
35
35
  describe 'normalize' do
36
36
  it "should handle ZH" do
37
- @switzerland.normalize('0443643532').should == '41443643532'
37
+ @switzerland.normalize('0443643532').should == '443643532'
38
38
  end
39
39
  end
40
40
  end
@@ -9,7 +9,7 @@ describe Phony do
9
9
  it '' do
10
10
  us = described_class['1']
11
11
  us.plausible?('4159224711').should be_true
12
- us.countrify!('4159224711').should == '14159224711'
12
+ us.normalize('4159224711').should == '4159224711'
13
13
  end
14
14
  end
15
15
  end
@@ -82,13 +82,13 @@ describe Phony do
82
82
  end
83
83
  describe 'country-based' do
84
84
  it 'normalizes the US correctly' do
85
- Phony["1"].normalize("555 1234567890").should == '15551234567890'
86
- Phony["1"].normalize("+1 555 1234567890").should == '15551234567890'
87
- Phony["1"].normalize("+1 (0) 555 1234567890").should == '15551234567890'
85
+ Phony["1"].normalize("555 1234567890").should == '5551234567890'
86
+ Phony["1"].normalize("+1 555 1234567890").should == '5551234567890'
87
+ Phony["1"].normalize("+1 (0) 555 1234567890").should == '5551234567890'
88
88
  end
89
89
  it 'normalizes Japan correctly' do
90
- Phony["81"].normalize("80 1234 5634").should == '818012345634'
91
- Phony["81"].normalize("+81 80 1234 5634").should == '818012345634'
90
+ Phony["81"].normalize("80 1234 5634").should == '8012345634'
91
+ Phony["81"].normalize("Hello 80 1234 5634").should == '8012345634'
92
92
  end
93
93
  end
94
94
  end
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.4
4
+ version: 2.2.0
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-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-21 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,7 @@ 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
+ - spec/functional/error_spec.rb
75
76
  - spec/functional/normalize_spec.rb
76
77
  - spec/functional/plausibility_spec.rb
77
78
  - spec/lib/phony/countries_spec.rb
@@ -97,22 +98,23 @@ require_paths:
97
98
  - lib
98
99
  required_ruby_version: !ruby/object:Gem::Requirement
99
100
  requirements:
100
- - - ! '>='
101
+ - - ">="
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  requirements:
105
- - - ! '>='
106
+ - - ">="
106
107
  - !ruby/object:Gem::Version
107
108
  version: '0'
108
109
  requirements: []
109
110
  rubyforge_project:
110
- rubygems_version: 2.0.3
111
+ rubygems_version: 2.2.0
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Fast international phone number (E164 standard) normalizing, splitting and
114
115
  formatting.
115
116
  test_files:
117
+ - spec/functional/error_spec.rb
116
118
  - spec/functional/normalize_spec.rb
117
119
  - spec/functional/plausibility_spec.rb
118
120
  - spec/lib/phony/countries_spec.rb