phony 2.12.14 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/phony.rb +3 -0
- data/lib/phony/country_codes.rb +2 -1
- data/spec/functional/format_spec.rb +7 -4
- 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: e19199a57d389032d55f939a10cae73a78287d4d
|
4
|
+
data.tar.gz: 009422959de3b6f962b97413f94a74f4577cef18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a4d6045871dbc59c274fa902be56c78fbe50b754b473d2cc4340ae1426367ae13d52bdc47dcd42636985bf256b2eb753a362006a32d638103195c340115c37
|
7
|
+
data.tar.gz: fe40d41769928ef6a86eb949e88f67a259373392cb051989744a2d0d0e01785815ac6084c9733693691e028bcaaf660d0cec3bc852695d6506e7eb24e8c51f4f
|
data/lib/phony.rb
CHANGED
@@ -200,6 +200,9 @@ module Phony
|
|
200
200
|
# @example Format a NANP number in local format.
|
201
201
|
# Phony.format("13015550100", :format => :local) # => "555 0100"
|
202
202
|
#
|
203
|
+
# @example Format a NANP number in a specific format.
|
204
|
+
# Phony.format("13015550100", :format => '%{cc} (%{trunk}%{ndc}) %{local}') # => "555 0100"
|
205
|
+
#
|
203
206
|
def format phone_number, options = {}
|
204
207
|
raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
|
205
208
|
format! phone_number.dup, options
|
data/lib/phony/country_codes.rb
CHANGED
@@ -118,7 +118,8 @@ module Phony
|
|
118
118
|
def format_cc_ndc format, space, cc, trunk, ndc, local
|
119
119
|
case format
|
120
120
|
when String
|
121
|
-
|
121
|
+
trunk = trunk % space if trunk && trunk.size > 1
|
122
|
+
format % { :trunk => trunk, :cc => cc, :ndc => ndc, :local => local }
|
122
123
|
when nil, :international_absolute, :international, :+
|
123
124
|
ndc ?
|
124
125
|
format_with_ndc(@international_absolute_format, cc, ndc, local, space) :
|
@@ -13,17 +13,20 @@ describe 'Phony#format' do
|
|
13
13
|
|
14
14
|
describe 'Templates' do
|
15
15
|
it 'handles a basic template correctly' do
|
16
|
-
Phony.format('41443643532', :format => 'A%{cc}B%{
|
16
|
+
Phony.format('41443643532', :format => 'A%{cc}B%{trunk}C%{ndc}D%{local}').should eql 'A41B0C44D364 35 32'
|
17
17
|
end
|
18
18
|
it 'handles a funky template correctly' do
|
19
|
-
Phony.format('41443643532', :format => '%{local}%{ndc}%{cc}', :local_spaces => '').should eql '
|
19
|
+
Phony.format('41443643532', :format => '%{local} %{ndc} %{trunk} %{cc}', :local_spaces => '').should eql '3643532 44 0 41'
|
20
20
|
end
|
21
21
|
it 'handles local_spaces correctly' do
|
22
22
|
Phony.format('41443643532', :format => 'A%{cc}B%{ndc}C%{local}', :local_spaces => '/').should eql 'A41B44C364/35/32'
|
23
23
|
end
|
24
|
-
it 'handles a
|
24
|
+
it 'handles a Russian example correctly' do
|
25
25
|
# https://github.com/floere/phony/issues/214
|
26
|
-
Phony.format('71234567890', :format => '
|
26
|
+
Phony.format('71234567890', :format => '+%{cc} (%{trunk}%{ndc}) %{local}', :local_spaces => '-').should eql '+7 (8123) 45-67890'
|
27
|
+
end
|
28
|
+
it 'handles an American example correctly' do
|
29
|
+
Phony.format('13015550100', :format => '+%{cc} %{trunk}%{ndc} %{local}', :local_spaces => '-').should eql '+1 1 301 555-0100'
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
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.13.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-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
|