phony 2.14.0 → 2.14.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -373,12 +373,18 @@ describe 'country descriptions' do
373
373
  it_splits '390471811353', ['39', '0471', '811', '353'] # Bolzano
374
374
  end
375
375
  describe 'Japan' do
376
- it_splits '81312345678', %w(81 3 1234 5678)
377
- it_splits '81120123456', %w(81 120 123 456)
378
- it_splits '81111234567', %w(81 11 1234 567)
379
- it_splits '81123123456', %w(81 123 123 456)
380
- it_splits '81126712345', %w(81 1267 123 45)
381
- it_splits '819012345678', %w(81 90 1234 5678)
376
+ it_splits '81312345678', %w(81 3 1234 5678) # Tokyo
377
+ it_splits '81612345678', %w(81 6 1234 5678) # Osaka
378
+ it_splits '81120123456', %w(81 120 123 456) # Freephone
379
+ it_splits '81111234567', %w(81 11 123 4567)
380
+ it_splits '81123123456', %w(81 123 12 3456)
381
+ it_splits '81126712345', %w(81 1267 1 2345)
382
+ it_splits '812012345678', %w(81 20 1234 5678) # Pager(Calling Party Pay)
383
+ it_splits '815012345678', %w(81 50 1234 5678) # IP Telephone
384
+ it_splits '816012345678', %w(81 60 1234 5678) # UPT
385
+ it_splits '817012345678', %w(81 70 1234 5678) # PHS
386
+ it_splits '818012345678', %w(81 80 1234 5678) # Cellular
387
+ it_splits '819012345678', %w(81 90 1234 5678) # Cellular
382
388
  end
383
389
  describe 'Kenya' do
384
390
  it_splits '254201234567', ['254', '20', '1234567'] # Nairobi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Fast international phone number (E164 standard) normalizing, splitting
14
14
  and formatting. Lots of formatting options: International (+.., 00..), national
@@ -75,9 +75,6 @@ files:
75
75
  - lib/phony/national_splitters/variable.rb
76
76
  - lib/phony/trunk_code.rb
77
77
  - lib/phony/vanity.rb
78
- - spec/functional/error_spec.rb
79
- - spec/functional/format_spec.rb
80
- - spec/functional/normalize_spec.rb
81
78
  - spec/functional/plausibility_spec.rb
82
79
  - spec/lib/phony/countries_spec.rb
83
80
  - spec/lib/phony/country_codes_spec.rb
@@ -91,8 +88,6 @@ files:
91
88
  - spec/lib/phony/national_splitters/none_spec.rb
92
89
  - spec/lib/phony/national_splitters/regex_spec.rb
93
90
  - spec/lib/phony/national_splitters/variable_spec.rb
94
- - spec/lib/phony/vanity_spec.rb
95
- - spec/lib/phony_spec.rb
96
91
  homepage: http://github.com/floere/phony
97
92
  licenses:
98
93
  - MIT
@@ -119,9 +114,6 @@ specification_version: 4
119
114
  summary: Fast international phone number (E164 standard) normalizing, splitting and
120
115
  formatting.
121
116
  test_files:
122
- - spec/functional/error_spec.rb
123
- - spec/functional/format_spec.rb
124
- - spec/functional/normalize_spec.rb
125
117
  - spec/functional/plausibility_spec.rb
126
118
  - spec/lib/phony/countries_spec.rb
127
119
  - spec/lib/phony/country_codes_spec.rb
@@ -135,5 +127,3 @@ test_files:
135
127
  - spec/lib/phony/national_splitters/none_spec.rb
136
128
  - spec/lib/phony/national_splitters/regex_spec.rb
137
129
  - spec/lib/phony/national_splitters/variable_spec.rb
