phony 2.9.1 → 2.10.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149c31aeeafd871ed8e08201ade25314998da9e1
|
4
|
+
data.tar.gz: f9160fe2f2da602bbb10259d95f4a12bea57290b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62f5e978d9aa5331c924f14c86efc9251d057f6c140ef606ff8d33c05a10d30735a2aa2e2745ad1f68f4d6ed398405bf3933614af3d356c2b80527bf140b4d89
|
7
|
+
data.tar.gz: 3fec76eb6b6359e3ee54e9f6c373f062a1e25850650e1d7291db71d69005787269893e8463770973bf04e8b7125e8fa20e509ce18e773a28fc45b193ab9b6f09
|
@@ -124,5 +124,6 @@ Phony.define do
|
|
124
124
|
one_of(ndcs_with_7_subscriber_digits) >> split(3, 2, 2) |
|
125
125
|
one_of(%w(800)) >> split(3, 2, 2) | # Russia free number
|
126
126
|
one_of(%w(995344 9971 99744 9976 997)) >> split(2, 4) | # South Osetia
|
127
|
-
fixed(3) >> split(2, 5)
|
127
|
+
fixed(3) >> split(2, 5),
|
128
|
+
:local_space => :-
|
128
129
|
end
|
data/lib/phony/country.rb
CHANGED
@@ -3,7 +3,8 @@ module Phony
|
|
3
3
|
#
|
4
4
|
#
|
5
5
|
class Country
|
6
|
-
|
6
|
+
|
7
|
+
attr_reader :format, :space, :local_space
|
7
8
|
attr_accessor :codes
|
8
9
|
|
9
10
|
#
|
@@ -26,6 +27,9 @@ module Phony
|
|
26
27
|
def with cc, options = {}
|
27
28
|
@cc = cc
|
28
29
|
@invalid_ndcs = options[:invalid_ndcs] || []
|
30
|
+
@format = options[:format]
|
31
|
+
@space = options[:space]
|
32
|
+
@local_space = options[:local_space]
|
29
33
|
end
|
30
34
|
|
31
35
|
# A number is split with the code handlers as given in the initializer.
|
data/lib/phony/country_codes.rb
CHANGED
@@ -80,15 +80,22 @@ module Phony
|
|
80
80
|
# Splits this number into cc, ndc and locally split number parts.
|
81
81
|
#
|
82
82
|
def split number
|
83
|
+
country, *cc_split_rest = internal_split number
|
84
|
+
cc_split_rest
|
85
|
+
end
|
86
|
+
|
87
|
+
def internal_split number
|
83
88
|
country, cc, rest = split_cc number
|
84
|
-
[cc, *country.split(rest)]
|
89
|
+
[country, cc, *country.split(rest)]
|
85
90
|
end
|
86
91
|
|
87
92
|
def format number, options = {}
|
88
|
-
|
89
|
-
|
90
|
-
options[:
|
91
|
-
|
93
|
+
country, *split_number = internal_split number
|
94
|
+
format_cc_ndc_local \
|
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
|
+
*split_number
|
92
99
|
end
|
93
100
|
alias formatted format
|
94
101
|
|
@@ -70,13 +70,13 @@ describe 'Phony#format' do
|
|
70
70
|
Phony.format(Phony.normalize('+370 800 12345'), :format => :international).should eql '+370 800 12 345'
|
71
71
|
end
|
72
72
|
it 'should format Russian numbers' do
|
73
|
-
Phony.format(Phony.normalize('+7 812 123 4567'), :format => :international).should eql '+7 812 123
|
73
|
+
Phony.format(Phony.normalize('+7 812 123 4567'), :format => :international).should eql '+7 812 123-45-67'
|
74
74
|
end
|
75
75
|
it 'should format Russian numbers' do
|
76
76
|
Phony.format(Phony.normalize('+370 800 12345'), :format => :national).should eql '8800 12 345'
|
77
77
|
end
|
78
78
|
it 'should format Russian numbers' do
|
79
|
-
Phony.format(Phony.normalize('+7 812 123 4567'), :format => :national).should eql '8812 123
|
79
|
+
Phony.format(Phony.normalize('+7 812 123 4567'), :format => :national).should eql '8812 123-45-67'
|
80
80
|
end
|
81
81
|
end
|
82
82
|
describe 'international' do
|