phony 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/phony.rb CHANGED
@@ -59,10 +59,14 @@ require File.expand_path '../phony/countries/zimbabwe', __FILE__
59
59
  #
60
60
  require File.expand_path '../phony/countries', __FILE__
61
61
 
62
-
63
-
64
62
  module Phony
65
63
 
64
+ class NormalizationError < StandardError
65
+ def initialize
66
+ super %Q{Phony could not normalize the given number. Is it a phone number?}
67
+ end
68
+ end
69
+
66
70
  # Phony uses a single country codes instance.
67
71
  #
68
72
  @codes = CountryCodes.instance
@@ -79,6 +83,8 @@ module Phony
79
83
  end
80
84
  def normalize! phone_number
81
85
  @codes.normalize phone_number
86
+ rescue
87
+ raise NormalizationError.new
82
88
  end
83
89
 
84
90
  # Splits the phone number into pieces according to the country codes.
@@ -3,32 +3,32 @@
3
3
 
4
4
  Phony.define do
5
5
  country '381',
6
- one_of(%w(800)) >> split(3,2) | # freephone
7
- one_of(%w(808)) >> split(3,2) | # payphone
8
- one_of(%w(230)) >> matched_split(
9
- /\A\d{4}\z/ => [4],
10
- /\A\d+\z/ => [3,2]) |
11
- one_of(%w(11 21)) >> matched_split(
12
- /\A\d{6}\z/ => [3,3],
13
- /\A\d+\z/ => [3,4]) |
14
- one_of(%w(26 31 35)) >> split(3,3) |
15
- one_of(%w(10 12 13 14 15 16 17 18 19 20 22 23 24 25 27 30 32 33 34 36 37)) >> matched_split(
16
- /\A\d{5}\z/ => [3,2],
17
- /\A\d+\z/ => [3,3]) |
18
- one_of(%w(72)) >> split(3,3) | # ISP
19
- one_of(%w(60 61 62 63 66 68 69)) >> matched_split(
20
- /\A\d{3}\z/ => [3],
21
- /\A\d{7}\z/ => [3,4],
22
- /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
23
- one_of(%w(64 65)) >> matched_split(
24
- /\A\d{2}\z/ => [2],
25
- /\A\d{3}\z/ => [3],
26
- /\A\d{6}\z/ => [3,3],
27
- /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
28
- one_of(%w(70)) >> split(3,3) | # universal access
29
- one_of(%w(42 78)) >> split(3,3) | # premium rate
30
- one_of(%w(9)) >> split(3,4) | # premium rate
31
- fixed(2) >> matched_split(
32
- /\A\d{5}\z/ => [3,2],
33
- /\A\d+\z/ => [3,3])
6
+ one_of(%w(800)) >> split(3,2) | # freephone
7
+ one_of(%w(808)) >> split(3,2) | # payphone
8
+ one_of(%w(230)) >> matched_split(
9
+ /\A\d{4}\z/ => [4],
10
+ /\A\d+\z/ => [3,2]) |
11
+ one_of(%w(11 21)) >> matched_split(
12
+ /\A\d{6}\z/ => [3,3],
13
+ /\A\d+\z/ => [3,4]) |
14
+ one_of(%w(26 31 35)) >> split(3,3) |
15
+ one_of(%w(10 12 13 14 15 16 17 18 19 20 22 23 24 25 27 30 32 33 34 36 37)) >> matched_split(
16
+ /\A\d{5}\z/ => [3,2],
17
+ /\A\d+\z/ => [3,3]) |
18
+ one_of(%w(72)) >> split(3,3) | # ISP
19
+ one_of(%w(60 61 62 63 66 68 69)) >> matched_split(
20
+ /\A\d{3}\z/ => [3],
21
+ /\A\d{7}\z/ => [3,4],
22
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
23
+ one_of(%w(64 65)) >> matched_split(
24
+ /\A\d{2}\z/ => [2],
25
+ /\A\d{3}\z/ => [3],
26
+ /\A\d{6}\z/ => [3,3],
27
+ /\A\d+\z/ => [3,3,4]) | # mobile, voicemail (mobile)
28
+ one_of(%w(70)) >> split(3,3) | # universal access
29
+ one_of(%w(42 78)) >> split(3,3) | # premium rate
30
+ one_of(%w(9)) >> split(3,4) | # premium rate
31
+ fixed(2) >> matched_split(
32
+ /\A\d{5}\z/ => [3,2],
33
+ /\A\d+\z/ => [3,3])
34
34
  end
@@ -2,21 +2,21 @@ Phony.define do
2
2
  # Somali Democratic Republic http://www.wtng.info/wtng-252-so.html
3
3
  # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SO
4
4
  country '252',
5
- one_of('88216') >> split(3) | # Thuraya Satellite Telecommunications Company
6
- one_of(%w(1034 1043)) >> split(3,2) | # Hortel
7
- one_of(%w(1313)) >> split(3) | # Telcom Somalia
8
- one_of(%w(160 161 162 163 164 165 166 167 168)) >> split(2,2) | # Hortel
9
- one_of(%w(200 203 211 212 213 313)) >> split(3) | # Telcom Somalia
10
- one_of(%w(201 204 208 210 214)) >> split(2,2) | # Telcom Somalia
11
- one_of(%w(500 501 502 503 504 505 506 507 508 509)) >> split(3,2) | # mobile NationLink Telecom
12
- one_of(%w(523 525 526)) >> split(2,2) | # Netco
13
- one_of(%w(642 643 644 648 649)) >> split(2,2) | # Galcom
14
- one_of(%w(33 51 52 54 55 56 57 58 59 68 71 76 78 79 88)) >> split(3,2) |
15
- match(/\A(67)\d{5}\z/) >> split(3,2) | # Golis Telecom Somalia
16
- one_of(%w(15 40 42 45 46 60 61 90 91)) >> split(3,3) | # mobile Somafone, Hortel
17
- one_of(%w(18)) >> split(3,2) | # Hortel
18
- one_of(%w(27 28 29 62 63 87)) >> split(2,2) | # Telcom Somalia, Emir Set
19
- one_of(%w(67 69)) >> split(4,3) | # mobile NationLink Telecom
20
- one_of('1') >> split(3,3) |
21
- fixed(1) >> split(3,3)
5
+ one_of('88216') >> split(3) | # Thuraya Satellite Telecommunications Company
6
+ one_of(%w(1034 1043)) >> split(3,2) | # Hortel
7
+ one_of(%w(1313)) >> split(3) | # Telcom Somalia
8
+ one_of(%w(160 161 162 163 164 165 166 167 168)) >> split(2,2) | # Hortel
9
+ one_of(%w(200 203 211 212 213 313)) >> split(3) | # Telcom Somalia
10
+ one_of(%w(201 204 208 210 214)) >> split(2,2) | # Telcom Somalia
11
+ one_of(%w(500 501 502 503 504 505 506 507 508 509)) >> split(3,2) | # mobile NationLink Telecom
12
+ one_of(%w(523 525 526)) >> split(2,2) | # Netco
13
+ one_of(%w(642 643 644 648 649)) >> split(2,2) | # Galcom
14
+ one_of(%w(33 51 52 54 55 56 57 58 59 68 71 76 78 79 88)) >> split(3,2) |
15
+ match(/\A(67)\d{5}\z/) >> split(3,2) | # Golis Telecom Somalia
16
+ one_of(%w(15 40 42 45 46 60 61 90 91)) >> split(3,3) | # mobile Somafone, Hortel
17
+ one_of(%w(18)) >> split(3,2) | # Hortel
18
+ one_of(%w(27 28 29 62 63 87)) >> split(2,2) | # Telcom Somalia, Emir Set
19
+ one_of(%w(67 69)) >> split(4,3) | # mobile NationLink Telecom
20
+ one_of('1') >> split(3,3) |
21
+ fixed(1) >> split(3,3)
22
22
  end
@@ -2,36 +2,36 @@
2
2
 
3
3
  Phony.define do
4
4
  country '263',
5
- one_of(%w(2582 2583 5483)) >>
6
- matched_split(/\A\d{6}\z/ => [3,3],
7
- /\A\d+\z/ => [3] ) | # geographic [XXXX] XXX(XXX)
8
- one_of(%w(147 204 205 222 227 228 238 248 2582 2583 271 272 274 276 281 283
9
- 284 286 287 288 289 298 308 317 371 375 376 379 383 387 389 517 518
10
- 557 558 628 637 667 668 687 688 698 848)) >>
11
- matched_split(/\A\d{6}\z/ => [3,3],
12
- /\A\d+\z/ => [3] ) | # geographic [XXX] XXX(XXX)
13
- one_of(%w(270)) >>
14
- matched_split(/\A\d{6}\z/ => [3,3],
15
- /\A\d+\z/ => [3,2] ) | # geographic [XXX] XXXXX(X)
16
- one_of(%w(273 275 277 278 279 282 285)) >>
17
- matched_split(/\A\d{6}\z/ => [3,3],
18
- /\A\d+\z/ => [2,2] ) | # geographic [XXX] XXXX(XX)
19
- one_of(%w(912)) >>
20
- matched_split(/\A\d{8}\z/ => [4,4], /\A\d+\z/ => [3]) | # mobile
21
- one_of(%w(13 14 15 16 17 18 19 21 24 26 29 30 31 32 34 35 36 50 55 57 58 59 60
22
- 63 64 65 66 69)) >>
23
- matched_split(/\A\d{6}\z/ => [3,3],
24
- /\A\d+\z/ => [3] ) | # geographic [XX] XXX(XXX)
25
- one_of(%w(20)) >>
26
- matched_split(/\A\d{6}\z/ => [3,3],
27
- /\A\d+\z/ => [3,2] ) | # geographic [XXX] XXXXX(X)
28
- one_of(%w(25 33 39 51 52 53 54 56 61 62 67 68 )) >>
29
- matched_split(/\A\d{6}\z/ => [3,3],
30
- /\A\d+\z/ => [2,2] ) | # geographic [XXX] XXXX(XX)
31
- one_of(%w(86)) >> split(4,4) | # VoIP telephony
32
- one_of(%w(71 73 77)) >> split(4,3) | # mobile
33
- one_of(%w(4 9)) >>
34
- matched_split(/\A\d{6}\z/ => [4,4],
35
- /\A\d+\z/ => [3,2] ) | # geographic [X] XXXXX(XXX)
36
- fixed(2) >> split(3,3)
5
+ one_of(%w(2582 2583 5483)) >>
6
+ matched_split(/\A\d{6}\z/ => [3,3],
7
+ /\A\d+\z/ => [3] ) | # geographic [XXXX] XXX(XXX)
8
+ one_of(%w(147 204 205 222 227 228 238 248 2582 2583 271 272 274 276 281 283
9
+ 284 286 287 288 289 298 308 317 371 375 376 379 383 387 389 517 518
10
+ 557 558 628 637 667 668 687 688 698 848)) >>
11
+ matched_split(/\A\d{6}\z/ => [3,3],
12
+ /\A\d+\z/ => [3] ) | # geographic [XXX] XXX(XXX)
13
+ one_of(%w(270)) >>
14
+ matched_split(/\A\d{6}\z/ => [3,3],
15
+ /\A\d+\z/ => [3,2] ) | # geographic [XXX] XXXXX(X)
16
+ one_of(%w(273 275 277 278 279 282 285)) >>
17
+ matched_split(/\A\d{6}\z/ => [3,3],
18
+ /\A\d+\z/ => [2,2] ) | # geographic [XXX] XXXX(XX)
19
+ one_of(%w(912)) >>
20
+ matched_split(/\A\d{8}\z/ => [4,4], /\A\d+\z/ => [3]) | # mobile
21
+ one_of(%w(13 14 15 16 17 18 19 21 24 26 29 30 31 32 34 35 36 50 55 57 58 59 60
22
+ 63 64 65 66 69)) >>
23
+ matched_split(/\A\d{6}\z/ => [3,3],
24
+ /\A\d+\z/ => [3] ) | # geographic [XX] XXX(XXX)
25
+ one_of(%w(20)) >>
26
+ matched_split(/\A\d{6}\z/ => [3,3],
27
+ /\A\d+\z/ => [3,2] ) | # geographic [XXX] XXXXX(X)
28
+ one_of(%w(25 33 39 51 52 53 54 56 61 62 67 68 )) >>
29
+ matched_split(/\A\d{6}\z/ => [3,3],
30
+ /\A\d+\z/ => [2,2] ) | # geographic [XXX] XXXX(XX)
31
+ one_of(%w(86)) >> split(4,4) | # VoIP telephony
32
+ one_of(%w(71 73 77)) >> split(4,3) | # mobile
33
+ one_of(%w(4 9)) >>
34
+ matched_split(/\A\d{6}\z/ => [4,4],
35
+ /\A\d+\z/ => [3,2] ) | # geographic [X] XXXXX(XXX)
36
+ fixed(2) >> split(3,3)
37
37
  end
@@ -46,11 +46,9 @@ module Phony
46
46
  number = rest.inject('', :+)
47
47
  mapping.each do |regex, format|
48
48
  next unless number =~ regex
49
- length = format.inject(0, :+)
50
- length -= 10 if length > 10
51
- return number.length == length
49
+ return plausible_with? number, format
52
50
  end
53
- false
51
+ plausible_with? number, fallback
54
52
  end
55
53
 
56
54
  private
@@ -62,6 +60,12 @@ module Phony
62
60
  result
63
61
  end
64
62
  end
63
+
64
+ def plausible_with? number, format
65
+ length = format.inject(0, :+)
66
+ length -= 10 if length > 10
67
+ number.length == length
68
+ end
65
69
 
66
70
  end
67
71
 
@@ -24,10 +24,12 @@ describe 'validations' do
24
24
  incorrect = [shortest.sub(/\d\s*\z/, ''), longest + '0']
25
25
 
26
26
  correct.each do |value|
27
- Phony.plausible?(value).should be_true, "not validates '#{value}', but should"
27
+ Phony.plausible?(value).should be_true,
28
+ "It should validate #{value}, but does not."
28
29
  end
29
30
  incorrect.each do |value|
30
- Phony.plausible?(value).should be_false, "validates '#{value}', but should not"
31
+ Phony.plausible?(value).should be_false,
32
+ "It should not validate #{value}, but does."
31
33
  end
32
34
  end
33
35
  end
@@ -479,6 +481,8 @@ describe 'validations' do
479
481
  '+264 63 088 612 345',
480
482
  '+264 85 1234 567']
481
483
  it_is_correct_for 'Nauru (Republic of)', :samples => '+674 239 8387'
484
+ it_is_correct_for 'Norway', :samples => ['+47 51 23 45 67',
485
+ '+47 41 23 45 67']
482
486
  it_is_correct_for 'Nepal', :samples => ['+977 1 434 5678',
483
487
  '+977 10 123 456',
484
488
  '+977 98 1234 5678']
@@ -4,60 +4,54 @@ require 'spec_helper'
4
4
 
5
5
  describe Phony do
6
6
 
7
- describe 'nil cases' do
8
- it "should raise on normalize nil" do
9
- expect {
10
- Phony.normalize(nil)
11
- }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number).")
12
- end
13
- it "should raise on format nil" do
14
- expect {
15
- Phony.format(nil)
16
- }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number).")
17
- end
18
- it "should raise on split nil" do
19
- expect {
20
- Phony.split(nil)
21
- }.to raise_error(ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number).")
7
+ describe 'normalize' do
8
+ describe 'exceptions' do
9
+ it 'raises on nil' do
10
+ expect {
11
+ Phony.normalize nil
12
+ }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.normalize(number).')
13
+ end
14
+ it 'raises a nice error message' do
15
+ expect do
16
+ Phony.normalize 'test'
17
+ end.to raise_error(Phony::NormalizationError, 'Phony could not normalize the given number. Is it a phone number?')
18
+ end
22
19
  end
