phony 2.18.3 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -0
  3. data/lib/phony/config.rb +25 -26
  4. data/lib/phony/countries/argentina.rb +352 -0
  5. data/lib/phony/countries/austria.rb +73 -74
  6. data/lib/phony/countries/bangladesh.rb +27 -28
  7. data/lib/phony/countries/belarus.rb +110 -111
  8. data/lib/phony/countries/brazil.rb +93 -93
  9. data/lib/phony/countries/cambodia.rb +10 -14
  10. data/lib/phony/countries/china.rb +22 -18
  11. data/lib/phony/countries/croatia.rb +6 -5
  12. data/lib/phony/countries/georgia.rb +84 -84
  13. data/lib/phony/countries/germany.rb +4067 -4068
  14. data/lib/phony/countries/guinea.rb +8 -8
  15. data/lib/phony/countries/india.rb +31 -34
  16. data/lib/phony/countries/indonesia.rb +57 -46
  17. data/lib/phony/countries/ireland.rb +10 -9
  18. data/lib/phony/countries/italy.rb +79 -60
  19. data/lib/phony/countries/japan.rb +456 -406
  20. data/lib/phony/countries/kyrgyzstan.rb +109 -109
  21. data/lib/phony/countries/latvia.rb +34 -34
  22. data/lib/phony/countries/libya.rb +109 -107
  23. data/lib/phony/countries/malaysia.rb +12 -12
  24. data/lib/phony/countries/moldova.rb +42 -42
  25. data/lib/phony/countries/montenegro.rb +24 -20
  26. data/lib/phony/countries/myanmar.rb +39 -39
  27. data/lib/phony/countries/namibia.rb +35 -29
  28. data/lib/phony/countries/nepal.rb +60 -62
  29. data/lib/phony/countries/netherlands.rb +13 -13
  30. data/lib/phony/countries/pakistan.rb +135 -111
  31. data/lib/phony/countries/paraguay.rb +135 -135
  32. data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +125 -128
  33. data/lib/phony/countries/saudi_arabia.rb +5 -5
  34. data/lib/phony/countries/serbia.rb +48 -36
  35. data/lib/phony/countries/somalia.rb +18 -18
  36. data/lib/phony/countries/south_korea.rb +16 -13
  37. data/lib/phony/countries/sweden.rb +356 -48
  38. data/lib/phony/countries/taiwan.rb +20 -18
  39. data/lib/phony/countries/tajikistan.rb +70 -70
  40. data/lib/phony/countries/turkmenistan.rb +65 -65
  41. data/lib/phony/countries/ukraine.rb +607 -607
  42. data/lib/phony/countries/united_kingdom.rb +66 -66
  43. data/lib/phony/countries/uruguay.rb +40 -41
  44. data/lib/phony/countries/vietnam.rb +20 -14
  45. data/lib/phony/countries/zimbabwe.rb +31 -31
  46. data/lib/phony/countries.rb +509 -453
  47. data/lib/phony/country.rb +50 -44
  48. data/lib/phony/country_codes.rb +77 -57
  49. data/lib/phony/dsl.rb +25 -28
  50. data/lib/phony/local_splitters/fixed.rb +24 -29
  51. data/lib/phony/local_splitters/regex.rb +30 -31
  52. data/lib/phony/national_code.rb +7 -10
  53. data/lib/phony/national_splitters/default.rb +9 -11
  54. data/lib/phony/national_splitters/dsl.rb +8 -18
  55. data/lib/phony/national_splitters/fixed.rb +12 -15
  56. data/lib/phony/national_splitters/none.rb +8 -14
  57. data/lib/phony/national_splitters/regex.rb +13 -17
  58. data/lib/phony/national_splitters/variable.rb +37 -38
  59. data/lib/phony/trunk_code.rb +23 -23
  60. data/lib/phony/vanity.rb +12 -13
  61. data/lib/phony.rb +84 -83
  62. metadata +14 -45
  63. data/README.textile +0 -112
  64. data/spec/functional/config_spec.rb +0 -44
  65. data/spec/functional/plausibility_spec.rb +0 -608
  66. data/spec/lib/phony/countries_spec.rb +0 -1391
  67. data/spec/lib/phony/country_codes_spec.rb +0 -203
  68. data/spec/lib/phony/country_spec.rb +0 -84
  69. data/spec/lib/phony/dsl_spec.rb +0 -24
  70. data/spec/lib/phony/local_splitters/fixed_spec.rb +0 -56
  71. data/spec/lib/phony/local_splitters/regex_spec.rb +0 -97
  72. data/spec/lib/phony/national_code_spec.rb +0 -91
  73. data/spec/lib/phony/national_splitters/default_spec.rb +0 -34
  74. data/spec/lib/phony/national_splitters/fixed_spec.rb +0 -49
  75. data/spec/lib/phony/national_splitters/none_spec.rb +0 -28
  76. data/spec/lib/phony/national_splitters/regex_spec.rb +0 -23
  77. data/spec/lib/phony/national_splitters/variable_spec.rb +0 -39
  78. data/spec/lib/phony/vanity_spec.rb +0 -30
  79. data/spec/lib/phony_spec.rb +0 -70
