phony 2.16.4 → 2.20.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/README.textile +34 -6
  3. data/lib/phony/config.rb +91 -0
  4. data/lib/phony/countries/argentina.rb +355 -0
  5. data/lib/phony/countries/austria.rb +4 -2
  6. data/lib/phony/countries/bangladesh.rb +2 -0
  7. data/lib/phony/countries/belarus.rb +2 -0
  8. data/lib/phony/countries/brazil.rb +4 -2
  9. data/lib/phony/countries/cambodia.rb +3 -5
  10. data/lib/phony/countries/china.rb +7 -2
  11. data/lib/phony/countries/croatia.rb +2 -0
  12. data/lib/phony/countries/georgia.rb +2 -0
  13. data/lib/phony/countries/germany.rb +5 -2
  14. data/lib/phony/countries/guinea.rb +8 -5
  15. data/lib/phony/countries/india.rb +2 -0
  16. data/lib/phony/countries/indonesia.rb +2 -0
  17. data/lib/phony/countries/ireland.rb +27 -23
  18. data/lib/phony/countries/italy.rb +40 -18
  19. data/lib/phony/countries/japan.rb +61 -8
  20. data/lib/phony/countries/kyrgyzstan.rb +2 -0
  21. data/lib/phony/countries/latvia.rb +2 -0
  22. data/lib/phony/countries/libya.rb +3 -1
  23. data/lib/phony/countries/malaysia.rb +22 -2
  24. data/lib/phony/countries/moldova.rb +2 -0
  25. data/lib/phony/countries/montenegro.rb +2 -0
  26. data/lib/phony/countries/myanmar.rb +2 -0
  27. data/lib/phony/countries/namibia.rb +2 -0
  28. data/lib/phony/countries/nepal.rb +2 -0
  29. data/lib/phony/countries/netherlands.rb +2 -0
  30. data/lib/phony/countries/pakistan.rb +2 -0
  31. data/lib/phony/countries/paraguay.rb +2 -0
  32. data/lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb +22 -13
  33. data/lib/phony/countries/saudi_arabia.rb +2 -0
  34. data/lib/phony/countries/serbia.rb +7 -1
  35. data/lib/phony/countries/somalia.rb +2 -0
  36. data/lib/phony/countries/south_korea.rb +7 -2
  37. data/lib/phony/countries/sweden.rb +2 -0
  38. data/lib/phony/countries/taiwan.rb +3 -0
  39. data/lib/phony/countries/tajikistan.rb +2 -0
  40. data/lib/phony/countries/turkmenistan.rb +2 -0
  41. data/lib/phony/countries/ukraine.rb +3 -0
  42. data/lib/phony/countries/united_kingdom.rb +5 -2
  43. data/lib/phony/countries/uruguay.rb +2 -0
  44. data/lib/phony/countries/vietnam.rb +93 -93
  45. data/lib/phony/countries/zimbabwe.rb +2 -0
  46. data/lib/phony/countries.rb +142 -64
  47. data/lib/phony/country.rb +15 -3
  48. data/lib/phony/country_codes.rb +16 -3
  49. data/lib/phony/dsl.rb +5 -3
  50. data/lib/phony/local_splitters/fixed.rb +2 -0
  51. data/lib/phony/national_code.rb +1 -1
  52. data/lib/phony/national_splitters/none.rb +1 -3
  53. data/lib/phony/trunk_code.rb +5 -5
  54. data/lib/phony.rb +62 -57
  55. data/spec/functional/config_spec.rb +44 -0
  56. data/spec/functional/plausibility_spec.rb +285 -18
  57. data/spec/lib/phony/countries_spec.rb +140 -39
  58. data/spec/lib/phony/country_codes_spec.rb +82 -58
  59. data/spec/lib/phony/country_spec.rb +29 -9
  60. data/spec/lib/phony/dsl_spec.rb +7 -3
  61. data/spec/lib/phony/local_splitters/regex_spec.rb +19 -15
  62. data/spec/lib/phony/national_code_spec.rb +15 -45
  63. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -16
  64. data/spec/lib/phony/national_splitters/none_spec.rb +3 -3
  65. data/spec/lib/phony/national_splitters/variable_spec.rb +9 -13
  66. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  67. data/spec/lib/phony/vanity_spec.rb +4 -4
  68. data/spec/lib/phony_spec.rb +63 -67
  69. metadata +13 -8
@@ -4,7 +4,7 @@ describe Phony::NationalSplitters::None do
4
4
 
5
5
  describe 'instance_for' do
6
6
  it 'caches' do
7
- described_class.instance_for.should equal(described_class.instance_for)
7
+ expect(described_class.instance_for).to eq described_class.instance_for
8
8
  end
9
9
  end
10
10
 