23
- end
24
-
25
- describe "normalize" do
26
- describe "some examples" do
27
- it "should normalize a too short number" do
20
+ describe 'some examples' do
21
+ it 'should normalize a too short number' do
28
22
  Phony.normalize('+972').should == '972'
29
23
  end
30
- it "should normalize an already normalized number" do
24
+ it 'should normalize an already normalized number' do
31
25
  Phony.normalize('41443643533').should == '41443643533'
32
26
  end
33
- it "should normalize a format number" do
27
+ it 'should normalize a format number' do
34
28
  Phony.normalize('+41 44 364 35 33').should == '41443643533'
35
29
  end
36
- it "should normalize a 00 number" do
30
+ it 'should normalize a 00 number' do
37
31
  Phony.normalize('0041 44 364 35 33').should == '41443643533'
38
32
  end
39
- it "should normalize a service number" do
33
+ it 'should normalize a service number' do
40
34
  Phony.normalize('+41 800 11 22 33').should == '41800112233'
41
35
  end
42
- it "should remove characters from the number" do
36
+ it 'should remove characters from the number' do
43
37
  Phony.normalize('John: +41 44 364 35 33').should == '41443643533'
44
38
  end
45
- it "should normalize one of these crazy american numbers" do
39
+ it 'should normalize one of these crazy american numbers' do
46
40
  Phony.normalize('1 (703) 451-5115').should == '17034515115'