@@ -1,203 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::CountryCodes do
4
-
5
- before(:all) do
6
- @countries = Phony::CountryCodes.instance
7
- end
8
-
9
- describe '#[]' do
10
- it 'returns a country' do
11
- @countries['41'].class.should eql Phony::Country
12
- end
13
- end
14
-
15
- describe '#country_for' do
16
- it 'returns a country' do
17
- @countries.send(:country_for, '41').class.should eql Phony::Country
18
- end
19
- end
20
-
21
- describe '#countrify' do
22
- it 'returns a country' do
23
- @countries.send(:countrify, '441231212', '41').should eql '41441231212'
24
- end
25
- end
26
- describe '#countrify!' do
27
- it 'in-place replaces the number' do
28
- number = '441231212'
29
- @countries.send(:countrify!, number, '41').should eql number
30
-
31
- number.should == '41441231212'
32
- end
33
- end
34
-
35
- describe '#vanity?' do
36
- it 'returns true if so' do
37
- @countries.vanity?('1800HELLOES').should eql true
38
- end
39
- it 'returns false if not' do
40
- @countries.vanity?('18001234567').should eql false
41
- end
42
- end
43
-
44
- describe 'normalize' do
45
- it 'normalizes correctly' do
46
- @countries.normalize('0041-44-364-35-32').should eql '41443643532'
47
- end
48
- it 'normalizes correctly with CC option' do
49
- @countries.normalize('044-364-35-32', cc: '41').should eql '41443643532'
50
- end
51
-
52
- context 'specific countries' do
53
- it 'handles Congo correctly' do
54
- @countries.normalize('+242 0571 73992').should eql '242057173992'
55
- @countries.normalize('+242 2221 15932').should eql '242222115932'
56
- end
57
- end
58
- end
59
-
60
- describe 'formatted' do
61
- it 'formats correctly' do
62
- @countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
63
- end
64
- it 'formats correctly' do
65
- @countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
66
- end
67
- it 'formats correctly' do
68
- @countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
69
- end
70
- context 'specific' do
71
- it 'formats Ireland correctly' do
72
- @countries.formatted("3533451234", :format => :national).should eql '0345 1234'
73
- end
74
- it 'formats Ireland correctly' do
75
- @countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
76
- end
77
- it 'formats Spain correctly' do
78
- @countries.formatted("34123456789", :format => :national).should eql '123 456 789'
79
- end
80
- it 'formats Cambodia correctly' do
81
- @countries.formatted('85512239123', :format => :national).should eql '012 239 123'
82
- end
83
- it 'formats the US correctly' do
84
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
85
- end
86
- it 'formats the US correctly' do
87
- @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
88
- end
89
- end
90
- context 'default' do
91
- it "should format swiss numbers" do
92
- @countries.formatted('41443643532').should eql '+41 44 364 35 32'
93
- end
94
- it "should format swiss service numbers" do
95
- @countries.formatted('41800112233').should eql '+41 800 112 233'
96
- end
97
- it "should format austrian numbers" do
98
- @countries.formatted('43198110').should eql '+43 1 98110'
99
- end
100
- it "should format american numbers" do
101
- @countries.formatted('18705551122').should eql '+1 (870) 555-1122'
102
- end
103
- it "should format irish numbers" do
104
- @countries.formatted('35311234567').should eql '+353 1 123 4567'
105
- end
106
- end
107
- describe "international" do
108
- it "should format north american numbers" do
109
- @countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
110
- end
111
- it "should format austrian numbers" do
112
- @countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
113
- end
114
- it "should format austrian numbers" do
115
- @countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
116
- end
117
- it "should format french numbers" do
118
- @countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
119
- end
120
- it "should format austrian numbers" do
121
- @countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
122
- end
123
- it 'should format liechtensteiner numbers' do
124
- @countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
125
- end
126
- it "should format irish numbers" do
127
- @countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
128
- end
129
- it "should format luxembourgian numbers" do
130
- @countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
131
- end
132
- it "should format luxembourgian 4-digit ndc numbers" do
133
- @countries.formatted('35226222809', :format => :international).should eql '+352 2622 28 09'
134
- end
135
- it "should format luxembourgian mobile numbers" do
136
- @countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
137
- end
138
- it "should format luxembourgian city numbers" do
139
- @countries.formatted('3524123456', :format => :international).should eql '+352 41 23 45 6'
140
- end
141
- it "should format luxembourgian machine to machine numbers" do
142
- @countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
143
- end
144
- it "should format luxembourgian numbers" do
145
- @countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
146
- end
147
- it "should format luxembourgian numbers" do
148
- @countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
149
- end
150
- it "should format nigerian numbers" do
151
- @countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
152
- end
153
- it "should format nigerian mobile numbers" do
154
- @countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
155
- end
156
- context 'with no spaces' do
157
- it "should format north american numbers" do
158
- Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234'
159
- end
160
- it "should format austrian numbers" do
161
- Phony.formatted('43198110', :format => :international, :spaces => '').should eql '+43198110'
162
- end
163
- it "should format austrian numbers" do
164
- Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110'
165
- end
166
- it "should format french numbers" do
167
- Phony.formatted('33142278186', :format => :+, :spaces => '').should eql '+33142278186'
168
- end
169
- it "should format austrian numbers" do
170
- Phony.formatted('43198110', :format => :international_relative, :spaces => '').should eql '0043198110'
171
- end
172
- it 'should format liechtensteiner numbers' do
173
- Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148'
174
- end
175
- end
176
- context 'with special spaces' do
177
- it "should format swiss numbers" do
178
- Phony.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
179
- end
180
- it "should format north american numbers" do
181
- Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234'
182
- end
183
- it "should format austrian numbers" do
184
- Phony.formatted('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
185
- end
186
- it "should format austrian numbers" do
187
- Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110'
188
- end
189
- it "should format french numbers" do
190
- Phony.formatted('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86'
191
- end
192
- it "should format austrian numbers" do
193
- Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110'
194
- end
195
- it 'should format liechtensteiner numbers' do
196
- Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48'
197
- end
198
-
199
- end
200
- end
201
- end
202
-
203
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::Country do
4
-
5
- describe 'general' do
6
- let(:country) do
7
- national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
8
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
9
- national_code = Phony::NationalCode.new national_splitter, local_splitter
10
-
11
- Phony::Country.new national_code
12
- end
13
- describe '#clean' do
14
- it 'cleans the number' do
15
- country.clean('+41-44-123-12-12').should eql '41441231212'
16
- end
17
- end
18
- describe '#vanity_to_number' do
19
- it 'turns the vanity number into a number' do
20
- country.vanity_to_number('1-800-HELLO').should eql '1-800-43556'
21
- end
22
- end
23
- end
24
-
25
- context 'regression' do
26
- describe 'iceland' do
27
- let(:country) do
28
- national_splitter = Phony::NationalSplitters::None.instance_for
29
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
30
-
31
- national_code = Phony::NationalCode.new national_splitter, local_splitter
32
- described_class.new national_code
33
- end
34
- it 'splits correctly' do
35
- country.split('112').should == [nil, false, '112']
36
- end
37
- end
38
- end
39
-
40
- context "without special cases (with switzerland)" do
41
- let(:country) do
42
- national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
43
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
44
- national_code = Phony::NationalCode.new national_splitter, local_splitter
45
-
46
- Phony::Country.new national_code
47
- end
48
-
49
- describe "split" do
50
- it "should handle ZH" do
51
- country.split('443643532').should == [nil, '44', '364', '35', '32']
52
- end
53
- end
54
- describe 'normalize' do
55
- it "should handle ZH" do
56
- country.normalize('0443643532').should == '443643532'
57
- end
58
- end
59
- end
60
-
61
- context "without special cases" do
62
- let(:country) do
63
- special_national_splitter = Phony::NationalSplitters::Variable.new nil, ['800']
64
- special_local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 3]
65
- special_code = Phony::NationalCode.new special_national_splitter, special_local_splitter
66
-
67
- national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
68
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
69
- national_code = Phony::NationalCode.new national_splitter, local_splitter
70
-
71
- Phony::Country.new special_code, national_code
72
- end
73
-
74
- describe "split" do
75
- it "should handle ZH" do
76
- country.split('443643532').should == [nil, '44', '364', '35', '32']
77
- end
78
- it "should handle 800" do
79
- country.split('800333666').should == [nil, '800', '333', '666']
80
- end
81
- end
82
- end
83
-
84
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- describe Phony::DSL do
6
-
7
- let(:dsl) { described_class.new }
8
-
9
- it 'has a todo' do
10
- Phony.define do
11
- todo.split("123456789012345").should == [nil, false, '123456789012345']
12
- end
13
- end
14
-
15
- describe 'match' do
16
- it 'checks for ( in regex' do
17
- expect { dsl.match(/123/) }.to raise_error("Regexp /123/ needs a group in it that defines which digits belong to the NDC.")
18
- end
19
- it 'should return a Phony::NationalSplitters::Regex' do
20
- dsl.match(/(123)/).class.name.should == Phony::NationalSplitters::Regex.name
21
- end
22
- end
23
-
24
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::LocalSplitters::Fixed do
4
-
5
- describe 'instance_for' do
6
- it 'caches' do
7
- described_class.instance_for([3,2,2]).should equal(described_class.instance_for([3,2,2]))
8
- end
9
- it 'caches correctly' do
10
- described_class.instance_for([1,2,3]).should_not equal(described_class.instance_for([9,9,9]))
11
- end
12
- it 'caches correctly' do
13
- described_class.instance_for.should equal(described_class.instance_for)
14
- end
15
- end
16
-
17
- describe 'split' do
18
- context "without format" do
19
- before(:each) do
20
- @splitter = described_class.new
21
- end
22
- it 'splits correctly' do
23
- @splitter.split('3643532').should == ['364','35','32']
24
- end
25
- it 'splits correctly even when the number is too long (but leniently)' do
26
- @splitter.split('3643532111').should == ['364','35','32111']
27
- end
28
- it 'splits correctly even when the number is too short' do
29
- @splitter.split('364353').should == ['364','35','3']
30
- end
31
- end
32
- context "with format" do
33
- before(:each) do
34
- @splitter = described_class.new [3, 2, 2]
35
- end
36
- it 'splits correctly' do
37
- @splitter.split('3643532').should == ['364','35','32']
38
- end
39
- it 'splits correctly even when the number is too long (but leniently)' do
40
- @splitter.split('3643532111').should == ['364','35','32111']
41
- end
42
- it 'splits correctly even when the number is too short' do
43
- @splitter.split('364353').should == ['364','35','3']
44
- end
45
- end
46
- context "with hard number (iceland regression)" do
47
- before(:each) do
48
- @splitter = described_class.new [3, 4]
49
- end
50
- it 'splits correctly' do
51
- @splitter.split('112').should == ['112']
52
- end
53
- end
54
- end
55
-
56
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- main = self
4
-
5
- describe Phony::LocalSplitters::Regex do
6
-
7
- before do
8
- load 'spec_helper_extensions.rb'
9
- main.send :include, SpecHelperExtensions
10
- end
11
-
12
- describe 'instance_for' do
13
- it 'does not cache' do
14
- described_class.instance_for({}).should_not equal(described_class.instance_for({}))
15
- end
16
- end
17
-
18
- describe 'split' do
19
- before(:each) do
20
- # Norway as example.
21
- #
22
- @splitter = described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
23
- end
24
- it 'splits a number correctly' do
25
- @splitter.split('21234567').should == ['21','23','45','67']
26
- end
27
- it 'splits a number correctly' do
28
- @splitter.split('31234567').should == ['31','23','45','67']
29
- end
30
- it 'splits a number correctly' do
31
- @splitter.split('41234567').should == ['412','34','567']
32
- end
33
- it 'splits a number correctly' do
34
- @splitter.split('51234567').should == ['51','23','45','67']
35
- end
36
- it 'splits a number correctly' do
37
- @splitter.split('61234567').should == ['61','23','45','67']
38
- end
39
- it 'splits a number correctly' do
40
- @splitter.split('71234567').should == ['71','23','45','67']
41
- end
42
- it 'splits a number correctly' do
43
- @splitter.split('81234567').should == ['812','34','567']
44
- end
45
- it 'splits a number correctly' do
46
- @splitter.split('91234567').should == ['912','34','567']
47
- end
48
- it 'splits it fast' do
49
- performance_of { @splitter.split('21234567').should == ['21','23','45','67'] }.should < 0.00005
50
- end
51
- it 'splits it fast' do
52
- performance_of { @splitter.split('91234567').should == ['912','34','567'] }.should < 0.00004
53
- end
54
- end
55
-
56
- describe 'plausible?' do
57
- let(:number) {['123', '456']}
58
- let(:result) { local_splitter.plausible?(number) }
59
-
60
- context 'Local splitter without mappings' do
61
- let(:local_splitter) { described_class.instance_for({})}
62
- it 'returns false' do
63
- result.should be_falsey
64
- end
65
- end
66
-
67
- context 'Mapping does not exist for a number' do
68
- let(:local_splitter) { described_class.instance_for(/\A5/ => [1,2,3])}
69
- it 'returns false' do
70
- result.should be_falsey
71
- end
72
- end
73
-
74
- context "Mapping exists, but the length is greater" do
75
- let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2])}
76
- it 'returns false' do
77
- result.should be_falsey
78
- end
79
- end
80
-
81
- context "Mapping exists, but the length is less" do
82
- let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,3])}
83
- it 'returns false' do
84
- result.should be_falsey
85
- end
86
- end
87
-
88
- context 'Mapping exists and the length is equal' do
89
- let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,2])}
90
- it 'returns true' do
91
- result.should be_truthy
92
- end
93
- end
94
-
95
- end
96
-
97
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::NationalCode do
4
-
5
- describe 'split' do
6
- context 'regression' do
7
- describe 'iceland' do
8
- before(:each) do
9
- national_splitter = Phony::NationalSplitters::None.instance_for
10
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
11
-
12
- @national = Phony::NationalCode.new national_splitter, local_splitter
13
- end
14
- it 'splits correctly' do
15
- @national.split('112').should == [nil, false, '112']
16
- end
17
- end
18
- end
19
- context 'with fixed ndc (Swiss)' do
20
- before(:each) do
21
- national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
22
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
23
-
24
- @national = Phony::NationalCode.new national_splitter, local_splitter
25
- end
26
- it 'splits correctly' do
27
- @national.split('443643532').should == [nil, '44', '364', '35', '32']
28
- end
29
- it 'splits correctly' do
30
- @national.split('44364353').should == [nil, '44', '364', '35', '3']
31
- end
32
- it 'normalizes correctly' do
33
- @national.normalize('044364353').should == '44364353'
34
- end
35
- it 'normalizes correctly' do
36
- @national.normalize('44364353').should == '44364353'
37
- end
38
- end
39
- context 'with fixed ndc (French)' do
40
- before(:each) do
41
- national_splitter = Phony::NationalSplitters::Fixed.instance_for 1
42
- local_splitter = Phony::LocalSplitters::Fixed.instance_for [2, 2, 2, 2]
43
-
44
- @national = Phony::NationalCode.new national_splitter, local_splitter
45
- end
46
- it 'splits correctly' do
47
- @national.split('142278186').should == [nil, '1', '42', '27', '81', '86']
48
- end
49
- it 'splits correctly' do
50
- @national.split('14227818').should == [nil, '1', '42', '27', '81', '8']
51
- end
52
- it 'normalizes correctly' do
53
- @national.normalize('0142278186').should == '142278186'
54
- end
55
- it 'normalizes correctly' do
56
- @national.normalize('142278186').should == '142278186'
57
- end
58
- end
59
- # context 'normalizing' do
60
- # context 'false' do
61
- # before(:each) do
62
- # @national = Phony::NationalCode.new nil, nil, false
63
- # end
64
- # it 'normalizes an italian case correctly' do
65
- # @national.normalize('0909709511').should == '0909709511'
66
- # end
67
- # end
68
- # context 'true' do
69
- # before(:each) do
70
- # national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
71
- # local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
72
- # @national = Phony::NationalCode.new national_splitter, local_splitter, true
73
- # end
74
- # it 'normalizes a swiss case correctly' do
75
- # @national.normalize('044364353').should == '44364353'
76
- # end
77
- # end
78
- # context 'nil (true)' do
79
- # before(:each) do
80
- # national_splitter = Phony::NationalSplitters::Fixed.instance_for 2
81
- # local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
82
- # @national = Phony::NationalCode.new national_splitter, local_splitter, nil
83
- # end
84
- # it 'normalizes a swiss case correctly' do
85
- # @national.normalize('044364353').should == '44364353'
86
- # end
87
- # end
88
- # end
89
- end
90
-
91
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::NationalSplitters::Default do
4
-
5
- describe 'instance_for' do
6
- it 'caches' do
7
- described_class.instance_for.should equal(described_class.instance_for)
8
- end
9
- end
10
-
11
- context 'with instance' do
12
- let(:splitter) { described_class.instance_for }
13
-
14
- describe 'split' do
15
- it 'does only pretend split' do
16
- splitter.split(:anything).should == [nil, :anything]
17
- end
18
- end
19
-
20
- describe 'plausible?' do
21
- it 'is always plausible' do
22
- splitter.plausible?(:anything, :anything).should be_truthy
23
- end
24
- end
25
-
26
- describe 'length' do
27
- it 'needs to be at least 3' do
28
- splitter.length.should == 3
29
- end
30
- end
31
-
32
- end
33
-
34
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::NationalSplitters::Fixed do
4
-
5
- describe 'instance_for' do
6
- it 'caches' do
7
- Phony::NationalSplitters::Fixed.instance_for(3).should equal(Phony::NationalSplitters::Fixed.instance_for(3))
8
- end
9
- it 'caches correctly' do
10
- Phony::NationalSplitters::Fixed.instance_for(1).should_not equal(Phony::NationalSplitters::Fixed.instance_for(2))
11
- end
12
- end
13
-
14
- describe 'split' do
15
- before(:each) do
16
- @splitter = Phony::NationalSplitters::Fixed.new 2
17
- end
18
- it 'splits correctly' do
19
- @splitter.split('443643532').should == [nil, '44', '3643532']
20
- end
21
- it 'splits correctly even when the number is too long' do
22
- @splitter.split('44364353211').should == [nil, '44', '364353211']
23
- end
24
- it 'splits correctly even when the number is too short' do
25
- @splitter.split('443').should == [nil, '44','3']
26
- end
27
- it 'has a length of 2' do
28
- @splitter.length.should == 2
29
- end
30
- end
31
- describe 'split' do
32
- before(:each) do
33
- @splitter = Phony::NationalSplitters::Fixed.new nil
34
- end
35
- it 'splits correctly' do
36
- @splitter.split('443643532').should == [nil, '443643532']
37
- end
38
- it 'splits correctly even when the number is too long' do
39
- @splitter.split('44364353211').should == [nil, '44364353211']
40
- end
41
- it 'splits correctly even when the number is too short' do
42
- @splitter.split('443').should == [nil, '443']
43
- end
44
- it 'has a length of nil' do
45
- @splitter.length.should == nil
46
- end
47
- end
48
-
49
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Phony::NationalSplitters::None do
4
-
5
- describe 'instance_for' do
6
- it 'caches' do
7
- described_class.instance_for.should equal(described_class.instance_for)
8
- end
9
- end
10
-
11
- context 'with instance' do
12
- let(:splitter) { described_class.instance_for }
13
-
14
- describe 'split' do
15
- it 'splits correctly into ndc and rest' do
16
- splitter.split('123456789').should == [nil, false, '123456789']
17
- end
18
- end
19
-
20
- describe 'length' do
21
- it 'is always 0' do
22
- splitter.length.should be_zero
23
- end
24
- end
25
-
26
- end
27
-
28
- end