@@ -13,13 +13,13 @@ describe Phony::NationalSplitters::None do
13
13
 
14
14
  describe 'split' do
15
15
  it 'splits correctly into ndc and rest' do
16
- splitter.split('123456789').should == [nil, false, '123456789']
16
+ expect(splitter.split('123456789')).to eq [nil, false, '123456789']
17
17
  end
18
18
  end
19
19
 
20
20
  describe 'length' do
21
21
  it 'is always 0' do
22
- splitter.length.should be_zero
22
+ expect(splitter.length).to be_zero
23
23
  end
24
24
  end
25
25
 
@@ -4,34 +4,30 @@ describe Phony::NationalSplitters::Variable do
4
4
 
5
5
  describe 'split' do
6
6
  context 'normal' do
7
- before(:each) do
8
- @splitter = Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711']
9
- end
7
+ let(:splitter) { Phony::NationalSplitters::Variable.new 4, ['1', '316', '67', '68', '669', '711'] }
10
8
  it "handles Vienna" do
11
- @splitter.split('198110').should == [nil, '1', '98110']
9
+ expect(splitter.split('198110')).to eq [nil, '1', '98110']
12
10
  end
13
11
  it "handles some mobile services" do
14
- @splitter.split('66914093902').should == [nil, '669', '14093902']
12
+ expect(splitter.split('66914093902')).to eq [nil, '669', '14093902']
15
13
  end
16
14
  it "handles Graz" do
17
- @splitter.split('3161234567891').should == [nil, '316', '1234567891']
15
+ expect(splitter.split('3161234567891')).to eq [nil, '316', '1234567891']
18
16
  end
19
17
  it "handles Rohrau" do
20
- @splitter.split('2164123456789').should == [nil, '2164', '123456789']
18
+ expect(splitter.split('2164123456789')).to eq [nil, '2164', '123456789']
21
19
  end
22
20
  it 'has an NDC length of 3' do
23
- @splitter.length.should == (1..3)
21
+ expect(splitter.length).to eq (1..3)
24
22
  end
25
23
  end
26
24
  context 'special handling for using the variable size splitter for Swiss service numbers' do
27
- before(:each) do
28
- @splitter = Phony::NationalSplitters::Variable.new 2, ['800']
29
- end
25
+ let(:splitter) { Phony::NationalSplitters::Variable.new 2, ['800'] }
30
26
  it "should handle swiss service numbers" do
31
- @splitter.split('800223344').should == [nil, '800', '223344']
27
+ expect(splitter.split('800223344')).to eq [nil, '800', '223344']
32
28
  end
33
29
  it 'has an NDC length of 3' do
34
- @splitter.length.should == (3..3)
30
+ expect(splitter.length).to eq (3..3)
35
31
  end
36
32
  end
37
33
  end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Phony::TrunkCode do
4
+
5
+ describe '#format' do
6
+ it 'is correct' do
7
+ code = described_class.new('0')
8
+ expect(code.format('%s %s')).to eq '0'
9
+ end
10
+ it 'is correct' do
11
+ code = described_class.new('0', format: true)
12
+ expect(code.format('%s %s')).to eq '0'
13
+ end
14
+ it 'is correct' do
15
+ code = described_class.new('0', format: false)
16
+ expect(code.format('%s %s')).to eq nil
17
+ end
18
+ it 'is correct' do
19
+ code = described_class.new('06')
20
+ expect(code.format('%s %s')).to eq '06'
21
+ end
22
+ it 'is correct' do
23
+ code = described_class.new('06', format: true)
24
+ expect(code.format('%s %s')).to eq '06'
25
+ end
26
+ it 'is correct' do
27
+ code = described_class.new('06', format: false)
28
+ expect(code.format('%s %s')).to eq nil
29
+ end
30
+ end
31
+
32
+ describe '#normalize' do
33
+ it 'is correct' do
34
+ code = described_class.new('0')
35
+ expect(code.normalize('0123')).to eq '0123'
36
+ end
37
+ it 'is correct' do
38
+ code = described_class.new('0', normalize: true)
39
+ expect(code.normalize('0123')).to eq '0123'
40
+ end
41
+ it 'is correct' do
42
+ code = described_class.new('0', normalize: false)
43
+ expect(code.normalize('0123')).to eq '0123'
44
+ end
45
+ it 'is correct' do
46
+ code = described_class.new('06')
47
+ expect(code.normalize('06123')).to eq '06123'
48
+ end
49
+ it 'is correct' do
50
+ code = described_class.new('06', normalize: true)
51
+ expect(code.normalize('06123')).to eq '06123'
52
+ end
53
+ it 'is correct' do
54
+ code = described_class.new('06', normalize: false)
55
+ expect(code.normalize('0123')).to eq '0123'
56
+ end
57
+ end
58
+
59
+ describe '#split' do
60
+ it 'is correct' do
61
+ code = described_class.new('0')
62
+ expect(code.split('0123')).to eq [code, '0123']
63
+ end
64
+ it 'is correct' do
65
+ code = described_class.new('0', split: true)
66
+ expect(code.split('0123')).to eq [code, '123']
67
+ end
68
+ it 'is correct' do
69
+ code = described_class.new('0', split: false)
70
+ expect(code.split('0123')).to eq [code, '0123']
71
+ end
72
+ it 'is correct' do
73
+ code = described_class.new('06')
74
+ expect(code.split('06123')).to eq [code, '06123']
75
+ end
76
+ it 'is correct' do
77
+ code = described_class.new('06', split: true)
78
+ expect(code.split('06123')).to eq [code, '123']
79
+ end
80
+ it 'is correct' do
81
+ code = described_class.new('06', split: false)
82
+ expect(code.split('06123')).to eq [code, '06123']
83
+ end
84
+ end
85
+ end
@@ -8,22 +8,22 @@ describe Phony::Vanity do
8
8
 
