phony 2.2.4 → 2.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.textile +29 -27
- data/lib/phony.rb +2 -2
- data/lib/phony/countries/ireland.rb +1 -3
- data/lib/phony/countries/malaysia.rb +2 -2
- data/lib/phony/country.rb +23 -20
- data/lib/phony/country_codes.rb +8 -6
- data/lib/phony/dsl.rb +2 -2
- data/lib/phony/national_code.rb +2 -2
- data/lib/phony/trunk_code.rb +1 -1
- data/lib/phony/vanity.rb +2 -2
- data/spec/functional/plausibility_spec.rb +0 -1
- data/spec/lib/phony/country_codes_spec.rb +47 -47
- data/spec/lib/phony/local_splitters/regex_spec.rb +6 -6
- data/spec/lib/phony_spec.rb +79 -74
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2I0ZWIxMzc3NTZlMzdlYTYyOGM4MjUwZjc1MDdkYTQ4ODJlYzY1Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTM5OWNkMTNmNjEyYjU5YzY2MTA0MjBkNDFkMTZkYWRiM2JkZWNjMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGZiNWViN2VjMWU1ZjEwZGFhZmVlNGJjNjdlOWMwYjU5MDNkYTI1OTY3NzAw
|
10
|
+
ZTdiODdhMGMzYmY3ZDgwNTBkMWE4ODkxNDJlOWIxZjBhZDgxY2RhNjJiYzUz
|
11
|
+
NDExMDllYTczMmU3NjA5OWI0NDFiZTEwMDM5MDlhMzdlZmEwODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWVkMDFmMTYwMDI0YjJmYWNiZmY1ZjBkMjQ1NTZkNTgzYzg5ZDhlMmM5MTQ4
|
14
|
+
ZjQyZGU3MDU1MjlmNTRjODQ3NzIwYWRjZTA1YTE4YTE0ZDE0NTk0YWRjMDc2
|
15
|
+
ZTMwYTRhYTBiOTJkMTAyZDI3MWVkNDlkNmNiMDBmMmVhNzA1Y2Q=
|
data/README.textile
CHANGED
@@ -91,69 +91,71 @@ This will often raise an error if you try normalizing a non E164-izable number (
|
|
91
91
|
|
92
92
|
h3(#formatting). Formatting
|
93
93
|
|
94
|
-
@Phony.formatted(
|
94
|
+
Aliased as @Phony.formatted(number_string)@.
|
95
95
|
|
96
|
-
@Phony.
|
96
|
+
@Phony.format('41443643532').should == '+41 44 364 35 32'@
|
97
97
|
|
98
|
-
@Phony.
|
98
|
+
@Phony.format('41800112233').should == '+41 800 11 22 33'@
|
99
99
|
|
100
|
-
@Phony.
|
100
|
+
@Phony.format('43198110').should == '+43 1 98110'@
|
101
|
+
|
102
|
+
@Phony.format('18705551122').should == '+1 870 555 1122'@
|
101
103
|
|
102
104
|
h4(#international). International
|
103
105
|
|
104
|
-
@Phony.
|
106
|
+
@Phony.format('18091231234', :format => :international).should == '+1 809 123 1234'@
|
105
107
|
|
106
|
-
@Phony.
|
108
|
+
@Phony.format('43198110', :format => :international).should == '+43 1 98110'@
|
107
109
|
|
108
|
-
@Phony.
|
110
|
+
@Phony.format('43198110', :format => :international_absolute).should == '+43 1 98110'@
|
109
111
|
|
110
|
-
@Phony.
|
112
|
+
@Phony.format('33142278186', :format => :+).should == '+33 1 42 27 81 86'@
|
111
113
|
|
112
|
-
@Phony.
|
114
|
+
@Phony.format('43198110', :format => :international_relative).should == '0043 1 98110'@
|
113
115
|
|
114
|
-
@Phony.
|
116
|
+
@Phony.format('4233841148', :format => :international_relative).should == '00423 384 11 48'@
|
115
117
|
|
116
118
|
h4(#spaces). With spaces
|
117
119
|
|
118
|
-
@Phony.
|
120
|
+
@Phony.format('18091231234', :format => :international, :spaces => '').should == '+18091231234'@
|
119
121
|
|
120
|
-
@Phony.
|
122
|
+
@Phony.format('43198110', :format => :international, :spaces => '').should == '+43198110'@
|
121
123
|
|
122
|
-
@Phony.
|
124
|
+
@Phony.format('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'@
|
123
125
|
|
124
|
-
@Phony.
|
126
|
+
@Phony.format('33142278186', :format => :+, :spaces => '').should == '+33142278186'@
|
125
127
|
|
126
|
-
@Phony.
|
128
|
+
@Phony.format('43198110', :format => :international_relative, :spaces => '').should == '0043198110'@
|
127
129
|
|
128
|
-
@Phony.
|
130
|
+
@Phony.format('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'@
|
129
131
|
|
130
132
|
h4(#special). With special spaces
|
131
133
|
|
132
|
-
@Phony.
|
134
|
+
@Phony.format('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'@
|
133
135
|
|
134
|
-
@Phony.
|
136
|
+
@Phony.format('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'@
|
135
137
|
|
136
|
-
@Phony.
|
138
|
+
@Phony.format('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'@
|
137
139
|
|
138
|
-
@Phony.
|
140
|
+
@Phony.format('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'@
|
139
141
|
|
140
|
-
@Phony.
|
142
|
+
@Phony.format('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'@
|
141
143
|
|
142
|
-
@Phony.
|
144
|
+
@Phony.format('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'@
|
143
145
|
|
144
146
|
h4(#national). National
|
145
147
|
|
146
|
-
@Phony.
|
148
|
+
@Phony.format('41443643532', :format => :national).should == '044 364 35 32'@
|
147
149
|
|
148
|
-
@Phony.
|
150
|
+
@Phony.format('41800112233', :format => :national).should == '0800 11 22 33'@
|
149
151
|
|
150
|
-
@Phony.
|
152
|
+
@Phony.format('43198110', :format => :national).should == '01 98110'@
|
151
153
|
|
152
154
|
h4(#local). Local
|
153
155
|
|
154
|
-
@Phony.
|
156
|
+
@Phony.format('41443643532', :format => :local).should == '364 35 32'@
|
155
157
|
|
156
|
-
@Phony.
|
158
|
+
@Phony.format('493038625454', :format => :local).should == '386 25454'@
|
157
159
|
|
158
160
|
h3(#splitting). Splitting
|
159
161
|
|
data/lib/phony.rb
CHANGED
@@ -115,10 +115,10 @@ module Phony
|
|
115
115
|
#
|
116
116
|
def format phone_number, options = {}
|
117
117
|
raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
|
118
|
-
|
118
|
+
format! phone_number.dup, options
|
119
119
|
end
|
120
120
|
def format! phone_number, options = {}
|
121
|
-
@codes.
|
121
|
+
@codes.format phone_number, options
|
122
122
|
end
|
123
123
|
alias formatted format
|
124
124
|
alias formatted! format!
|
@@ -9,8 +9,6 @@
|
|
9
9
|
# http://www.comreg.ie/_fileupload/publications/ComReg03147.pdf
|
10
10
|
# http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Republic_of_Ireland
|
11
11
|
#
|
12
|
-
handlers = []
|
13
|
-
|
14
12
|
ndcs_with_5_subscriber_digits = [
|
15
13
|
('22'..'29').to_a, # Mallow, Bandon, Youghal, Fermoy, Macroom, Bantry, Skibbereen, Kanturk
|
16
14
|
'402', # Arklow
|
@@ -73,4 +71,4 @@ Phony.define do
|
|
73
71
|
match(/^(8\d).+$/) >> split(3,4) | # mobile
|
74
72
|
fixed(3) >> split(6) # Fallback
|
75
73
|
|
76
|
-
end
|
74
|
+
end
|
@@ -12,7 +12,7 @@ ndcs = [
|
|
12
12
|
'9', # Kelantan, Pahang (except Cameron Highlands & Genting Highlands) & Terengganu
|
13
13
|
]
|
14
14
|
mobile = %w{ 10 11 12 13 14 153 154 156 158 16 17 18 19 }
|
15
|
-
service = %w{ 100 101 102 103 104 108 991 994 995 999 } # Emergeny and Service numbers, only 3 digits long
|
15
|
+
# service = %w{ 100 101 102 103 104 108 991 994 995 999 } # Emergeny and Service numbers, only 3 digits long
|
16
16
|
freephone = %w{ 300 700 800 }
|
17
17
|
|
18
18
|
Phony.define do
|
@@ -21,4 +21,4 @@ Phony.define do
|
|
21
21
|
one_of(mobile) >> split(3,4) | # Mobile
|
22
22
|
one_of(ndcs) >> split(8) | # 1-digit NDCs
|
23
23
|
fixed(2) >> split(8) # 2-digit NDCs (Also, fallback)
|
24
|
-
end
|
24
|
+
end
|
data/lib/phony/country.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module Phony
|
2
|
-
|
2
|
+
|
3
3
|
#
|
4
4
|
#
|
5
5
|
class Country
|
6
|
-
|
6
|
+
|
7
7
|
attr_accessor :codes
|
8
|
-
|
9
|
-
#
|
8
|
+
|
9
|
+
#
|
10
10
|
#
|
11
11
|
def initialize *codes
|
12
12
|
@codes = codes
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
# Chain two codes together.
|
16
16
|
#
|
17
17
|
def |(other)
|
18
18
|
self.codes = self.codes + other.codes
|
19
19
|
self
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Options.
|
23
23
|
#
|
24
24
|
# TODO Rewrite.
|
@@ -27,7 +27,7 @@ module Phony
|
|
27
27
|
@cc = cc
|
28
28
|
@invalid_ndcs = options[:invalid_ndcs] || []
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# A number is split with the code handlers as given in the initializer.
|
32
32
|
#
|
33
33
|
# Note: If the ndc is nil, it will not return it.
|
@@ -37,6 +37,9 @@ module Phony
|
|
37
37
|
zero, ndc, *rest = code.split national_number
|
38
38
|
return [zero, ndc, *rest] if rest && !rest.empty?
|
39
39
|
end
|
40
|
+
# Best effort in error case.
|
41
|
+
#
|
42
|
+
[nil, national_number, []]
|
40
43
|
end
|
41
44
|
def split_ndc national_number
|
42
45
|
@codes.each do |code|
|
@@ -44,7 +47,7 @@ module Phony
|
|
44
47
|
return [code.local_splitter, zero, ndc, *rest] if rest && !rest.empty?
|
45
48
|
end
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
# Cleans all non-numeric characters.
|
49
52
|
#
|
50
53
|
@@basic_cleaning_pattern = /\(0\)|\D/
|
@@ -58,10 +61,10 @@ module Phony
|
|
58
61
|
def clean! number
|
59
62
|
number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
|
60
63
|
end
|
61
|
-
|
64
|
+
|
62
65
|
# Removes 0s from partially normalized numbers
|
63
66
|
# such as 410443643533.
|
64
|
-
#
|
67
|
+
#
|
65
68
|
# Example:
|
66
69
|
# 410443643533 -> 41443643533
|
67
70
|
#
|
@@ -76,12 +79,12 @@ module Phony
|
|
76
79
|
end
|
77
80
|
normalized
|
78
81
|
end
|
79
|
-
|
82
|
+
|
80
83
|
# Tests for plausibility of this national number.
|
81
84
|
#
|
82
85
|
def plausible? rest, hints = {}
|
83
86
|
local, _, ndc, *rest = split_ndc rest
|
84
|
-
|
87
|
+
|
85
88
|
# Element based checking.
|
86
89
|
#
|
87
90
|
# Note: ndc == false means the country has none.
|
@@ -89,21 +92,21 @@ module Phony
|
|
89
92
|
return false if ndc.nil?
|
90
93
|
return false if ndc && ndc.empty?
|
91
94
|
return false if @invalid_ndcs.include? ndc # TODO Refactor.
|
92
|
-
|
95
|
+
|
93
96
|
# # A valid range for the rest is 0 or 3+ total digits.
|
94
97
|
# #
|
95
98
|
# return false if (1..2) === rest_size
|
96
|
-
|
99
|
+
|
97
100
|
# National destination code plausible?
|
98
101
|
#
|
99
102
|
ndc_needed = hints[:ndc]
|
100
103
|
return false if ndc_needed && !(ndc_needed === ndc)
|
101
|
-
|
104
|
+
|
102
105
|
# Local code specific checks.
|
103
106
|
#
|
104
107
|
return local.plausible? rest, hints
|
105
108
|
end
|
106
|
-
|
109
|
+
|
107
110
|
# Is this national number a vanity number?
|
108
111
|
#
|
109
112
|
def vanity? national_number
|
@@ -112,10 +115,10 @@ module Phony
|
|
112
115
|
#
|
113
116
|
#
|
114
117
|
def vanity_to_number vanity_number
|
115
|
-
|
118
|
+
_, ndc, *rest = split vanity_number
|
116
119
|
"#{ndc}#{Vanity.replace(rest.join)}"
|
117
120
|
end
|
118
|
-
|
121
|
+
|
119
122
|
end
|
120
|
-
|
121
|
-
end
|
123
|
+
|
124
|
+
end
|
data/lib/phony/country_codes.rb
CHANGED
@@ -50,7 +50,7 @@ module Phony
|
|
50
50
|
countrify!(number, cc) || number
|
51
51
|
end
|
52
52
|
def countrify! number, cc
|
53
|
-
number.sub!
|
53
|
+
number.sub!(/\A/, cc) # @countrify_regex, @cc
|
54
54
|
end
|
55
55
|
|
56
56
|
# 00 for the standard international call prefix.
|
@@ -83,9 +83,11 @@ module Phony
|
|
83
83
|
[cc, *country.split(rest)]
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
86
|
+
def format number, options = {}
|
87
87
|
format_cc_ndc_local options[:format], options[:spaces] || @default_space, *split(number)
|
88
88
|
end
|
89
|
+
alias formatted format
|
90
|
+
|
89
91
|
# Formats country code and national destination code.
|
90
92
|
#
|
91
93
|
def format_cc_ndc_local format, space, cc, zero, ndc, *parts
|
@@ -127,15 +129,15 @@ module Phony
|
|
127
129
|
#
|
128
130
|
#
|
129
131
|
def service? number
|
130
|
-
country,
|
132
|
+
country, _, rest = split_cc number
|
131
133
|
country.service? rest
|
132
134
|
end
|
133
135
|
def mobile? number
|
134
|
-
country,
|
136
|
+
country, _, rest = split_cc number
|
135
137
|
country.mobile? rest
|
136
138
|
end
|
137
139
|
def landline? number
|
138
|
-
country,
|
140
|
+
country, _, rest = split_cc number
|
139
141
|
country.landline? rest
|
140
142
|
end
|
141
143
|
|
@@ -179,7 +181,7 @@ module Phony
|
|
179
181
|
# Country specific tests.
|
180
182
|
#
|
181
183
|
country.plausible? rest, hints
|
182
|
-
rescue StandardError
|
184
|
+
rescue StandardError
|
183
185
|
return false
|
184
186
|
end
|
185
187
|
|
data/lib/phony/dsl.rb
CHANGED
data/lib/phony/national_code.rb
CHANGED
data/lib/phony/trunk_code.rb
CHANGED
data/lib/phony/vanity.rb
CHANGED
@@ -16,7 +16,7 @@ module Phony
|
|
16
16
|
# Replaces (and normalizes) vanity characters of passed number with correct digits.
|
17
17
|
#
|
18
18
|
def self.replace number
|
19
|
-
number.tr
|
19
|
+
number.tr(*mapping)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Returns true if there is a character in the number
|
@@ -29,7 +29,7 @@ module Phony
|
|
29
29
|
|
30
30
|
# Vanity-Normalized.
|
31
31
|
#
|
32
|
-
@@vanity_normalizing_regexp = /^0*|[^\
|
32
|
+
@@vanity_normalizing_regexp = /^0*|[^\w]/
|
33
33
|
def self.normalized number
|
34
34
|
number.gsub @@vanity_normalizing_regexp, ''
|
35
35
|
end
|
@@ -8,39 +8,39 @@ describe Phony::CountryCodes do
|
|
8
8
|
|
9
9
|
describe 'international_absolute_format=' do
|
10
10
|
it 'formats correctly' do
|
11
|
-
@countries.formatted('41443643532', :format => :international).should
|
11
|
+
@countries.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
12
12
|
end
|
13
13
|
it 'formats correctly' do
|
14
14
|
old_format = @countries.international_absolute_format
|
15
15
|
@countries.international_absolute_format = '!!! %s%s%s'
|
16
16
|
|
17
|
-
@countries.formatted('41443643532', :format => :international).should
|
17
|
+
@countries.formatted('41443643532', :format => :international).should eql '!!! 41 44 364 35 32'
|
18
18
|
|
19
19
|
@countries.international_absolute_format = old_format
|
20
20
|
end
|
21
21
|
end
|
22
22
|
describe 'international_relative_format=' do
|
23
23
|
it 'formats correctly' do
|
24
|
-
@countries.formatted('41443643532', :format => :international_relative).should
|
24
|
+
@countries.formatted('41443643532', :format => :international_relative).should eql '0041 44 364 35 32'
|
25
25
|
end
|
26
26
|
it 'formats correctly' do
|
27
27
|
old_format = @countries.international_relative_format
|
28
28
|
@countries.international_relative_format = '000 %s%s%s'
|
29
29
|
|
30
|
-
@countries.formatted('41443643532', :format => :international_relative).should
|
30
|
+
@countries.formatted('41443643532', :format => :international_relative).should eql '000 41 44 364 35 32'
|
31
31
|
|
32
32
|
@countries.international_relative_format = old_format
|
33
33
|
end
|
34
34
|
end
|
35
35
|
describe 'national_format=' do
|
36
36
|
it 'formats correctly' do
|
37
|
-
@countries.formatted('41443643532', :format => :international_relative).should
|
37
|
+
@countries.formatted('41443643532', :format => :international_relative).should eql '0041 44 364 35 32'
|
38
38
|
end
|
39
39
|
it 'formats correctly' do
|
40
40
|
old_format = @countries.national_format
|
41
41
|
@countries.national_format = '%s%s'
|
42
42
|
|
43
|
-
@countries.formatted('11231231234', :format => :national).should
|
43
|
+
@countries.formatted('11231231234', :format => :national).should eql '123 123 1234'
|
44
44
|
|
45
45
|
@countries.national_format = old_format
|
46
46
|
end
|
@@ -48,139 +48,139 @@ describe Phony::CountryCodes do
|
|
48
48
|
|
49
49
|
describe 'split' do
|
50
50
|
it 'splits correctly' do
|
51
|
-
@countries.split('41443643532').should
|
51
|
+
@countries.split('41443643532').should eql ['41', '0', '44', '364', '35', '32']
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe 'formatted' do
|
56
56
|
it 'formats correctly' do
|
57
|
-
@countries.formatted('41443643532', :format => :international, :spaces => :-).should
|
57
|
+
@countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
58
58
|
end
|
59
59
|
it 'formats correctly' do
|
60
|
-
@countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should
|
60
|
+
@countries.formatted('41443643532', :format => :international_relative, :spaces => :-).should eql '0041-44-364-35-32'
|
61
61
|
end
|
62
62
|
it 'formats correctly' do
|
63
|
-
@countries.formatted('41443643532', :format => :national, :spaces => :-).should
|
63
|
+
@countries.formatted('41443643532', :format => :national, :spaces => :-).should eql '044-364-35-32'
|
64
64
|
end
|
65
65
|
context 'specific' do
|
66
66
|
it 'formats ireland correctly' do
|
67
|
-
@countries.formatted("3533451234", :format => :national).should
|
67
|
+
@countries.formatted("3533451234", :format => :national).should eql '0345 1234'
|
68
68
|
end
|
69
69
|
it 'formats ireland correctly' do
|
70
|
-
@countries.formatted("353411231234", :format => :national).should
|
70
|
+
@countries.formatted("353411231234", :format => :national).should eql '041 123 1234'
|
71
71
|
end
|
72
72
|
end
|
73
73
|
context 'default' do
|
74
74
|
it "should format swiss numbers" do
|
75
|
-
@countries.formatted('41443643532').should
|
75
|
+
@countries.formatted('41443643532').should eql '+41 44 364 35 32'
|
76
76
|
end
|
77
77
|
it "should format swiss service numbers" do
|
78
|
-
@countries.formatted('41800112233').should
|
78
|
+
@countries.formatted('41800112233').should eql '+41 800 112 233'
|
79
79
|
end
|
80
80
|
it "should format austrian numbers" do
|
81
|
-
@countries.formatted('43198110').should
|
81
|
+
@countries.formatted('43198110').should eql '+43 1 98110'
|
82
82
|
end
|
83
83
|
it "should format american numbers" do
|
84
|
-
@countries.formatted('18705551122').should
|
84
|
+
@countries.formatted('18705551122').should eql '+1 870 555 1122'
|
85
85
|
end
|
86
86
|
it "should format irish numbers" do
|
87
|
-
@countries.formatted('35311234567').should
|
87
|
+
@countries.formatted('35311234567').should eql '+353 1 123 4567'
|
88
88
|
end
|
89
89
|
end
|
90
90
|
describe "international" do
|
91
91
|
it "should format north american numbers" do
|
92
|
-
@countries.formatted('18091231234', :format => :international).should
|
92
|
+
@countries.formatted('18091231234', :format => :international).should eql '+1 809 123 1234'
|
93
93
|
end
|
94
94
|
it "should format austrian numbers" do
|
95
|
-
@countries.formatted('43198110', :format => :international).should
|
95
|
+
@countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
96
96
|
end
|
97
97
|
it "should format austrian numbers" do
|
98
|
-
@countries.formatted('43198110', :format => :international_absolute).should
|
98
|
+
@countries.formatted('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
99
99
|
end
|
100
100
|
it "should format french numbers" do
|
101
|
-
@countries.formatted('33142278186', :format => :+).should
|
101
|
+
@countries.formatted('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
102
102
|
end
|
103
103
|
it "should format austrian numbers" do
|
104
|
-
@countries.formatted('43198110', :format => :international_relative).should
|
104
|
+
@countries.formatted('43198110', :format => :international_relative).should eql '0043 1 98110'
|
105
105
|
end
|
106
106
|
it 'should format liechtensteiner numbers' do
|
107
|
-
@countries.formatted('4233841148', :format => :international_relative).should
|
107
|
+
@countries.formatted('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
108
108
|
end
|
109
109
|
it "should format irish numbers" do
|
110
|
-
@countries.formatted('35311234567', :format => :international).should
|
110
|
+
@countries.formatted('35311234567', :format => :international).should eql '+353 1 123 4567'
|
111
111
|
end
|
112
112
|
it "should format luxembourgian numbers" do
|
113
|
-
@countries.formatted('352222809', :format => :international).should
|
113
|
+
@countries.formatted('352222809', :format => :international).should eql '+352 22 28 09'
|
114
114
|
end
|
115
115
|
it "should format luxembourgian 4-digit ndc numbers" do
|
116
|
-
@countries.formatted('35226222809', :format => :international).should
|
116
|
+
@countries.formatted('35226222809', :format => :international).should eql '+352 26 22 28 09'
|
117
117
|
end
|
118
118
|
it "should format luxembourgian mobile numbers" do
|
119
|
-
@countries.formatted('352621123456', :format => :international).should
|
119
|
+
@countries.formatted('352621123456', :format => :international).should eql '+352 621 123 456'
|
120
120
|
end
|
121
121
|
it "should format luxembourgian city numbers" do
|
122
|
-
@countries.formatted('3524123456', :format => :international).should
|
122
|
+
@countries.formatted('3524123456', :format => :international).should eql '+352 4 12 34 56'
|
123
123
|
end
|
124
124
|
it "should format luxembourgian machine to machine numbers" do
|
125
|
-
@countries.formatted('352602112345678', :format => :international).should
|
125
|
+
@countries.formatted('352602112345678', :format => :international).should eql '+352 6021 12 34 56 78'
|
126
126
|
end
|
127
127
|
it "should format luxembourgian numbers" do
|
128
|
-
@countries.formatted('352370431', :format => :international).should
|
128
|
+
@countries.formatted('352370431', :format => :international).should eql '+352 37 04 31'
|
129
129
|
end
|
130
130
|
it "should format luxembourgian numbers" do
|
131
|
-
@countries.formatted('35227855', :format => :international).should
|
131
|
+
@countries.formatted('35227855', :format => :international).should eql '+352 27 85 5'
|
132
132
|
end
|
133
133
|
it "should format nigerian numbers" do
|
134
|
-
@countries.formatted('23414480000', :format => :international).should
|
134
|
+
@countries.formatted('23414480000', :format => :international).should eql '+234 1 448 0000'
|
135
135
|
end
|
136
136
|
it "should format nigerian mobile numbers" do
|
137
|
-
@countries.formatted('2347061234567', :format => :international).should
|
137
|
+
@countries.formatted('2347061234567', :format => :international).should eql '+234 706 123 4567'
|
138
138
|
end
|
139
139
|
context 'with no spaces' do
|
140
140
|
it "should format north american numbers" do
|
141
|
-
Phony.formatted('18091231234', :format => :international, :spaces => '').should
|
141
|
+
Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+18091231234'
|
142
142
|
end
|
143
143
|
it "should format austrian numbers" do
|
144
|
-
Phony.formatted('43198110', :format => :international, :spaces => '').should
|
144
|
+
Phony.formatted('43198110', :format => :international, :spaces => '').should eql '+43198110'
|
145
145
|
end
|
146
146
|
it "should format austrian numbers" do
|
147
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should
|
147
|
+
Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110'
|
148
148
|
end
|
149
149
|
it "should format french numbers" do
|
150
|
-
Phony.formatted('33142278186', :format => :+, :spaces => '').should
|
150
|
+
Phony.formatted('33142278186', :format => :+, :spaces => '').should eql '+33142278186'
|
151
151
|
end
|
152
152
|
it "should format austrian numbers" do
|
153
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => '').should
|
153
|
+
Phony.formatted('43198110', :format => :international_relative, :spaces => '').should eql '0043198110'
|
154
154
|
end
|
155
155
|
it 'should format liechtensteiner numbers' do
|
156
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should
|
156
|
+
Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148'
|
157
157
|
end
|
158
158
|
end
|
159
159
|
context 'with special spaces' do
|
160
160
|
it "should format swiss numbers" do
|
161
|
-
Phony.formatted('41443643532', :format => :international).should
|
161
|
+
Phony.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
162
162
|
end
|
163
163
|
it "should format north american numbers" do
|
164
|
-
Phony.formatted('18091231234', :format => :international, :spaces => :-).should
|
164
|
+
Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-809-123-1234'
|
165
165
|
end
|
166
166
|
it "should format austrian numbers" do
|
167
|
-
Phony.formatted('43198110', :format => :international, :spaces => :-).should
|
167
|
+
Phony.formatted('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
|
168
168
|
end
|
169
169
|
it "should format austrian numbers" do
|
170
|
-
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should
|
170
|
+
Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110'
|
171
171
|
end
|
172
172
|
it "should format french numbers" do
|
173
|
-
Phony.formatted('33142278186', :format => :+, :spaces => :-).should
|
173
|
+
Phony.formatted('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86'
|
174
174
|
end
|
175
175
|
it "should format austrian numbers" do
|
176
|
-
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should
|
176
|
+
Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110'
|
177
177
|
end
|
178
178
|
it 'should format liechtensteiner numbers' do
|
179
|
-
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should
|
179
|
+
Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48'
|
180
180
|
end
|
181
181
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
end
|
186
|
+
end
|
@@ -12,7 +12,7 @@ describe Phony::LocalSplitters::Regex do
|
|
12
12
|
before(:each) do
|
13
13
|
# Norway as example.
|
14
14
|
#
|
15
|
-
@splitter = described_class.instance_for
|
15
|
+
@splitter = described_class.instance_for(/^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
|
16
16
|
end
|
17
17
|
it 'splits a number correctly' do
|
18
18
|
@splitter.split('21234567').should == ['21','23','45','67']
|
@@ -58,28 +58,28 @@ describe Phony::LocalSplitters::Regex do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'Mapping does not exist for a number' do
|
61
|
-
let(:local_splitter) { described_class.instance_for
|
61
|
+
let(:local_splitter) { described_class.instance_for(/\A5/ => [1,2,3])}
|
62
62
|
it 'returns false' do
|
63
63
|
result.should be_false
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
context "Mapping exists, but the length is greater" do
|
68
|
-
let(:local_splitter) { described_class.instance_for
|
68
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2])}
|
69
69
|
it 'returns false' do
|
70
70
|
result.should be_false
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
context "Mapping exists, but the length is less" do
|
75
|
-
let(:local_splitter) { described_class.instance_for
|
75
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,3])}
|
76
76
|
it 'returns false' do
|
77
77
|
result.should be_false
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'Mapping exists and the length is equal' do
|
82
|
-
let(:local_splitter) { described_class.instance_for
|
82
|
+
let(:local_splitter) { described_class.instance_for(/\A123/ => [2,2,2])}
|
83
83
|
it 'returns true' do
|
84
84
|
result.should be_true
|
85
85
|
end
|
@@ -87,4 +87,4 @@ describe Phony::LocalSplitters::Regex do
|
|
87
87
|
|
88
88
|
end
|
89
89
|
|
90
|
-
end
|
90
|
+
end
|
data/spec/lib/phony_spec.rb
CHANGED
@@ -6,7 +6,12 @@ describe Phony do
|
|
6
6
|
|
7
7
|
describe 'regression' do
|
8
8
|
it '#151' do
|
9
|
-
|
9
|
+
described_class.normalize('1-111-111-1111').should == '1111111111' # One 1 is removed because 1 is the trunk code.
|
10
|
+
described_class.normalize('111-111-1111', cc: '1').should == '1111111111' # One 1 is removed because 1 is the trunk code.
|
11
|
+
end
|
12
|
+
it 'best effort #152' do
|
13
|
+
described_class.split('39694805123').should == ['39', '694805123', []]
|
14
|
+
described_class.format('39694805123').should == '+39 694805123 '
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
@@ -15,7 +20,7 @@ describe Phony do
|
|
15
20
|
it '' do
|
16
21
|
us = described_class['1']
|
17
22
|
us.plausible?('4159224711').should be_true
|
18
|
-
us.normalize('4159224711').should
|
23
|
+
us.normalize('4159224711').should eql '4159224711'
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -35,73 +40,73 @@ describe Phony do
|
|
35
40
|
end
|
36
41
|
describe 'some examples' do
|
37
42
|
it 'should normalize a too short number' do
|
38
|
-
Phony.normalize('+972').should
|
43
|
+
Phony.normalize('+972').should eql '972'
|
39
44
|
end
|
40
45
|
it 'should normalize an already normalized number' do
|
41
|
-
Phony.normalize('41443643533').should
|
46
|
+
Phony.normalize('41443643533').should eql '41443643533'
|
42
47
|
end
|
43
48
|
it 'should normalize a format number' do
|
44
|
-
Phony.normalize('+41 44 364 35 33').should
|
49
|
+
Phony.normalize('+41 44 364 35 33').should eql '41443643533'
|
45
50
|
end
|
46
51
|
it 'should normalize a 00 number' do
|
47
|
-
Phony.normalize('0041 44 364 35 33').should
|
52
|
+
Phony.normalize('0041 44 364 35 33').should eql '41443643533'
|
48
53
|
end
|
49
54
|
it 'should normalize a service number' do
|
50
|
-
Phony.normalize('+41 800 11 22 33').should
|
55
|
+
Phony.normalize('+41 800 11 22 33').should eql '41800112233'
|
51
56
|
end
|
52
57
|
it 'should remove characters from the number' do
|
53
|
-
Phony.normalize('John: +41 44 364 35 33').should
|
58
|
+
Phony.normalize('John: +41 44 364 35 33').should eql '41443643533'
|
54
59
|
end
|
55
60
|
it 'should normalize one of these crazy american numbers' do
|
56
|
-
Phony.normalize('1 (703) 451-5115').should
|
61
|
+
Phony.normalize('1 (703) 451-5115').should eql '17034515115'
|
57
62
|
end
|
58
63
|
it 'should normalize another one of these crazy american numbers' do
|
59
|
-
Phony.normalize('1-888-407-4747').should
|
64
|
+
Phony.normalize('1-888-407-4747').should eql '18884074747'
|
60
65
|
end
|
61
66
|
it 'should normalize a number with colons' do
|
62
|
-
Phony.normalize('1.906.387.1698').should
|
67
|
+
Phony.normalize('1.906.387.1698').should eql '19063871698'
|
63
68
|
end
|
64
69
|
it 'should normalize a number with optional ndc' do
|
65
|
-
Phony.normalize('+41 (044) 364 35 33').should
|
70
|
+
Phony.normalize('+41 (044) 364 35 33').should eql '41443643533'
|
66
71
|
end
|
67
72
|
it 'should normalize a number with erroneous zero inside' do
|
68
|
-
Phony.normalize('+410443643533').should
|
73
|
+
Phony.normalize('+410443643533').should eql '41443643533'
|
69
74
|
end
|
70
75
|
it 'should not normalize a number with a correct zero inside' do
|
71
|
-
Phony.normalize('+390909709511').should
|
76
|
+
Phony.normalize('+390909709511').should eql '390909709511'
|
72
77
|
end
|
73
78
|
|
74
79
|
context 'special trunk prefixes' do
|
75
80
|
it 'normalizes Hungary' do
|
76
|
-
Phony.normalize('36 0630245506').should
|
81
|
+
Phony.normalize('36 0630245506').should eql '3630245506'
|
77
82
|
end
|
78
83
|
it 'normalizes Russia' do
|
79
|
-
Phony.normalize('7 8 342 1234567').should
|
84
|
+
Phony.normalize('7 8 342 1234567').should eql '73421234567'
|
80
85
|
end
|
81
86
|
it 'normalizes Lithuania' do
|
82
|
-
Phony.normalize('370 8 5 1234567').should
|
87
|
+
Phony.normalize('370 8 5 1234567').should eql '37051234567'
|
83
88
|
end
|
84
89
|
it 'normalizes Belarus' do
|
85
|
-
Phony.normalize('375 152450911').should
|
90
|
+
Phony.normalize('375 152450911').should eql '375152450911'
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
89
94
|
describe 'country-based' do
|
90
95
|
it 'normalizes the US correctly' do
|
91
|
-
Phony["1"].normalize("555 1234567890").should
|
92
|
-
Phony["1"].normalize("+1 555 1234567890").should
|
93
|
-
Phony["1"].normalize("+1 (0) 555 1234567890").should
|
96
|
+
Phony["1"].normalize("555 1234567890").should eql '5551234567890'
|
97
|
+
Phony["1"].normalize("+1 555 1234567890").should eql '5551234567890'
|
98
|
+
Phony["1"].normalize("+1 (0) 555 1234567890").should eql '5551234567890'
|
94
99
|
end
|
95
100
|
it 'normalizes Japan correctly' do
|
96
|
-
Phony["81"].normalize("80 1234 5634").should
|
97
|
-
Phony["81"].normalize("Hello 80 1234 5634").should
|
101
|
+
Phony["81"].normalize("80 1234 5634").should eql '8012345634'
|
102
|
+
Phony["81"].normalize("Hello 80 1234 5634").should eql '8012345634'
|
98
103
|
end
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
102
107
|
describe 'formatted' do
|
103
108
|
it 'is an alias of format' do
|
104
|
-
Phony.formatted('41443643532').should
|
109
|
+
Phony.formatted('41443643532').should eql '+41 44 364 35 32'
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|
@@ -115,128 +120,128 @@ describe Phony do
|
|
115
120
|
end
|
116
121
|
describe 'default' do
|
117
122
|
it 'should format swiss numbers' do
|
118
|
-
Phony.format('41443643532').should
|
123
|
+
Phony.format('41443643532').should eql '+41 44 364 35 32'
|
119
124
|
end
|
120
125
|
# TODO
|
121
126
|
#
|
122
127
|
it 'should format swiss service numbers' do
|
123
|
-
Phony.format('41800112233').should
|
128
|
+
Phony.format('41800112233').should eql '+41 800 112 233'
|
124
129
|
end
|
125
130
|
it 'should format austrian numbers' do
|
126
|
-
Phony.format('43198110').should
|
131
|
+
Phony.format('43198110').should eql '+43 1 98110'
|
127
132
|
end
|
128
133
|
it 'should format american numbers' do
|
129
|
-
Phony.format('18705551122').should
|
134
|
+
Phony.format('18705551122').should eql '+1 870 555 1122'
|
130
135
|
end
|
131
136
|
it 'should format New Zealand 021 mobile numbers' do
|
132
|
-
Phony.format('64211234567').should
|
137
|
+
Phony.format('64211234567').should eql '+64 21 123 4567'
|
133
138
|
end
|
134
139
|
it 'should format New Zealand landline numbers' do
|
135
|
-
Phony.format('6493791234').should
|
140
|
+
Phony.format('6493791234').should eql '+64 9 379 1234'
|
136
141
|
end
|
137
142
|
it 'should format Indian numbers' do
|
138
|
-
Phony.format('914433993939').should
|
143
|
+
Phony.format('914433993939').should eql '+91 44 339 93 939'
|
139
144
|
end
|
140
145
|
end
|
141
146
|
describe 'international' do
|
142
147
|
it 'should format north american numbers' do
|
143
|
-
Phony.format('18091231234', :format => :international).should
|
148
|
+
Phony.format('18091231234', :format => :international).should eql '+1 809 123 1234'
|
144
149
|
end
|
145
150
|
it 'should format austrian numbers' do
|
146
|
-
Phony.format('43198110', :format => :international).should
|
151
|
+
Phony.format('43198110', :format => :international).should eql '+43 1 98110'
|
147
152
|
end
|
148
153
|
it 'should format austrian numbers' do
|
149
|
-
Phony.format('43198110', :format => :international_absolute).should
|
154
|
+
Phony.format('43198110', :format => :international_absolute).should eql '+43 1 98110'
|
150
155
|
end
|
151
156
|
it 'should format french numbers' do
|
152
|
-
Phony.format('33142278186', :format => :+).should
|
157
|
+
Phony.format('33142278186', :format => :+).should eql '+33 1 42 27 81 86'
|
153
158
|
end
|
154
159
|
it 'should format austrian numbers' do
|
155
|
-
Phony.format('43198110', :format => :international_relative).should
|
160
|
+
Phony.format('43198110', :format => :international_relative).should eql '0043 1 98110'
|
156
161
|
end
|
157
162
|
it 'should format liechtensteiner numbers' do
|
158
|
-
Phony.format('4233841148', :format => :international_relative).should
|
163
|
+
Phony.format('4233841148', :format => :international_relative).should eql '00423 384 11 48'
|
159
164
|
end
|
160
165
|
context 'with no spaces' do
|
161
166
|
it 'should format north american numbers' do
|
162
|
-
Phony.format('18091231234', :format => :international, :spaces => '').should
|
167
|
+
Phony.format('18091231234', :format => :international, :spaces => '').should eql '+18091231234'
|
163
168
|
end
|
164
169
|
it 'should format austrian numbers' do
|
165
|
-
Phony.format('43198110', :format => :international, :spaces => '').should
|
170
|
+
Phony.format('43198110', :format => :international, :spaces => '').should eql '+43198110'
|
166
171
|
end
|
167
172
|
it 'should format austrian numbers' do
|
168
|
-
Phony.format('43198110', :format => :international_absolute, :spaces => '').should
|
173
|
+
Phony.format('43198110', :format => :international_absolute, :spaces => '').should eql '+43198110'
|
169
174
|
end
|
170
175
|
it 'should format french numbers' do
|
171
|
-
Phony.format('33142278186', :format => :+, :spaces => '').should
|
176
|
+
Phony.format('33142278186', :format => :+, :spaces => '').should eql '+33142278186'
|
172
177
|
end
|
173
178
|
it 'should format austrian numbers' do
|
174
|
-
Phony.format('43198110', :format => :international_relative, :spaces => '').should
|
179
|
+
Phony.format('43198110', :format => :international_relative, :spaces => '').should eql '0043198110'
|
175
180
|
end
|
176
181
|
it 'should format liechtensteiner numbers' do
|
177
|
-
Phony.format('4233841148', :format => :international_relative, :spaces => '').should
|
182
|
+
Phony.format('4233841148', :format => :international_relative, :spaces => '').should eql '004233841148'
|
178
183
|
end
|
179
184
|
end
|
180
185
|
context 'with special spaces' do
|
181
186
|
it 'should format swiss numbers' do
|
182
|
-
Phony.format('41443643532', :format => :international).should
|
187
|
+
Phony.format('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
183
188
|
end
|
184
189
|
it 'should format north american numbers' do
|
185
|
-
Phony.format('18091231234', :format => :international, :spaces => :-).should
|
190
|
+
Phony.format('18091231234', :format => :international, :spaces => :-).should eql '+1-809-123-1234'
|
186
191
|
end
|
187
192
|
it 'should format austrian numbers' do
|
188
|
-
Phony.format('43198110', :format => :international, :spaces => :-).should
|
193
|
+
Phony.format('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
|
189
194
|
end
|
190
195
|
it 'should format austrian numbers' do
|
191
|
-
Phony.format('43198110', :format => :international_absolute, :spaces => :-).should
|
196
|
+
Phony.format('43198110', :format => :international_absolute, :spaces => :-).should eql '+43-1-98110'
|
192
197
|
end
|
193
198
|
it 'should format french numbers' do
|
194
|
-
Phony.format('33142278186', :format => :+, :spaces => :-).should
|
199
|
+
Phony.format('33142278186', :format => :+, :spaces => :-).should eql '+33-1-42-27-81-86'
|
195
200
|
end
|
196
201
|
it 'should format austrian numbers' do
|
197
|
-
Phony.format('43198110', :format => :international_relative, :spaces => :-).should
|
202
|
+
Phony.format('43198110', :format => :international_relative, :spaces => :-).should eql '0043-1-98110'
|
198
203
|
end
|
199
204
|
it 'should format liechtensteiner numbers' do
|
200
|
-
Phony.format('4233841148', :format => :international_relative, :spaces => :-).should
|
205
|
+
Phony.format('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48'
|
201
206
|
end
|
202
207
|
end
|
203
208
|
describe "'unsupported' countries" do
|
204
209
|
it 'should format as a single block' do
|
205
|
-
Phony.format('88132155605220').should
|
210
|
+
Phony.format('88132155605220').should eql '+881 32155605220'
|
206
211
|
end
|
207
212
|
it 'should format as a single block, regardless of format' do
|
208
|
-
Phony.format('8811819372205', :format => :international).should
|
213
|
+
Phony.format('8811819372205', :format => :international).should eql '+881 1819372205'
|
209
214
|
end
|
210
215
|
it 'should format as a single block, respecting custom spaces' do
|
211
|
-
Phony.format('8811819372205', :spaces => :-).should
|
216
|
+
Phony.format('8811819372205', :spaces => :-).should eql '+881-1819372205'
|
212
217
|
end
|
213
218
|
it 'should format as a single block, even without spaces' do
|
214
|
-
Phony.format('8811819372205', :spaces => '').should
|
219
|
+
Phony.format('8811819372205', :spaces => '').should eql '+8811819372205'
|
215
220
|
end
|
216
221
|
end
|
217
222
|
end
|
218
223
|
describe 'national' do
|
219
224
|
it 'should format swiss numbers' do
|
220
|
-
Phony.format('41443643532', :format => :national).should
|
225
|
+
Phony.format('41443643532', :format => :national).should eql '044 364 35 32'
|
221
226
|
end
|
222
227
|
# TODO
|
223
228
|
#
|
224
229
|
it 'should format swiss service numbers' do
|
225
|
-
Phony.format('41800112233', :format => :national).should
|
230
|
+
Phony.format('41800112233', :format => :national).should eql '0800 112 233'
|
226
231
|
end
|
227
232
|
it 'should format austrian numbers' do
|
228
|
-
Phony.format('43198110', :format => :national).should
|
233
|
+
Phony.format('43198110', :format => :national).should eql '01 98110'
|
229
234
|
end
|
230
235
|
it 'should format US numbers without a leading zero' do
|
231
|
-
Phony.format('14159224711', :format => :national).should
|
236
|
+
Phony.format('14159224711', :format => :national).should eql '415 922 4711'
|
232
237
|
end
|
233
238
|
end
|
234
239
|
describe 'local' do
|
235
240
|
it 'should format swiss numbers' do
|
236
|
-
Phony.format('41443643532', :format => :local).should
|
241
|
+
Phony.format('41443643532', :format => :local).should eql '364 35 32'
|
237
242
|
end
|
238
243
|
it 'should format german numbers' do
|
239
|
-
Phony.format('493038625454', :format => :local).should
|
244
|
+
Phony.format('493038625454', :format => :local).should eql '386 25454'
|
240
245
|
end
|
241
246
|
end
|
242
247
|
end
|
@@ -244,7 +249,7 @@ describe Phony do
|
|
244
249
|
context 'minimal cases' do
|
245
250
|
context 'normalizing' do
|
246
251
|
it "handles completely crazy 'numbers'" do
|
247
|
-
Phony.normalize('Hello, I am Cora, the 41th parrot, and 044 is my 364 times 35 funky number. 32.').should
|
252
|
+
Phony.normalize('Hello, I am Cora, the 41th parrot, and 044 is my 364 times 35 funky number. 32.').should eql '41443643532'
|
248
253
|
end
|
249
254
|
end
|
250
255
|
context 'splitting' do
|
@@ -256,32 +261,32 @@ describe Phony do
|
|
256
261
|
end
|
257
262
|
end
|
258
263
|
it 'handles completely missing numbers well enough' do
|
259
|
-
Phony.split('4144').should
|
264
|
+
Phony.split('4144').should eql ['41', '44', '']
|
260
265
|
end
|
261
266
|
it 'handles a missing number part' do
|
262
|
-
Phony.split('4144364').should
|
267
|
+
Phony.split('4144364').should eql ['41', '44', '364']
|
263
268
|
end
|
264
269
|
it 'handles a missing number part' do
|
265
|
-
Phony.split('414436435').should
|
270
|
+
Phony.split('414436435').should eql ['41', '44', '364', '35']
|
266
271
|
end
|
267
272
|
end
|
268
273
|
context 'formatting' do
|
269
274
|
it 'handles completely missing numbers well enough' do
|
270
|
-
Phony.format('4144').should
|
275
|
+
Phony.format('4144').should eql '+41 44 '
|
271
276
|
end
|
272
277
|
it 'handles a missing number part' do
|
273
|
-
Phony.format('4144364').should
|
278
|
+
Phony.format('4144364').should eql '+41 44 364'
|
274
279
|
end
|
275
280
|
it 'handles a missing number part' do
|
276
|
-
Phony.format('414436435').should
|
281
|
+
Phony.format('414436435').should eql '+41 44 364 35'
|
277
282
|
end
|
278
283
|
end
|
279
284
|
context "'unsupported' countries" do
|
280
285
|
it 'handles formatting' do
|
281
|
-
Phony.format('88132155605220').should
|
286
|
+
Phony.format('88132155605220').should eql '+881 32155605220'
|
282
287
|
end
|
283
288
|
it 'handles normalizing' do
|
284
|
-
Phony.normalize('+881-321 5560 5220').should
|
289
|
+
Phony.normalize('+881-321 5560 5220').should eql '88132155605220'
|
285
290
|
end
|
286
291
|
end
|
287
292
|
end
|
@@ -336,11 +341,11 @@ describe Phony do
|
|
336
341
|
end
|
337
342
|
|
338
343
|
describe 'vanity_to_number' do
|
339
|
-
it {Phony.vanity_to_number('41800WEGGLI').should
|
340
|
-
it {Phony.vanity_to_number('41800weggli').should
|
341
|
-
# it {Phony.vanity_to_number('41800SUCCESSMATCH').should
|
342
|
-
it {Phony.vanity_to_number('41800SUCCESSMATCH').should
|
343
|
-
it {Phony.vanity_to_number('4180BLA').should
|
344
|
+
it {Phony.vanity_to_number('41800WEGGLI').should eql '41800934454'}
|
345
|
+
it {Phony.vanity_to_number('41800weggli').should eql '41800934454'}
|
346
|
+
# it {Phony.vanity_to_number('41800SUCCESSMATCH').should eql '41800782237'} # Cut off according to the swiss norms.
|
347
|
+
it {Phony.vanity_to_number('41800SUCCESSMATCH').should eql '41800782237762824'} # Allow for call-through numbers (>= 1.6.0)
|
348
|
+
it {Phony.vanity_to_number('4180BLA').should eql '4180252'} # Does not check for validity of number.
|
344
349
|
end
|
345
350
|
end
|
346
351
|
|
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.2.
|
4
|
+
version: 2.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-20 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
|