138
- - spec/lib/phony/vanity_spec.rb
139
- - spec/lib/phony_spec.rb
@@ -1,22 +0,0 @@
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
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # This is a very helpful page for phone number formatting:
4
- # http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers
5
- #
6
- describe 'Phony#format' do
7
-
8
- describe 'cases' do
9
- describe 'Exceptions' do
10
- it 'raises on nil' do
11
- expect {
12
- Phony.format nil
13
- }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.format(number).')
14
- end
15
- end
16
-
17
- describe 'Templates' do
18
- it 'handles a basic template correctly' do
19
- Phony.format('41443643532', :format => 'A%{cc}B%{trunk}C%{ndc}D%{local}').should eql 'A41B0C44D364 35 32'
20
- end
21
- it 'handles a funky template correctly' do
22
- Phony.format('41443643532', :format => '%{local} %{ndc} %{trunk} %{cc}', :local_spaces => '').should eql '3643532 44 0 41'
23
- end
24
- it 'handles local_spaces correctly' do
25
- Phony.format('41443643532', :format => 'A%{cc}B%{ndc}C%{local}', :local_spaces => '/').should eql 'A41B44C364/35/32'
26
- end
27
- it 'handles a Russian example correctly' do
28
- # https://github.com/floere/phony/issues/214
29
- Phony.format('71234567890', :format => '+%{cc} (%{trunk}%{ndc}) %{local}', :local_spaces => '-').should eql '+7 (8123) 45-67890'
30
- end
31
- it 'handles an American example correctly' do
32
- Phony.format('13015550100', :format => '+%{cc} %{trunk}%{ndc} %{local}', :local_spaces => '-').should eql '+1 301 555-0100'
33
- end
34
- end
35
-
36
- def self.for_each_from tsv_file_name
37
- require 'csv'
38
- describe "from file #{tsv_file_name}" do
39
- CSV.open(tsv_file_name, headers: true, col_sep: "\t").each.with_index do |row, index|
40
- country, expected, original, format, spaces, local_spaces = *row.
41
- values_at('Country', 'Expected', 'Original', 'Format', 'Spaces', 'Local Spaces')
42
- options = {}
43
- options[:format] = format.to_sym if format
44
- options[:spaces] = spaces.to_sym if spaces
45
- it "(row #{index + 2}) #{country}: #{expected} from #{original} with #{format}, #{spaces}, #{local_spaces}" do
46
- Phony.format(original, options).should eql expected
47
- end
48
- end
49
- end
50
- end
51
-
52
- # Countries.
53
- #
54
- for_each_from 'spec/functional/format.tab'
55
-
56
- describe 'Austria' do
57
- it { Phony.format('43198110').should eql '+43 1 98110' }
58
- it { Phony.format('43198110', :format => :international).should eql '+43 1 98110' }
59
- it { Phony.format('43198110', :format => :international_absolute).should eql '+43 1 98110' }
60
- it { Phony.format('43198110', :format => :international_relative).should eql '0043 1 98110' }
61
- it { Phony.format('43198110', :format => :international, :spaces => '').should eql '+43198110' }
62
- it { Phony.format('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110' }
63
- it { Phony.format('43198110', :format => :international_relative, :spaces => '').should eql '0043198110' }
64
- it { Phony.format('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110' }
65
- it { Phony.format('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110' }
66
- it { Phony.format('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110' }
67
- it { Phony.format('43198110', :format => :national).should eql '01 98110' }
68
- end
69
- describe 'Denmark' do
70
- it { Phony.format('4540506070', format: :national).should eql '40 50 60 70' }
71
- end
72
- describe 'France' do
73
- it { Phony.format('33142278186', :format => :+).should eql '+33 1 42 27 81 86' }
74
- it { Phony.format('33142278186', :format => :+, :spaces => '').should eql '+33142278186' }
75
- it { Phony.format('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86' }
76
- end
77
- describe 'India' do
78
- it { Phony.format('914433993939').should eql '+91 44 339 93 939' }
79
- end
80
- describe 'Italy' do
81
- it { Phony.format('393333337647', :format => :international).should eql '+39 333 333 7647' }
82
- it { Phony.format('390108480161', :format => :international).should eql '+39 010 8480161' }
83
- it { Phony.format('393333337647', :format => :national).should eql '333 333 7647' }
84
- it { Phony.format('390108480161', :format => :national).should eql '010 8480161' }
85
- end
86
- describe 'Liechtenstein' do
87
- it { Phony.format('4233841148', :format => :international_relative).should eql '00423 384 11 48' }
88
- it { Phony.format('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148' }
89
- it { Phony.format('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48' }
90
- end
91
- describe 'NANP' do
92
- it { Phony.format('18705551122').should eql '+1 (870) 555-1122' }
93
- it { Phony.format('18091231234', :format => :international).should eql '+1 (809) 123-1234' }
94
- it { Phony.format('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234' }
95
- # Gets a trunk code.
96
- it { Phony.format('14152223333', :format => :national).should eql '(415) 222-3333' }
97
- # Does not show a trunk code.
98
- it { Phony.format('14152223333', :format => :national).should eql '(415) 222-3333' }
99
- it { Phony.format('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234' }
100
- it { Phony.format('14159224711', :format => :national).should eql '(415) 922-4711' }
101
- # With forced trunk.
102
- it { Phony.format('14159224711', :format => :national, :trunk => true).should eql '1 (415) 922-4711' }
103
- it { Phony.format('14159224711', :format => :national, :trunk => false).should eql '(415) 922-4711' }
104
- # With forced parentheses.
105
- it { Phony.format('14159224711', :format => :national, :parentheses => true).should eql '(415) 922-4711' }
106
- it { Phony.format('14159224711', :format => :national, :parentheses => false).should eql '415 922-4711' }
107
- end
108
- describe 'Netherlands' do
109
- it { Phony.format('311012341234', :format => :national).should eql '010 123 41234' }
110
- # With forced trunk.
111
- it { Phony.format('311012341234', :format => :national, :trunk => true).should eql '010 123 41234' }
112
- end
113
- describe 'New Zealand' do
114
- it { Phony.format('6421123456').should eql '+64 21 123 456' }
115
- it { Phony.format('64211234567').should eql '+64 21 123 4567' }
116
- it { Phony.format('642112345678').should eql '+64 21 12 345 678' }
117
- it { Phony.format('6493791234').should eql '+64 9 379 1234' }
118
- end
119
- describe 'Russia' do
120
- it { Phony.format(Phony.normalize('+370 800 12345'), :format => :international).should eql '+370 800 12 345' }
121
- it { Phony.format(Phony.normalize('+7 812 123 4567'), :format => :international).should eql '+7 812 123-45-67' }
122
- it { Phony.format(Phony.normalize('+370 800 12345'), :format => :national).should eql '8800 12 345' }
123
- it { Phony.format(Phony.normalize('+7 812 123 4567'), :format => :national).should eql '8812 123-45-67' }
124
- end
125
- describe 'Switzerland' do
126
- it { Phony.format('41443643532').should eql '+41 44 364 35 32' }
127
- it { Phony.format('41443643532', :format => :national).should eql '044 364 35 32' }
128
- it { Phony.format('41800112233').should eql '+41 800 112 233' }
129
- it { Phony.format('41443643532', :format => :international).should eql '+41 44 364 35 32' }
130
- it { Phony.format('41443643532', :format => :national).should eql '044 364 35 32' }
131
- it { Phony.format('41800112233', :format => :national).should eql '0800 112 233' }
132
- it { Phony.format('41443643532', :format => :local).should eql '364 35 32' }
133
- it { Phony.format('493038625454', :format => :local).should eql '386 25454' }
134
- end
135
- describe 'yet unsupported' do
136
- # formats as a single block
137
- it { Phony.format('88132155605220').should eql '+881 32155605220' }
138
- # formats as a single block, regardless of format
139
- it { Phony.format('8811819372205', :format => :international).should eql '+881 1819372205' }
140
- # formats as a single block, respecting custom spaces
141
- it { Phony.format('8811819372205', :spaces => :-).should eql '+881-1819372205' }
142
- # formats as a single block, even without spaces
143
- it { Phony.format('8811819372205', :spaces => '').should eql '+8811819372205' }
144
- end
145
-
146
- end
147
-
148
- describe 'formatted' do
149
- it 'is an alias of format' do
150
- Phony.formatted('41443643532').should eql '+41 44 364 35 32'
151
- end
152
- end
153
-
154
- end
@@ -1,121 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Phony#normalize' do
4
-
5
- describe 'cases' do
6
-
7
- describe 'regressions' do
8
- it '#151' do
9
- # Normalizes, but this is a non-real case.
10
- #
11
- Phony.normalize('1-111-111-1111').should eql '1111111111'
12
- Phony.normalize('111-111-1111', cc: '1').should eql '1111111111'
13
- end
14
- end
15
-
16
- it 'handles the US (with cc) correctly' do
17
- Phony.normalize('+1 724 999 9999').should eql '17249999999'
18
- end
19
- it 'handles the Dutch number (without US cc) correctly' do
20
- Phony.normalize('310 5552121').should eql '315552121'
21
- end
22
- it 'handles the US (with cc and cc option) correctly' do
23
- Phony.normalize('+1 724 999 9999', cc: '1').should eql '17249999999'
24
- end
25
- it 'handles the US (without cc) correctly' do
26
- Phony.normalize('(310) 555-2121', cc: '1').should eql '13105552121'
27
- end
28
- it 'handles a German number with extra (0)' do
29
- Phony.normalize('+49 (0) 209 22 33 44 55').should eql '4920922334455'
30
- end
31
- it 'handles a German number with extra 0' do
32
- Phony.normalize('+49 0 209 22 33 44 55').should eql '4920922334455'
33
- end
34
- it 'handles Cambodian numbers with an extra 0' do
35
- Phony.normalize('+855012239134').should eql "85512239134"
36
- end
37
- it 'should normalize a too short number' do
38
- Phony.normalize('+972').should eql '972'
39
- end
40
- it 'should normalize an already normalized number' do
41
- Phony.normalize('41443643533').should eql '41443643533'
42
- end
43
- it 'should normalize a format number' do
44
- Phony.normalize('+41 44 364 35 33').should eql '41443643533'
45
- end
46
- it 'should normalize a 00 number' do
47
- Phony.normalize('0041 44 364 35 33').should eql '41443643533'
48
- end
49
- it 'should normalize a service number' do
50
- Phony.normalize('+41 800 11 22 33').should eql '41800112233'
51
- end
52
- it 'should remove characters from the number' do
53
- Phony.normalize('John: +41 44 364 35 33').should eql '41443643533'
54
- end
55
- it 'should normalize one of these crazy american numbers' do
56
- Phony.normalize('1 (703) 451-5115').should eql '17034515115'
57
- end
58
- it 'should normalize another one of these crazy american numbers' do
59
- Phony.normalize('1-888-407-4747').should eql '18884074747'
60
- end
61
- it 'should normalize a number with colons' do
62
- Phony.normalize('1.906.387.1698').should eql '19063871698'
63
- end
64
- it 'should normalize a number with erroneous zero inside' do
65
- Phony.normalize('+410443643533').should eql '41443643533'
66
- end
67
- it 'should not normalize a number with a correct zero inside' do
68
- Phony.normalize('+390909709511').should eql '390909709511'
69
- end
70
-
71
- it "handles completely crazy 'numbers'" do
72
- Phony.normalize('Hello, I am Cora, the 41th parrot, and 44 is my 364 times 35 funky number. 32.').should eql '41443643532'
73
- end
74
-
75
- context 'special trunk prefixes are not handled' do
76
- it 'normalizes Hungary' do
77
- Phony.normalize('36 0630245506').should eql '360630245506'
78
- end
79
- it 'normalizes Russia' do
80
- Phony.normalize('7 8 342 1234567').should eql '783421234567'
81
- end
82
- it 'normalizes Lithuania' do
83
- Phony.normalize('370 8 5 1234567').should eql '370851234567'
84
- end
85
- it 'normalizes Belarus' do
86
- Phony.normalize('375 152450911').should eql '375152450911'
87
- end
88
- end
89
-
90
- describe 'exceptions' do
91
- it 'raises on nil' do
92
- expect {
93
- Phony.normalize nil
94
- }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.normalize(number).')
95
- end
96
- it 'raises if number starts with reserved zero code' do
97
- expect do
98
- Phony.normalize '+00 00 00 00 01'
99
- end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
100
- end
101
- it 'raises a nice error message' do
102
- expect do
103
- Phony.normalize 'test'
104
- end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
105
- end
106
- end
107
-
108
- describe 'country-based' do
109
- it 'normalizes the US correctly' do
110
- Phony["1"].normalize("555 1234567890").should eql '5551234567890'
111
- Phony["1"].normalize("+1 555 1234567890").should eql '5551234567890'
112
- Phony["1"].normalize("+1 (0) 555 1234567890").should eql '5551234567890'
113
- end
114
- it 'normalizes Japan correctly' do
115
- Phony["81"].normalize("80 1234 5634").should eql '8012345634'
116
- Phony["81"].normalize("Hello 80 1234 5634").should eql '8012345634'
117
- end
118
- end
119
- end
120
-
121
- end
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- describe Phony::Vanity do
6
-
7
- describe "vanity?" do
8
- it 'recognizes a vanity number' do
9
- Phony::Vanity.vanity?('800HELLOWORLD').should == true
10
- end
11
- it 'recognizes a non vanity number' do
12
- Phony::Vanity.vanity?('444443322').should == false
13
- end
14
- end
15
-
16
- describe "replace" do
17
- it 'replaces all characters' do
18
- Phony::Vanity.replace('0123456789abcdefghijklmnopqrstuvwxyz').should == '012345678922233344455566677778889999'
19
- end
20
- end
21
-
22
- describe 'mapping' do
23
- it 'caches' do
24
- Phony::Vanity.mapping.should equal(Phony::Vanity.mapping)
25
- end
26
- it 'returns the right thing' do
27
- Phony::Vanity.mapping.should == [
28
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.freeze,
29
- '2223334445556667777888999922233344455566677778889999'.freeze
30
- ]
31
- end
32
- end
33
-
34
- end
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- describe Phony do
6
-
7
- describe 'regression' do
8
- it 'best effort #152' do
9
- described_class.split('39694805123').should eql ['39', '694805123', []]
10
- described_class.format('39694805123').should eql '+39 694805123 '
11
- end
12
- end
13
-
14
- describe 'OO interface' do
15
- describe '[]' do
16
- it '' do
17
- us = described_class['1']
18
- us.plausible?('4159224711').should be_true
19
- us.normalize('4159224711').should eql '4159224711'
20
- end
21
- end
22
- end
23
-
24
- context 'minimal cases' do
25
- context 'splitting' do
26
- describe 'exceptions' do
27
- it 'should raise on split nil' do
28
- expect {
29
- Phony.split nil
30
- }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.split(number).')
31
- end
32
- end
33
- it 'handles completely missing numbers well enough' do
34
- Phony.split('4144').should eql ['41', '44', '']
35
- end
36
- it 'handles a missing number part' do
37
- Phony.split('4144364').should eql ['41', '44', '364']
38
- end
39
- it 'handles a missing number part' do
40
- Phony.split('414436435').should eql ['41', '44', '364', '35']
41
- end
42
- end
43
- context 'formatting' do
44
- it 'handles completely missing numbers well enough' do
45
- Phony.format('4144').should eql '+41 44 '
46
- end
47
- it 'handles a missing number part' do
48
- Phony.format('4144364').should eql '+41 44 364'
49
- end
50
- it 'handles a missing number part' do
51
- Phony.format('414436435').should eql '+41 44 364 35'
52
- end
53
- end
54
- context "'unsupported' countries" do
55
- it 'handles formatting' do
56
- Phony.format('88132155605220').should eql '+881 32155605220'
57
- end
58
- it 'handles normalizing' do
59
- Phony.normalize('+881-321 5560 5220').should eql '88132155605220'
60
- end
61
- end
62
- end
63
-
64
- context 'speed' do
65
- before(:each) do
66
- @phone_numbers = [
67
- '41443643532',
68
- '18091231234',
69
- '43198110',
70
- '33142278186',
71
- '4233841148'
72
- ]
73
- end
74
- describe 'split' do
75
- it 'is fast' do
76
- number = @phone_numbers.first
77
- performance_of { Phony.split(number) }.should < 0.00005
78
- end
79
- it 'is fast' do
80
- performance_of { @phone_numbers.each { |number| Phony.split(number) } }.should < 0.00015
81
- end
82
- end
83
- describe 'normalize' do
84
- it 'is fast' do
85
- number = @phone_numbers.first
86
- performance_of { Phony.normalize(number) }.should < 0.0001
87
- end
88
- it 'is fast' do
89
- performance_of { @phone_numbers.each { |number| Phony.normalize(number) } }.should < 0.00016
90
- end
91
- end
92
- describe 'format' do
93
- it 'is fast' do
94
- number = @phone_numbers.first
95
- performance_of { Phony.format(number) }.should < 0.000075
96
- end
97
- it 'is fast' do
98
- performance_of { @phone_numbers.each { |number| Phony.format(number) } }.should < 0.00016
99
- end
100
- end
101
- end
102
-
103
- describe 'vanity' do
104
- describe 'vanity_number?' do
105
- it {Phony.vanity?('41800 WEGGLI').should be_true}
106
- it {Phony.vanity?('41800WEGGLI').should be_true}
107
- it {Phony.vanity?('41848 SUCCESSMATCH').should be_true}
108
- it {Phony.vanity?('4180 NO NO NO').should be_false}
109
- it {Phony.vanity?('41900 KURZ').should be_false}
110
- it {Phony.vanity?('41 44 364 35 32').should be_false}
111
- end
112
-
113
- describe 'vanity_to_number' do
114
- it {Phony.vanity_to_number('41800WEGGLI').should eql '41800934454'}
115
- it {Phony.vanity_to_number('41800weggli').should eql '41800934454'}
116
- # it {Phony.vanity_to_number('41800SUCCESSMATCH').should eql '41800782237'} # Cut off according to the swiss norms.
117
- it {Phony.vanity_to_number('41800SUCCESSMATCH').should eql '41800782237762824'} # Allow for call-through numbers (>= 1.6.0)
118
- it {Phony.vanity_to_number('4180BLA').should eql '4180252'} # Does not check for validity of number.
119
- end
120
- end
121
-
122
- end