phony 2.13.0 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/phony.rb +1 -3
- data/lib/phony/countries.rb +4 -2
- data/lib/phony/country.rb +76 -2
- data/lib/phony/country_codes.rb +75 -140
- data/lib/phony/trunk_code.rb +10 -1
- data/spec/functional/format_spec.rb +19 -9
- data/spec/lib/phony/country_codes_spec.rb +8 -53
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad23d7833af7d5c22a7a2157ac509e762c16ad39
|
4
|
+
data.tar.gz: 0d2aab1c49bdac649ce7d2c0a93e4acf2234f714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 089b667c5e5651ce2b8b1ae611cd74fa84cd32b71207a1246aa143c96c78ed50e29799e9cda94def9dee22027c68a0c06753fdaef2e00a531d5aca9c251c24ac
|
7
|
+
data.tar.gz: cc36ddfa8d3afef335858bcf700fc726cfcc2fcc8d87db4327356f09eb09b54b9df595a84e8cdf971fc7935e6659da417303fd3399fdb9e71abe9d520d6d4813
|
data/lib/phony.rb
CHANGED
@@ -177,9 +177,7 @@ module Phony
|
|
177
177
|
# Phony.split!("13015550100") # => ["1", "301", "555", "0100"]
|
178
178
|
#
|
179
179
|
def split! phone_number
|
180
|
-
|
181
|
-
parts.delete_at 1
|
182
|
-
parts
|
180
|
+
@codes.split phone_number
|
183
181
|
end
|
184
182
|
|
185
183
|
# Formats a normalized E164 number according to a country's formatting scheme.
|
data/lib/phony/countries.rb
CHANGED
@@ -51,9 +51,11 @@ Phony.define do
|
|
51
51
|
#
|
52
52
|
country '1',
|
53
53
|
# The US has a delimiter between NDC and local number.
|
54
|
-
trunk('1%s', normalize: true) | # http://en.wikipedia.org/wiki/Trunk_prefix
|
54
|
+
trunk('1%s', normalize: true, format: false) | # http://en.wikipedia.org/wiki/Trunk_prefix
|
55
55
|
fixed(3) >> split(3,4),
|
56
|
-
:invalid_ndcs => /[0-1]\d{2}|[3-9]11
|
56
|
+
:invalid_ndcs => /[0-1]\d{2}|[3-9]11/,
|
57
|
+
:parentheses => true,
|
58
|
+
:local_space => :-
|
57
59
|
|
58
60
|
# Kazakhstan (Republic of) & Russsian Federation.
|
59
61
|
# also Abhasia and South Osetia autonomous regions / recognized by some states as independent countries
|
data/lib/phony/country.rb
CHANGED
@@ -4,15 +4,24 @@ module Phony
|
|
4
4
|
#
|
5
5
|
class Country
|
6
6
|
|
7
|
-
attr_reader :format, :space, :local_space
|
8
7
|
attr_accessor :codes
|
9
8
|
|
10
|
-
|
9
|
+
@@international_absolute_format = '+%s%s%s%s%s'
|
10
|
+
@@international_relative_format = '00%s%s%s%s%s'
|
11
|
+
@@national_format = '%s%s%s%s'
|
12
|
+
|
13
|
+
@@default_space = ' '
|
14
|
+
@@default_local_space = ' '
|
15
|
+
@@default_parentheses = false
|
16
|
+
|
17
|
+
# TODO Doc.
|
11
18
|
#
|
12
19
|
def initialize *codes
|
13
20
|
@codes = codes
|
14
21
|
end
|
15
22
|
|
23
|
+
# DSL method.
|
24
|
+
#
|
16
25
|
# Chain two codes together.
|
17
26
|
#
|
18
27
|
def | other
|
@@ -26,10 +35,13 @@ module Phony
|
|
26
35
|
#
|
27
36
|
def with cc, options = {}
|
28
37
|
@cc = cc
|
38
|
+
|
29
39
|
@invalid_ndcs = options[:invalid_ndcs]
|
40
|
+
|
30
41
|
@format = options[:format]
|
31
42
|
@space = options[:space]
|
32
43
|
@local_space = options[:local_space]
|
44
|
+
@parentheses = options[:parentheses]
|
33
45
|
end
|
34
46
|
|
35
47
|
# A number is split with the code handlers as given in the initializer.
|
@@ -53,6 +65,68 @@ module Phony
|
|
53
65
|
return [code.local_splitter, zero, ndc, *rest] if rest && !rest.empty?
|
54
66
|
end
|
55
67
|
end
|
68
|
+
|
69
|
+
# Format the number, given the national part of it.
|
70
|
+
#
|
71
|
+
def format national_number, options = {}
|
72
|
+
type = options[:format] || @format
|
73
|
+
space = options[:spaces] || @space || @@default_space
|
74
|
+
local_space = options[:local_spaces] || @local_space || space || @@default_local_space
|
75
|
+
parentheses = options[:parentheses]
|
76
|
+
parentheses = @parentheses || @@default_parentheses if parentheses.nil?
|
77
|
+
use_trunk = options[:trunk]
|
78
|
+
|
79
|
+
trunk, ndc, *local_pieces = split national_number
|
80
|
+
|
81
|
+
local = format_local local_pieces, local_space
|
82
|
+
|
83
|
+
format_cc_ndc trunk, ndc, local, type, space, parentheses, use_trunk
|
84
|
+
end
|
85
|
+
def format_local local, local_space
|
86
|
+
if local.empty?
|
87
|
+
EMPTY_STRING
|
88
|
+
else
|
89
|
+
local.compact!
|
90
|
+
local.join local_space.to_s
|
91
|
+
end
|
92
|
+
end
|
93
|
+
def format_cc_ndc trunk, ndc, local, type, space, parentheses, use_trunk
|
94
|
+
case type
|
95
|
+
when String
|
96
|
+
trunk &&= trunk.format(space, use_trunk)
|
97
|
+
type % { :trunk => trunk, :cc => @cc, :ndc => ndc, :local => local }
|
98
|
+
when nil, :international_absolute, :international, :+
|
99
|
+
if ndc
|
100
|
+
ndc = parentheses ? "(#{ndc})" : ndc
|
101
|
+
format_with_ndc(@@international_absolute_format, @cc, ndc, local, space)
|
102
|
+
else
|
103
|
+
format_without_ndc(@@international_absolute_format, @cc, local, space)
|
104
|
+
end
|
105
|
+
when :international_relative
|
106
|
+
if ndc
|
107
|
+
ndc = parentheses ? "(#{ndc})" : ndc
|
108
|
+
format_with_ndc(@@international_relative_format, @cc, ndc, local, space)
|
109
|
+
else
|
110
|
+
format_without_ndc(@@international_relative_format, @cc, local, space)
|
111
|
+
end
|
112
|
+
when :national
|
113
|
+
trunk &&= trunk.format(space, use_trunk)
|
114
|
+
if ndc && !ndc.empty?
|
115
|
+
ndc = parentheses ? "(#{ndc})" : ndc
|
116
|
+
@@national_format % [trunk, ndc, space, local]
|
117
|
+
else
|
118
|
+
@@national_format % [trunk, nil, nil, local]
|
119
|
+
end
|
120
|
+
when :local
|
121
|
+
local
|
122
|
+
end
|
123
|
+
end
|
124
|
+
def format_with_ndc format, cc, ndc, local, space
|
125
|
+
format % [cc, space, ndc, space, local]
|
126
|
+
end
|
127
|
+
def format_without_ndc format, cc, local, space
|
128
|
+
format % [cc, space, local, nil, nil]
|
129
|
+
end
|
56
130
|
|
57
131
|
# Cleans all non-numeric characters.
|
58
132
|
#
|
data/lib/phony/country_codes.rb
CHANGED
@@ -9,18 +9,23 @@ module Phony
|
|
9
9
|
attr_reader :countries
|
10
10
|
attr_accessor :international_absolute_format, :international_relative_format, :national_format
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
@international_relative_format = '00%s%s%s%s%s'
|
15
|
-
@national_format = '%s%s%s%s'
|
16
|
-
|
17
|
-
@default_space = ' '
|
18
|
-
@default_local_space = ' '
|
19
|
-
end
|
20
|
-
|
12
|
+
# Singleton instance.
|
13
|
+
#
|
21
14
|
def self.instance
|
22
15
|
@instance ||= new
|
23
16
|
end
|
17
|
+
|
18
|
+
# Add the given country to the mapping under the
|
19
|
+
# given country code.
|
20
|
+
#
|
21
|
+
def add country_code, country
|
22
|
+
country_code = country_code.to_s
|
23
|
+
optimized_country_code_access = country_code.size
|
24
|
+
|
25
|
+
@countries ||= {}
|
26
|
+
@countries[optimized_country_code_access] ||= {}
|
27
|
+
@countries[optimized_country_code_access][country_code] = country
|
28
|
+
end
|
24
29
|
|
25
30
|
# Get the Country object for the given CC.
|
26
31
|
#
|
@@ -42,18 +47,6 @@ module Phony
|
|
42
47
|
number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
|
43
48
|
end
|
44
49
|
|
45
|
-
# Adds the country code to the front
|
46
|
-
# if it does not already start with it.
|
47
|
-
#
|
48
|
-
# Note: This won't be correct in some cases, but it is the best we can do.
|
49
|
-
#
|
50
|
-
def countrify number, cc
|
51
|
-
countrify!(number, cc) || number
|
52
|
-
end
|
53
|
-
def countrify! number, cc
|
54
|
-
number.sub!(/\A/, cc) # @countrify_regex, @cc
|
55
|
-
end
|
56
|
-
|
57
50
|
# 00 for the standard international call prefix.
|
58
51
|
# http://en.wikipedia.org/wiki/List_of_international_call_prefixes
|
59
52
|
#
|
@@ -70,7 +63,7 @@ module Phony
|
|
70
63
|
self[cc]
|
71
64
|
else
|
72
65
|
clean! number
|
73
|
-
country, cc, number =
|
66
|
+
country, cc, number = partial_split number
|
74
67
|
country
|
75
68
|
end
|
76
69
|
number = country.normalize number
|
@@ -80,114 +73,21 @@ module Phony
|
|
80
73
|
# Splits this number into cc, ndc and locally split number parts.
|
81
74
|
#
|
82
75
|
def split number
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def internal_split number
|
88
|
-
country, cc, rest = split_cc number
|
89
|
-
[country, cc, *country.split(rest)]
|
76
|
+
# TODO Think about reordering.
|
77
|
+
country, cc, trunk, *pieces = internal_split number
|
78
|
+
[cc, *pieces]
|
90
79
|
end
|
91
80
|
|
81
|
+
# Format the number.
|
82
|
+
#
|
92
83
|
def format number, options = {}
|
93
|
-
country,
|
94
|
-
|
95
|
-
options[:format] || country.format,
|
96
|
-
options[:spaces] || country.space || @default_space,
|
97
|
-
options[:local_spaces] || country.local_space || options[:spaces] || @default_local_space,
|
98
|
-
cc,
|
99
|
-
options[:trunk] == false ? nil : trunk,
|
100
|
-
ndc,
|
101
|
-
*parts
|
84
|
+
country, _, national = partial_split number
|
85
|
+
country.format national, options
|
102
86
|
end
|
103
87
|
alias formatted format
|
104
88
|
|
105
|
-
#
|
106
|
-
#
|
107
|
-
def format_cc_ndc_local format, space, local_space, cc, trunk, ndc, *parts
|
108
|
-
local = if parts.empty?
|
109
|
-
EMPTY_STRING
|
110
|
-
else
|
111
|
-
format_local(local_space, parts) unless parts.empty?
|
112
|
-
end
|
113
|
-
|
114
|
-
format_cc_ndc format, space, cc, trunk, ndc, local
|
115
|
-
|
116
|
-
# cc_ndc = cc_ndc.slice 0...cc_ndc.rindex(space.to_s) if parts.empty?
|
117
|
-
end
|
118
|
-
def format_cc_ndc format, space, cc, trunk, ndc, local
|
119
|
-
case format
|
120
|
-
when String
|
121
|
-
trunk = trunk % space if trunk && trunk.size > 1
|
122
|
-
format % { :trunk => trunk, :cc => cc, :ndc => ndc, :local => local }
|
123
|
-
when nil, :international_absolute, :international, :+
|
124
|
-
ndc ?
|
125
|
-
format_with_ndc(@international_absolute_format, cc, ndc, local, space) :
|
126
|
-
format_without_ndc(@international_absolute_format, cc, local, space)
|
127
|
-
when :international_relative
|
128
|
-
ndc ?
|
129
|
-
format_with_ndc(@international_relative_format, cc, ndc, local, space) :
|
130
|
-
format_without_ndc(@international_relative_format, cc, local, space)
|
131
|
-
when :national
|
132
|
-
# Replaces the %s in the trunk code with a "space".
|
133
|
-
trunk = trunk % space if trunk && trunk.size > 1
|
134
|
-
ndc && !ndc.empty? ?
|
135
|
-
@national_format % [trunk, ndc, space, local] :
|
136
|
-
@national_format % [trunk, nil, nil, local]
|
137
|
-
when :local
|
138
|
-
local
|
139
|
-
end
|
140
|
-
end
|
141
|
-
def format_local local_space, parts_ary
|
142
|
-
parts_ary.compact!
|
143
|
-
parts_ary.join local_space.to_s
|
144
|
-
end
|
145
|
-
|
146
|
-
def format_with_ndc format, cc, ndc, local, space
|
147
|
-
format % [cc, space, ndc, space, local]
|
148
|
-
end
|
149
|
-
def format_without_ndc format, cc, local, space
|
150
|
-
format % [cc, space, local, nil, nil]
|
151
|
-
end
|
152
|
-
|
153
|
-
#
|
154
|
-
#
|
155
|
-
def service? number
|
156
|
-
country, _, rest = split_cc number
|
157
|
-
country.service? rest
|
158
|
-
end
|
159
|
-
def mobile? number
|
160
|
-
country, _, rest = split_cc number
|
161
|
-
country.mobile? rest
|
162
|
-
end
|
163
|
-
def landline? number
|
164
|
-
country, _, rest = split_cc number
|
165
|
-
country.landline? rest
|
166
|
-
end
|
167
|
-
|
168
|
-
# Is the given number a vanity number?
|
169
|
-
#
|
170
|
-
def vanity? number
|
171
|
-
country, _, rest = split_cc number
|
172
|
-
country.vanity? rest
|
173
|
-
end
|
174
|
-
# Converts a vanity number into a normalized E164 number.
|
89
|
+
# Is this number plausible?
|
175
90
|
#
|
176
|
-
def vanity_to_number vanity_number
|
177
|
-
country, cc, rest = split_cc vanity_number
|
178
|
-
"#{cc}#{country.vanity_to_number(rest)}"
|
179
|
-
end
|
180
|
-
|
181
|
-
def split_cc rest
|
182
|
-
presumed_cc = ''
|
183
|
-
1.upto(3) do |i|
|
184
|
-
presumed_cc << rest.slice!(0..0)
|
185
|
-
country = countries[i][presumed_cc]
|
186
|
-
return [country, presumed_cc, rest] if country
|
187
|
-
end
|
188
|
-
# This line is never reached as CCs are in prefix code.
|
189
|
-
end
|
190
|
-
|
191
91
|
def plausible? number, hints = {}
|
192
92
|
normalized = clean number
|
193
93
|
|
@@ -195,7 +95,7 @@ module Phony
|
|
195
95
|
#
|
196
96
|
return false unless (4..15) === normalized.size
|
197
97
|
|
198
|
-
country, cc, rest =
|
98
|
+
country, cc, rest = partial_split normalized
|
199
99
|
|
200
100
|
# Country code plausible?
|
201
101
|
#
|
@@ -208,25 +108,60 @@ module Phony
|
|
208
108
|
rescue StandardError
|
209
109
|
return false
|
210
110
|
end
|
211
|
-
|
212
|
-
#
|
213
|
-
# #
|
214
|
-
# def self.with_cc cc
|
215
|
-
# mapping[cc.size][cc.to_s]
|
216
|
-
# end
|
217
|
-
|
218
|
-
# Add the given country to the mapping under the
|
219
|
-
# given country code.
|
111
|
+
|
112
|
+
# Is the given number a vanity number?
|
220
113
|
#
|
221
|
-
def
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
114
|
+
def vanity? number
|
115
|
+
country, _, national = partial_split number
|
116
|
+
country.vanity? national
|
117
|
+
end
|
118
|
+
# Converts a vanity number into a normalized E164 number.
|
119
|
+
#
|
120
|
+
def vanity_to_number vanity_number
|
121
|
+
country, cc, national = partial_split vanity_number
|
122
|
+
"#{cc}#{country.vanity_to_number(national)}"
|
228
123
|
end
|
229
124
|
|
125
|
+
private
|
126
|
+
|
127
|
+
# Return a country for the number.
|
128
|
+
#
|
129
|
+
def country_for number
|
130
|
+
country, _ = partial_split number
|
131
|
+
country
|
132
|
+
end
|
133
|
+
|
134
|
+
# Return a country and the split pieces of a number.
|
135
|
+
#
|
136
|
+
def internal_split number
|
137
|
+
country, cc, national = partial_split number
|
138
|
+
[country, cc, *country.split(national)]
|
139
|
+
end
|
140
|
+
|
141
|
+
# Split off the country and the cc, and also return the national number part.
|
142
|
+
#
|
143
|
+
def partial_split number
|
144
|
+
cc = ''
|
145
|
+
1.upto(3) do |i|
|
146
|
+
cc << number.slice!(0..0)
|
147
|
+
country = countries[i][cc]
|
148
|
+
return [country, cc, number] if country
|
149
|
+
end
|
150
|
+
# This line is never reached as CCs are in prefix code.
|
151
|
+
end
|
152
|
+
|
153
|
+
# Adds the country code to the front
|
154
|
+
# if it does not already start with it.
|
155
|
+
#
|
156
|
+
# Note: This won't be correct in some cases, but it is the best we can do.
|
157
|
+
#
|
158
|
+
def countrify number, cc
|
159
|
+
countrify!(number, cc) || number
|
160
|
+
end
|
161
|
+
def countrify! number, cc
|
162
|
+
number.sub!(/\A/, cc) # @countrify_regex, @cc
|
163
|
+
end
|
164
|
+
|
230
165
|
end
|
231
166
|
|
232
167
|
end
|
data/lib/phony/trunk_code.rb
CHANGED
@@ -14,6 +14,7 @@ module Phony
|
|
14
14
|
@trunk_code_replacement = /\A#{code.gsub(%r{%s}, '')}/
|
15
15
|
@normalize = options[:normalize] || options[:normalize].nil?
|
16
16
|
@split = options[:split]
|
17
|
+
@format = options[:format] || options[:format].nil?
|
17
18
|
end
|
18
19
|
|
19
20
|
# Prepends itself to the other codes.
|
@@ -28,13 +29,21 @@ module Phony
|
|
28
29
|
#
|
29
30
|
def split national_number
|
30
31
|
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split
|
31
|
-
return [
|
32
|
+
return [self, national_number]
|
32
33
|
end
|
33
34
|
|
35
|
+
# Normalize normalizes the given national number.
|
36
|
+
#
|
34
37
|
def normalize national_number
|
35
38
|
national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @normalize
|
36
39
|
return national_number
|
37
40
|
end
|
41
|
+
|
42
|
+
# Format the trunk code using the spaces given.
|
43
|
+
#
|
44
|
+
def format space, force = nil
|
45
|
+
@code.size > 1 ? @code % space : @code if force || @format
|
46
|
+
end
|
38
47
|
|
39
48
|
end
|
40
49
|
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# This is a very helpful page for phone number formatting:
|
4
|
+
# http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers
|
5
|
+
#
|
3
6
|
describe 'Phony#format' do
|
4
7
|
|
5
8
|
describe 'cases' do
|
@@ -26,7 +29,7 @@ describe 'Phony#format' do
|
|
26
29
|
Phony.format('71234567890', :format => '+%{cc} (%{trunk}%{ndc}) %{local}', :local_spaces => '-').should eql '+7 (8123) 45-67890'
|
27
30
|
end
|
28
31
|
it 'handles an American example correctly' do
|
29
|
-
Phony.format('13015550100', :format => '+%{cc} %{trunk}%{ndc} %{local}', :local_spaces => '-').should eql '+1
|
32
|
+
Phony.format('13015550100', :format => '+%{cc} %{trunk}%{ndc} %{local}', :local_spaces => '-').should eql '+1 301 555-0100'
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
@@ -86,19 +89,26 @@ describe 'Phony#format' do
|
|
86
89
|
it { Phony.format('4233841148', :format => :international_relative, :spaces => :-).should eql '00423-384-11-48' }
|
87
90
|
end
|
88
91
|
describe 'NANP' do
|
89
|
-
it { Phony.format('18705551122').should eql '+1 870 555
|
90
|
-
it { Phony.format('18091231234', :format => :international).should eql '+1 809 123
|
91
|
-
it { Phony.format('18091231234', :format => :international, :spaces => '').should eql '+
|
92
|
+
it { Phony.format('18705551122').should eql '+1 (870) 555-1122' }
|
93
|
+
it { Phony.format('18091231234', :format => :international).should eql '+1 (809) 123-1234' }
|
94
|
+
it { Phony.format('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234' }
|
92
95
|
# Gets a trunk code.
|
93
|
-
it { Phony.format('14152223333', :format => :national).should eql '
|
96
|
+
it { Phony.format('14152223333', :format => :national).should eql '(415) 222-3333' }
|
94
97
|
# Does not show a trunk code.
|
95
|
-
it { Phony.format('14152223333', :format => :national
|
96
|
-
it { Phony.format('18091231234', :format => :international, :spaces => :-).should eql '+1-809-123-1234' }
|
97
|
-
|
98
|
-
|
98
|
+
it { Phony.format('14152223333', :format => :national).should eql '(415) 222-3333' }
|
99
|
+
it { Phony.format('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234' }
|
100
|
+
it { Phony.format('14159224711', :format => :national).should eql '(415) 922-4711' }
|
101
|
+
# With forced trunk.
|
102
|
+
it { Phony.format('14159224711', :format => :national, :trunk => true).should eql '1 (415) 922-4711' }
|
103
|
+
it { Phony.format('14159224711', :format => :national, :trunk => false).should eql '(415) 922-4711' }
|
104
|
+
# With forced parentheses.
|
105
|
+
it { Phony.format('14159224711', :format => :national, :parentheses => true).should eql '(415) 922-4711' }
|
106
|
+
it { Phony.format('14159224711', :format => :national, :parentheses => false).should eql '415 922-4711' }
|
99
107
|
end
|
100
108
|
describe 'Netherlands' do
|
101
109
|
it { Phony.format('311012341234', :format => :national).should eql '010 123 41234' }
|
110
|
+
# With forced trunk.
|
111
|
+
it { Phony.format('311012341234', :format => :national, :trunk => true).should eql '010 123 41234' }
|
102
112
|
end
|
103
113
|
describe 'New Zealand' do
|
104
114
|
it { Phony.format('6421123456').should eql '+64 21 123 456' }
|
@@ -6,54 +6,6 @@ describe Phony::CountryCodes do
|
|
6
6
|
@countries = Phony::CountryCodes.instance
|
7
7
|
end
|
8
8
|
|
9
|
-
describe 'international_absolute_format=' do
|
10
|
-
it 'formats correctly' do
|
11
|
-
@countries.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
12
|
-
end
|
13
|
-
it 'formats correctly' do
|
14
|
-
old_format = @countries.international_absolute_format
|
15
|
-
@countries.international_absolute_format = '!!! %s%s%s%s%s'
|
16
|
-
|
17
|
-
@countries.formatted('41443643532', :format => :international).should eql '!!! 41 44 364 35 32'
|
18
|
-
|
19
|
-
@countries.international_absolute_format = old_format
|
20
|
-
end
|
21
|
-
end
|
22
|
-
describe 'international_relative_format=' do
|
23
|
-
it 'formats correctly' do
|
24
|
-
@countries.formatted('41443643532', :format => :international_relative).should eql '0041 44 364 35 32'
|
25
|
-
end
|
26
|
-
it 'formats correctly' do
|
27
|
-
old_format = @countries.international_relative_format
|
28
|
-
@countries.international_relative_format = '000 %s%s%s%s%s'
|
29
|
-
|
30
|
-
@countries.formatted('41443643532', :format => :international_relative).should eql '000 41 44 364 35 32'
|
31
|
-
|
32
|
-
@countries.international_relative_format = old_format
|
33
|
-
end
|
34
|
-
end
|
35
|
-
describe 'national_format=' do
|
36
|
-
it 'formats correctly' do
|
37
|
-
@countries.formatted('41443643532', :format => :international_relative).should eql '0041 44 364 35 32'
|
38
|
-
end
|
39
|
-
it 'formats correctly' do
|
40
|
-
old_format = @countries.national_format
|
41
|
-
@countries.national_format = '%s%s%s%s'
|
42
|
-
|
43
|
-
# Removes CC 1, but adds national call prefix 1.
|
44
|
-
#
|
45
|
-
@countries.formatted('11231231234', :format => :national).should eql '1 123 123 1234'
|
46
|
-
|
47
|
-
@countries.national_format = old_format
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'split' do
|
52
|
-
it 'splits correctly' do
|
53
|
-
@countries.split('41443643532').should eql ['41', '0', '44', '364', '35', '32']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
9
|
describe 'formatted' do
|
58
10
|
it 'formats correctly' do
|
59
11
|
@countries.formatted('41443643532', :format => :international, :spaces => :-).should eql '+41-44-364-35-32'
|
@@ -78,7 +30,10 @@ describe Phony::CountryCodes do
|
|
78
30
|
@countries.formatted('85512239123', :format => :national).should eql '012 239 123'
|
79
31
|
end
|
80
32
|
it 'formats the US correctly' do
|
81
|
-
@countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '
|
33
|
+
@countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
34
|
+
end
|
35
|
+
it 'formats the US correctly' do
|
36
|
+
@countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '(800)-555-1212'
|
82
37
|
end
|
83
38
|
end
|
84
39
|
context 'default' do
|
@@ -92,7 +47,7 @@ describe Phony::CountryCodes do
|
|
92
47
|
@countries.formatted('43198110').should eql '+43 1 98110'
|
93
48
|
end
|
94
49
|
it "should format american numbers" do
|
95
|
-
@countries.formatted('18705551122').should eql '+1 870 555
|
50
|
+
@countries.formatted('18705551122').should eql '+1 (870) 555-1122'
|
96
51
|
end
|
97
52
|
it "should format irish numbers" do
|
98
53
|
@countries.formatted('35311234567').should eql '+353 1 123 4567'
|
@@ -100,7 +55,7 @@ describe Phony::CountryCodes do
|
|
100
55
|
end
|
101
56
|
describe "international" do
|
102
57
|
it "should format north american numbers" do
|
103
|
-
@countries.formatted('18091231234', :format => :international).should eql '+1 809 123
|
58
|
+
@countries.formatted('18091231234', :format => :international).should eql '+1 (809) 123-1234'
|
104
59
|
end
|
105
60
|
it "should format austrian numbers" do
|
106
61
|
@countries.formatted('43198110', :format => :international).should eql '+43 1 98110'
|
@@ -149,7 +104,7 @@ describe Phony::CountryCodes do
|
|
149
104
|
end
|
150
105
|
context 'with no spaces' do
|
151
106
|
it "should format north american numbers" do
|
152
|
-
Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+
|
107
|
+
Phony.formatted('18091231234', :format => :international, :spaces => '').should eql '+1(809)123-1234'
|
153
108
|
end
|
154
109
|
it "should format austrian numbers" do
|
155
110
|
Phony.formatted('43198110', :format => :international, :spaces => '').should eql '+43198110'
|
@@ -172,7 +127,7 @@ describe Phony::CountryCodes do
|
|
172
127
|
Phony.formatted('41443643532', :format => :international).should eql '+41 44 364 35 32'
|
173
128
|
end
|
174
129
|
it "should format north american numbers" do
|
175
|
-
Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-809-123-1234'
|
130
|
+
Phony.formatted('18091231234', :format => :international, :spaces => :-).should eql '+1-(809)-123-1234'
|
176
131
|
end
|
177
132
|
it "should format austrian numbers" do
|
178
133
|
Phony.formatted('43198110', :format => :international, :spaces => :-).should eql '+43-1-98110'
|
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.
|
4
|
+
version: 2.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 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
|