47
41
  end
48
- it "should normalize another one of these crazy american numbers" do
42
+ it 'should normalize another one of these crazy american numbers' do
49
43
  Phony.normalize('1-888-407-4747').should == '18884074747'
50
44
  end
51
- it "should normalize a number with colons" do
45
+ it 'should normalize a number with colons' do
52
46
  Phony.normalize('1.906.387.1698').should == '19063871698'
53
47
  end
54
- it "should normalize a number with optional ndc" do
48
+ it 'should normalize a number with optional ndc' do
55
49
  Phony.normalize('+41 (044) 364 35 33').should == '41443643533'
56
50
  end
57
- it "should normalize a number with erroneous zero inside" do
51
+ it 'should normalize a number with erroneous zero inside' do
58
52
  Phony.normalize('+410443643533').should == '41443643533'
59
53
  end
60
- it "should not normalize a number with a correct zero inside" do
54
+ it 'should not normalize a number with a correct zero inside' do
61
55
  Phony.normalize('+390909709511').should == '390909709511'
62
56
  end
63
57
 
@@ -83,56 +77,63 @@ describe Phony do
83
77
  end
84
78
  end
85
79
 
86
- describe "format" do
87
- describe "default" do
88
- it "should format swiss numbers" do
80
+ describe 'format' do
81
+ describe 'exceptions' do
82
+ it 'raises on nil' do
83
+ expect {
84
+ Phony.format nil
85
+ }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.format(number).')
86
+ end
87
+ end
88
+ describe 'default' do
89
+ it 'should format swiss numbers' do
89
90
  Phony.format('41443643532').should == '+41 44 364 35 32'