9
9
  describe '.replace' do
10
10
  it 'replaces letters with digits' do
11
- vanity.replace('1-800-HELLO').should == '1-800-43556'
11
+ expect(vanity.replace('1-800-HELLO')).to eq '1-800-43556'
12
12
  end
13
13
  end
14
14
 
15
15
  describe '.vanity?' do
16
16
  it 'returns true on a vanity number' do
17
- vanity.vanity?('800HELLOES').should == true
17
+ expect(vanity.vanity?('800HELLOES')).to eq true
18
18
  end
19
19
  it 'returns false on a non-vanity number' do
20
- vanity.vanity?('8004355637').should == false
20
+ expect(vanity.vanity?('8004355637')).to eq false
21
21
  end
22
22
  end
23
23
 
24
24
  describe '.normalized' do
25
25
  it 'normalizes the vanity number' do
26
- vanity.normalized('1-800-HELLO').should == '1800HELLO'
26
+ expect(vanity.normalized('1-800-HELLO')).to eq '1800HELLO'
27
27
  end
28
28
  end
29
29
 
@@ -1,74 +1,70 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Phony do
4
-
5
- describe described_class::NormalizationError do
6
- it 'is correctly raised on normalize' do
7
- expect do
8
- described_class.normalize('000')
9
- end.to raise_error(described_class::NormalizationError)
10
- end
11
- it 'is correctly raised on normalize' do
12
- expect do
13
- described_class.normalize('000')
14
- end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
15
- end
16
- it 'is correctly raised on normalize!' do
17
- expect do
18
- described_class.normalize!('000')
19
- end.to raise_error(described_class::NormalizationError)
20
- end
21
- it 'is correctly raised on normalize!' do
22
- expect do
23
- described_class.normalize!('000')
24
- end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
25
- end
3
+ describe Phony::NormalizationError do
4
+ it 'is correctly raised on normalize' do
5
+ expect do
6
+ Phony.normalize('000')
7
+ end.to raise_error(Phony::NormalizationError)
26
8
  end
9
+ it 'is correctly raised on normalize' do
10
+ expect do
11
+ Phony.normalize('000')
12
+ end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
13
+ end
14
+ it 'is correctly raised on normalize!' do
15
+ expect do
16
+ Phony.normalize!('000')
17
+ end.to raise_error(Phony::NormalizationError)
18
+ end
19
+ it 'is correctly raised on normalize!' do
20
+ expect do
21
+ Phony.normalize!('000')
22
+ end.to raise_error(%Q{Phony could not normalize the given number. Is it a phone number?})
23
+ end
24
+ end
25
+
26
+ describe Phony::SplittingError do
27
+ it 'is correctly raised on split' do
28
+ expect do
29
+ Phony.split('000')
30
+ end.to raise_error(Phony::SplittingError)
31
+ end
32
+ it 'is correctly raised on split' do
33
+ expect do
34
+ Phony.split('000')
35
+ end.to raise_error(%Q{Phony could not split the given number. Is "000" a phone number?})
36
+ end
37
+ it 'is correctly raised on split!' do
38
+ expect do
39
+ Phony.split!('000')
40
+ end.to raise_error(Phony::SplittingError)
41
+ end
42
+ it 'is correctly raised on split!' do
43
+ expect do
44
+ Phony.split!('000')
45
+ end.to raise_error(%Q{Phony could not split the given number. Is it a phone number?})
46
+ end
47
+ end
27
48
 
