phony 2.14.3 → 2.14.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cefb31abcc6e35e6d23212b756d008129f3b6163
4
- data.tar.gz: db8fc173a095f55f81069fad6aebd4b13928bf23
3
+ metadata.gz: 5435a9ae0cf44bc8a237cbc27ba101bb7a1c563c
4
+ data.tar.gz: 61cad1ebaec418406a7376691e14cf88a196e1ba
5
5
  SHA512:
6
- metadata.gz: c5d504bf4dcb20083053fb1b84659c1a6b70c7270d9dbe0cf4f1a75ebfd6ee7bb48a085d0772711b24b15adfc7fa62e40f24c9010e9e567aff2f56010b235368
7
- data.tar.gz: 4e015f2dab7863d757dadc1b0829ea5fe13a7b391ab4b28d1604a658fde0b25c9a7b1e277aca3d33ba056f0511ec9a0ac35af40eb243f13bf0099bd64c0198a3
6
+ metadata.gz: b48ca5377879ea3588e65a5e33ad19fcafb672b211597514d6da9bd6681414c20b9df997709aedcdd91eda5d969348d95a6f7589c55aa36a0665e5e00869531c
7
+ data.tar.gz: cc47f05ba132af603a54ab8823ba8403c1ecadd35cf063edeeb90a5b31631259cb492b9d15c39ee4d53dc2deae0cc0c439101077ee87671341aae86b396d1a0a
data/README.textile CHANGED
@@ -27,7 +27,7 @@ E164 numbers are international numbers with a country dial prefix, usually an ar
27
27
 
28
28
  It currently handles the countries listed at the end of this README.
29
29
 
30
- It is covered by roughly 1,800 tests (June 2105).
30
+ It is covered by roughly 1,800 tests (June 2015).
31
31
  If it doesn't work, please "enter an issue":http://github.com/floere/phony/issues or better, fork and "send a pull request":http://github.com/floere/phony/pulls.
32
32
 
33
33
  h2. Installation
@@ -74,6 +74,10 @@ Split a number into its parts: CC, NDC, local.
74
74
 
75
75
  @Phony.split('3928061371').assert == ['39', '2', '806', '1371']@
76
76
 
77
+ NB If a country does not have an NDC, @#split@ will return @false@ in the NDC position, for example for Denmark:
78
+
79
+ @Phony.split('4512121212').assert == ['45', false, '12', '12', '12', '12']@
80
+
77
81
  h2. List of Handled Countries
78
82
 
79
83
  Mildly unmaintained list: Abhas, Afghan, Algerian, Argentinan, Austrian, Australian, Azerbaijani, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Liberian, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, Vietnamese, and Zambian numbers.
@@ -81,4 +85,4 @@ Mildly unmaintained list: Abhas, Afghan, Algerian, Argentinan, Austrian, Austral
81
85
  h2. License
82
86
 
83
87
  MIT.
84
- See "LICENSE":./LICENSE file.
88
+ See "LICENSE":./LICENSE file.
data/lib/phony/country.rb CHANGED
@@ -48,22 +48,26 @@ module Phony
48
48
  #
49
49
  # Note: If the ndc is nil, it will not return it.
50
50
  #
51
+ # @return [Trunk, String (ndc), Array<String> (national pieces)]
52
+ #
51
53
  def split national_number
54
+ _, trunk, ndc, *rest = internal_split national_number
55
+ [trunk, ndc, *rest]
56
+ end
57
+ #
58
+ #
59
+ # @return [Splitters::Local, Trunk, String (ndc), Array<String> (national pieces)]
60
+ #
61
+ def internal_split national_number
52
62
  trunk = nil
53
- @codes.each do |code|
54
- new_trunk, ndc, *rest = code.split national_number
63
+ @codes.each do |national_splitter|
64
+ new_trunk, ndc, *rest = national_splitter.split national_number
55
65
  trunk ||= new_trunk
56
- return [trunk, ndc, *rest] if rest && !rest.empty?
57
- end
58
- # Best effort in error case.
59
- #
60
- [trunk, national_number, []]
61
- end
62
- def split_ndc national_number
63
- @codes.each do |code|
64
- zero, ndc, *rest = code.split national_number
65
- return [code.local_splitter, zero, ndc, *rest] if rest && !rest.empty?
66
+ return [national_splitter.local_splitter, trunk, ndc, *rest] if rest && !rest.empty?
66
67
  end
68
+
69
+ # Best effort.
70
+ [nil, trunk, national_number, []]
67
71
  end
68
72
 
69
73
  # Format the number, given the national part of it.
@@ -163,7 +167,7 @@ module Phony
163
167
  # Tests for plausibility of this national number.
164
168
  #
165
169
  def plausible? rest, hints = {}
166
- local, _, ndc, *rest = split_ndc rest
170
+ local, _, ndc, *rest = internal_split rest
167
171
 
168
172
  # Element based checking.
169
173
  #
@@ -73,16 +73,20 @@ module Phony
73
73
  # Splits this number into cc, ndc and locally split number parts.
74
74
  #
75
75
  def split number
76
- # TODO Think about reordering.
77
- country, cc, trunk, *pieces = internal_split number
78
- [cc, *pieces]
76
+ # Split the number into country, cc, and national part.
77
+ country, cc, national_number = partial_split number
78
+
79
+ # Split the national number into ndc and local part.
80
+ trunk, ndc, *local = country.split national_number
81
+
82
+ [cc, ndc, *local]
79
83
  end
80
84
 
81
85
  # Format the number.
82
86
  #
83
87
  def format number, options = {}
84
- country, _, national = partial_split number
85
- country.format national, options
88
+ country, _, national_number = partial_split number
89
+ country.format national_number, options
86
90
  end
87
91
  alias formatted format
88
92
 
@@ -130,14 +134,7 @@ module Phony
130
134
  country, _ = partial_split number
131
135
  country
132
136
  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
-
137
+
141
138
  # Split off the country and the cc, and also return the national number part.
142
139
  #
143
140
  def partial_split number
@@ -9,7 +9,7 @@ module Phony
9
9
  def self.instance_for
10
10
  @instance ||= new
11
11
  end
12
-
12
+
13
13
  # "Splits" the national part of a phone number into a single piece.
14
14
  #
15
15
  # @param [String] national_number An national part of a number.
@@ -20,7 +20,7 @@ module Phony
20
20
  # Phony.split("1234567") # => ["1234567"]
21
21
  #
22
22
  def split national_number
23
- [national_number]
23
+ [nil, national_number]
24
24
  end
25
25
 
26
26
  # By default, the national part of a number is always plausible.
@@ -12,8 +12,8 @@ describe Phony::NationalSplitters::Default do
12
12
  let(:splitter) { described_class.instance_for }
13
13
 
14
14
  describe 'split' do
15
- it 'does not split' do
16
- splitter.split(:anything).should == [:anything]
15
+ it 'does only pretend split' do
16
+ splitter.split(:anything).should == [nil, :anything]
17
17
  end
18
18
  end
19
19
 
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.14.3
4
+ version: 2.14.4
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-06-12 00:00:00.000000000 Z
11
+ date: 2015-06-15 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