90
91
  end
91
92
  # TODO
92
93
  #
93
- it "should format swiss service numbers" do
94
+ it 'should format swiss service numbers' do
94
95
  Phony.format('41800112233').should == '+41 800 112 233'
95
96
  end
96
- it "should format austrian numbers" do
97
+ it 'should format austrian numbers' do
97
98
  Phony.format('43198110').should == '+43 1 98110'
98
99
  end
99
- it "should format american numbers" do
100
+ it 'should format american numbers' do
100
101
  Phony.format('18705551122').should == '+1 870 555 1122'
101
102
  end
102
103
  end
103
- describe "international" do
104
- it "should format north american numbers" do
104
+ describe 'international' do
105
+ it 'should format north american numbers' do
105
106
  Phony.format('18091231234', :format => :international).should == '+1 809 123 1234'
106
107
  end
107
- it "should format austrian numbers" do
108
+ it 'should format austrian numbers' do
108
109
  Phony.format('43198110', :format => :international).should == '+43 1 98110'
109
110
  end
110
- it "should format austrian numbers" do
111
+ it 'should format austrian numbers' do
111
112
  Phony.format('43198110', :format => :international_absolute).should == '+43 1 98110'
112
113
  end
113
- it "should format french numbers" do
114
+ it 'should format french numbers' do
114
115
  Phony.format('33142278186', :format => :+).should == '+33 1 42 27 81 86'