28
- describe described_class::SplittingError do
29
- it 'is correctly raised on split' do
30
- expect do
31
- described_class.split('000')
32
- end.to raise_error(described_class::SplittingError)
33
- end
34
- it 'is correctly raised on split' do
35
- expect do
36
- described_class.split('000')
37
- end.to raise_error(%Q{Phony could not split the given number. Is "000" a phone number?})
38
- end
39
- it 'is correctly raised on split!' do
40
- expect do
41
- described_class.split!('000')
42
- end.to raise_error(described_class::SplittingError)
43
- end
44
- it 'is correctly raised on split!' do
45
- expect do
46
- described_class.split!('000')
47
- end.to raise_error(%Q{Phony could not split the given number. Is it a phone number?})
48
- end
49
+ describe Phony::FormattingError do
50
+ it 'is correctly raised on format' do
51
+ expect do
52
+ Phony.format('000')
53
+ end.to raise_error(Phony::FormattingError)
54
+ end
55
+ it 'is correctly raised on format' do
56
+ expect do
57
+ Phony.format('000')
58
+ end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
59
+ end
60
+ it 'is correctly raised on format!' do
61
+ expect do
62
+ Phony.format!('000')
63
+ end.to raise_error(Phony::FormattingError)
49
64
  end
50
-
51
- describe described_class::FormattingError do
52
- it 'is correctly raised on format' do
53
- expect do
54
- described_class.format('000')
55
- end.to raise_error(described_class::FormattingError)
56
- end
57
- it 'is correctly raised on format' do
58
- expect do
59
- described_class.format('000')
60
- end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
61
- end
62
- it 'is correctly raised on format!' do
63
- expect do
64
- described_class.format!('000')
65
- end.to raise_error(described_class::FormattingError)
66
- end
67
- it 'is correctly raised on format!' do
68
- expect do
69
- described_class.format!('000')
70
- end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
71
- end
65
+ it 'is correctly raised on format!' do
66
+ expect do
67
+ Phony.format!('000')
68
+ end.to raise_error(%Q{Phony could not format the given number. Is it a phone number?})
72
69
  end
73
-
74
70
  end
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.16.4
4
+ version: 2.20.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-31 00:00:00.000000000 Z
11
+ date: 2023-09-06 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
@@ -21,7 +21,9 @@ extra_rdoc_files:
21
21
  files:
22
22
  - README.textile
23
23
  - lib/phony.rb
24
+ - lib/phony/config.rb
24
25
  - lib/phony/countries.rb
26
+ - lib/phony/countries/argentina.rb
25
27
  - lib/phony/countries/austria.rb
26
28
  - lib/phony/countries/bangladesh.rb
27
29
  - lib/phony/countries/belarus.rb
@@ -77,6 +79,7 @@ files:
77
79
  - lib/phony/national_splitters/variable.rb
78
80
  - lib/phony/trunk_code.rb
79
81
  - lib/phony/vanity.rb
82
+ - spec/functional/config_spec.rb
80
83
  - spec/functional/plausibility_spec.rb
81
84
  - spec/lib/phony/countries_spec.rb
82
85
  - spec/lib/phony/country_codes_spec.rb
@@ -90,13 +93,14 @@ files:
90
93
  - spec/lib/phony/national_splitters/none_spec.rb
91
94
  - spec/lib/phony/national_splitters/regex_spec.rb
92
95
  - spec/lib/phony/national_splitters/variable_spec.rb
96
+ - spec/lib/phony/trunk_code_spec.rb
93
97
  - spec/lib/phony/vanity_spec.rb
94
98
  - spec/lib/phony_spec.rb
95
- homepage: http://github.com/floere/phony
99
+ homepage: https://github.com/floere/phony
96
100
  licenses:
97
101
  - MIT
98
102
  metadata: {}
99
- post_install_message:
103
+ post_install_message:
100
104
  rdoc_options: []
101
105
  require_paths:
102
106
  - lib
@@ -111,13 +115,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
115
  - !ruby/object:Gem::Version
112
116
  version: '0'
113
117
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.13
116
- signing_key:
118
+ rubygems_version: 3.4.19
119
+ signing_key:
117
120
  specification_version: 4
118
121
  summary: Fast international phone number (E164 standard) normalizing, splitting and
119
122
  formatting.
120
123
  test_files:
124
+ - spec/functional/config_spec.rb
121
125
  - spec/functional/plausibility_spec.rb
122
126
  - spec/lib/phony/countries_spec.rb
123
127
  - spec/lib/phony/country_codes_spec.rb
@@ -131,5 +135,6 @@ test_files:
131
135
  - spec/lib/phony/national_splitters/none_spec.rb
132
136
  - spec/lib/phony/national_splitters/regex_spec.rb
133
137
  - spec/lib/phony/national_splitters/variable_spec.rb
138
+ - spec/lib/phony/trunk_code_spec.rb
134
139
  - spec/lib/phony/vanity_spec.rb
135
140
  - spec/lib/phony_spec.rb