phony 2.15.40 → 2.15.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 025fd5f44739a955cee2b09ef250e2e820de8ecd
4
- data.tar.gz: fea5fd6630d91521f8dcfaa1f3c0a22fb4025a2f
3
+ metadata.gz: 82b503c2e5f9f3b3a81043a38c68f15552ef5d6b
4
+ data.tar.gz: 9572b6582b657cbefa87f1f516b47e89cc062068
5
5
  SHA512:
6
- metadata.gz: 356f262ce1fc0eb730c0ed00d8c1fb4f09862b96a5afae1bdf6c12e7fe42e7f3b8a9fd86e4fe585d616bb0241038d3fd1c5f87a062f992669902dada5b0a878a
7
- data.tar.gz: 641cec9186c42bb03bae365c8d1a54e20b39d26a3e287dc7134aeb52504e6b2668d766f9bf8f779f272731393ffbc24339f8a6a7bcbe732491865e41143ce2a6
6
+ metadata.gz: 43eef5656724b34b4e9f71201423570572bae9db6b21bdc8bd3a1c5f8d2be58f20533402aa3a2f02447c950160b7146bd62cf3aed04ba8aa9cec64d026d3b6c8
7
+ data.tar.gz: 3031b7bb1f87f64349e123aac3be733f748a9a1d5afa436484bbeeb0fe92b35442cceab3a66119a38fb48b31026aad3decf012efe31fb54f7ca8229473ffe87e
data/lib/phony.rb CHANGED
@@ -77,8 +77,8 @@ module Phony
77
77
  # Phony.normalize("Fnork!") # Raises a Phony::NormalizationError.
78
78
  #
79
79
  class NormalizationError < StandardError
80
- def initialize
81
- super %Q{Phony could not normalize the given number. Is it a phone number?}
80
+ def initialize(input)
81
+ super %Q{Phony could not normalize the given number. Is #{input.inspect} a phone number?}
82
82
  end
83
83
  end
84
84
 
@@ -143,7 +143,7 @@ module Phony
143
143
  def normalize! phone_number, options = {}
144
144
  @codes.normalize phone_number, options
145
145
  rescue
146
- raise NormalizationError.new
146
+ raise NormalizationError.new phone_number
147
147
  end
148
148
 
149
149
  # Splits the phone number into pieces according to the country codes.
@@ -112,8 +112,8 @@ ndcs_with_6_subscriber_digits = %w(3012 3022 3412 3435 3439 3452 3456 3462 3463
112
112
 
113
113
  ndcs_with_7_subscriber_digits = %w(342 343 347 351 383 391 473 495 496 498 499 812 818 831 843 844 846 861 863
114
114
  901 902 903 904 905 906 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
115
- 930 931 932 933 934 936 937 938 950 951 952 953 960 961 962 963 964 965 967 968 980 981 982 983 984 985 987 988
116
- 989 997
115
+ 930 931 932 933 934 936 937 938 950 951 952 953 960 961 962 963 964 965 967 968 969 977 980 981 982 983 984 985
116
+ 987 988 989 996 997 999
117
117
  )
118
118
 
119
119
  Phony.define do
data/lib/phony/vanity.rb CHANGED
@@ -20,7 +20,7 @@ module Phony
20
20
  end
21
21
 
22
22
  # Returns true if there is a character in the number
23
- # after the first four numbers.
23
+ # after the first three numbers.
24
24
  #
25
25
  @@vanity_regexp = /\A\d{3}[a-zA-Z]{6,12}\Z/
26
26
  def self.vanity? number
@@ -594,17 +594,23 @@ describe 'country descriptions' do
594
594
  it_splits '40791231234', ['40', '79', '123', '1234'] # mobile
595
595
  it_splits '40249123123', ['40', '249', '123', '123'] # Olt
596
596
  end
597
+
597
598
  describe 'Russia' do
598
599
  it_splits '78122345678', ['7', '812', '234', '56', '78'] # Russia 3-digit
599
600
  it_splits '74012771077', ['7', '4012', '77', '10', '77'] # Russia 4-digit
600
601
  it_splits '78402411212', ['7', '84024', '1', '12', '12'] # Russia 5-digit
601
- it_splits '79296119119', ['7', '929', '611', '91', '19'] # Russia 3-digit, Megafon Mobile.
602
+ it_splits '79296119119', ['7', '929', '611', '91', '19'] # Russia 3-digit, Megafon Mobile
603
+ it_splits '79691234567', ['7', '969', '123', '45', '67'] # Russia 3-digit, Beeline
604
+ it_splits '79771234567', ['7', '977', '123', '45', '67'] # Russia 3-digit
605
+ it_splits '79961234567', ['7', '996', '123', '45', '67'] # Russia 3-digit
606
+ it_splits '79991234567', ['7', '999', '123', '45', '67'] # Russia 3-digit
602
607
  it_splits '7840121212', ['7', '840', '12', '1212'] # Abhasia
603
608
  it_splits '7799121212', ['7', '799', '12', '1212'] # Kazachstan
604
- it_splits '7995344121212', ['7','995344','12','1212'] # South Osetia
609
+ it_splits '7995344121212', ['7','995344','12','1212'] # South Osetia
605
610
  it_splits '7209175276', ['7', '209', '17', '5276'] # Fantasy number
606
611
  end
607
- describe 'Rwanda' do
612
+
613
+ describe 'Rwanda' do
608
614
  it_splits '250781234567', ['250', '78', '1234567'] # mobile
609
615
  it_splits '250721234567', ['250', '72', '1234567'] # mobile
610
616
  it_splits '250731234567', ['250', '73', '1234567'] # mobile
@@ -5,6 +5,50 @@ describe Phony::CountryCodes do
5
5
  before(:all) do
6
6
  @countries = Phony::CountryCodes.instance
7
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
+ end
8
52
 
9
53
  describe 'formatted' do
10
54
  it 'formats correctly' do
@@ -2,45 +2,64 @@ require 'spec_helper'
2
2
 
3
3
  describe Phony::Country do
4
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
+
5
25
  context 'regression' do
6
26
  describe 'iceland' do
7
- before(:each) do
27
+ let(:country) do
8
28
  national_splitter = Phony::NationalSplitters::None.instance_for
9
29
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 4]
10
30
 
11
31
  national_code = Phony::NationalCode.new national_splitter, local_splitter
12
- @iceland = described_class.new national_code
32
+ described_class.new national_code
13
33
  end
14
34
  it 'splits correctly' do
15
- @iceland.split('112').should == [nil, false, '112']
35
+ country.split('112').should == [nil, false, '112']
16
36
  end
17
37
  end
18
38
  end
19
39
 
20
- context "without special cases" do
21
- before(:each) do
40
+ context "without special cases (with switzerland)" do
41
+ let(:country) do
22
42
  national_splitter = Phony::NationalSplitters::Variable.new 4, ['44']
23
43
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
24
44
  national_code = Phony::NationalCode.new national_splitter, local_splitter
25
45
 
26
- @switzerland = Phony::Country.new national_code
27
- @switzerland.with '41' # TODO Remove this kludge.
46
+ Phony::Country.new national_code
28
47
  end
29
48
 
30
49
  describe "split" do
31
50
  it "should handle ZH" do
32
- @switzerland.split('443643532').should == [nil, '44', '364', '35', '32']
51
+ country.split('443643532').should == [nil, '44', '364', '35', '32']
33
52
  end
34
53
  end
35
54
  describe 'normalize' do
36
55
  it "should handle ZH" do
37
- @switzerland.normalize('0443643532').should == '443643532'
56
+ country.normalize('0443643532').should == '443643532'
38
57
  end
39
58
  end
40
59
  end
41
60
 
42
61
  context "without special cases" do
43
- before(:each) do
62
+ let(:country) do
44
63
  special_national_splitter = Phony::NationalSplitters::Variable.new nil, ['800']
45
64
  special_local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 3]