115
116
  end
116
- it "should format austrian numbers" do
117
+ it 'should format austrian numbers' do
117
118
  Phony.format('43198110', :format => :international_relative).should == '0043 1 98110'
118
119
  end
119
120
  it 'should format liechtensteiner numbers' do
120
121
  Phony.format('4233841148', :format => :international_relative).should == '00423 384 11 48'
121
122
  end
122
123
  context 'with no spaces' do
123
- it "should format north american numbers" do
124
+ it 'should format north american numbers' do
124
125
  Phony.format('18091231234', :format => :international, :spaces => '').should == '+18091231234'
125
126
  end
126
- it "should format austrian numbers" do
127
+ it 'should format austrian numbers' do
127
128
  Phony.format('43198110', :format => :international, :spaces => '').should == '+43198110'
128
129
  end
129
- it "should format austrian numbers" do
130
+ it 'should format austrian numbers' do
130
131
  Phony.format('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'
131
132
  end
132
- it "should format french numbers" do
133
+ it 'should format french numbers' do
133
134
  Phony.format('33142278186', :format => :+, :spaces => '').should == '+33142278186'
134
135
  end
135
- it "should format austrian numbers" do
136
+ it 'should format austrian numbers' do
136
137
  Phony.format('43198110', :format => :international_relative, :spaces => '').should == '0043198110'
137
138
  end
138
139
  it 'should format liechtensteiner numbers' do
@@ -140,29 +141,29 @@ describe Phony do
140
141
  end
141
142
  end
142
143
  context 'with special spaces' do
143
- it "should format swiss numbers" do
144
+ it 'should format swiss numbers' do
144
145
  Phony.format('41443643532', :format => :international).should == '+41 44 364 35 32'
145
146
  end
146
- it "should format north american numbers" do
147
+ it 'should format north american numbers' do
147
148
  Phony.format('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'
148
149
  end
149
- it "should format austrian numbers" do
150
+ it 'should format austrian numbers' do
150
151
  Phony.format('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'
151
152
  end
152
- it "should format austrian numbers" do
153
+ it 'should format austrian numbers' do
153
154
  Phony.format('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'
154
155
  end
155
- it "should format french numbers" do
156
+ it 'should format french numbers' do
156
157
  Phony.format('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'
157
158
  end
158
- it "should format austrian numbers" do
159
+ it 'should format austrian numbers' do
159
160
  Phony.format('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'
160
161
  end
161
162
  it 'should format liechtensteiner numbers' do
162
163
  Phony.format('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'
163
164
  end
164
165
  end
165
- describe '"unsupported" countries' do
166
+ describe "'unsupported' countries" do
166
167
  it 'should format as a single block' do
167
168
  Phony.format('88132155605220').should == '+881 32155605220'
168
169
  end
@@ -177,27 +178,27 @@ describe Phony do
177
178
  end
178
179
  end
179
180
  end
180
- describe "national" do
181
- it "should format swiss numbers" do
181
+ describe 'national' do
182
+ it 'should format swiss numbers' do
182
183
  Phony.format('41443643532', :format => :national).should == '044 364 35 32'
183
184
  end
184
185
  # TODO
185
186
  #
186
- it "should format swiss service numbers" do
187
+ it 'should format swiss service numbers' do
187
188
  Phony.format('41800112233', :format => :national).should == '0800 112 233'
188
189
  end
189
- it "should format austrian numbers" do
190
+ it 'should format austrian numbers' do
190
191
  Phony.format('43198110', :format => :national).should == '01 98110'
191
192
  end
192
- it "should format US numbers without a leading zero" do
193
+ it 'should format US numbers without a leading zero' do
193
194
  Phony.format('14159224711', :format => :national).should == '415 922 4711'
194
195
  end
195
196
  end
196
- describe "local" do
197
- it "should format swiss numbers" do
197
+ describe 'local' do
198
+ it 'should format swiss numbers' do
198
199
  Phony.format('41443643532', :format => :local).should == '364 35 32'
199
200
  end
200
- it "should format german numbers" do
201
+ it 'should format german numbers' do
201
202
  Phony.format('493038625454', :format => :local).should == '386 25454'
202
203
  end
203
204
  end
@@ -205,11 +206,18 @@ describe Phony do
205
206
 
206
207
  context 'minimal cases' do
207
208
  context 'normalizing' do
208
- it 'handles completely crazy "numbers"' do
209
+ it "handles completely crazy 'numbers'" do
209
210
  Phony.normalize('Hello, I am Cora, the 41th parrot, and 044 is my 364 times 35 funky number. 32.').should == '41443643532'
210
211
  end
211
212
  end
212
213
  context 'splitting' do
214
+ describe 'exceptions' do
215
+ it 'should raise on split nil' do
216
+ expect {
217
+ Phony.split nil
218
+ }.to raise_error(ArgumentError, 'Phone number cannot be nil. Use e.g. number && Phony.split(number).')
219
+ end
220
+ end
213
221
  it 'handles completely missing numbers well enough' do
214
222
  Phony.split('4144').should == ['41', '44', '']
215
223
  end
@@ -231,7 +239,7 @@ describe Phony do
231
239
  Phony.format('414436435').should == '+41 44 364 35'
232
240
  end
233
241
  end
234
- context '"unsupported" countries' do
242
+ context "'unsupported' countries" do
235
243
  it 'handles formatting' do
236
244
  Phony.format('88132155605220').should == '+881 32155605220'
237
245
  end
@@ -241,7 +249,7 @@ describe Phony do
241
249
  end
242
250
  end
243
251
 
244
- context "speed" do
252
+ context 'speed' do
245
253
  before(:each) do
246
254
  @phone_numbers = [
247
255
  '41443643532',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-05-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Fast international phone number (E164 standard) normalizing, splitting
15
15
  and formatting. Lots of formatting options: International (+.., 00..), national