46
65
  special_code = Phony::NationalCode.new special_national_splitter, special_local_splitter
@@ -49,15 +68,15 @@ describe Phony::Country do
49
68
  local_splitter = Phony::LocalSplitters::Fixed.instance_for [3, 2, 2]
50
69
  national_code = Phony::NationalCode.new national_splitter, local_splitter
51
70
 
52
- @switzerland = Phony::Country.new special_code, national_code
71
+ Phony::Country.new special_code, national_code
53
72
  end
54
73
 
55
74
  describe "split" do
56
75
  it "should handle ZH" do
57
- @switzerland.split('443643532').should == [nil, '44', '364', '35', '32']
76
+ country.split('443643532').should == [nil, '44', '364', '35', '32']
58
77
  end
59
78
  it "should handle 800" do
60
- @switzerland.split('800333666').should == [nil, '800', '333', '666']
79
+ country.split('800333666').should == [nil, '800', '333', '666']
61
80
  end
62
81
  end
63
82
  end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe Phony::Vanity do
6
+
7
+ let(:vanity) { described_class }
8
+
9
+ describe '.replace' do
10
+ it 'replaces letters with digits' do
11
+ vanity.replace('1-800-HELLO').should == '1-800-43556'
12
+ end
13
+ end
14
+
15
+ describe '.vanity?' do
16
+ it 'returns true on a vanity number' do
17
+ vanity.vanity?('800HELLOES').should == true
18
+ end
19
+ it 'returns false on a non-vanity number' do
20
+ vanity.vanity?('8004355637').should == false
21
+ end
22
+ end
23
+
24
+ describe '.normalized' do
25
+ it 'normalizes the vanity number' do
26
+ vanity.normalized('1-800-HELLO').should == '1800HELLO'
27
+ end
28
+ end
29
+
30
+ 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.15.40
4
+ version: 2.15.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Hanke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-22 00:00:00.000000000 Z
11
+ date: 2017-02-13 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
@@ -90,6 +90,7 @@ files:
90
90
  - spec/lib/phony/national_splitters/none_spec.rb
91
91
  - spec/lib/phony/national_splitters/regex_spec.rb
92
92
  - spec/lib/phony/national_splitters/variable_spec.rb
93
+ - spec/lib/phony/vanity_spec.rb
93
94
  homepage: http://github.com/floere/phony
94
95
  licenses:
95
96
  - MIT
@@ -129,3 +130,4 @@ test_files:
129
130
  - spec/lib/phony/national_splitters/none_spec.rb
130
131
  - spec/lib/phony/national_splitters/regex_spec.rb
131
132
  - spec/lib/phony/national_splitters/variable_spec.rb
133
+ - spec/lib/phony/vanity_spec.rb