phony 2.7.1 → 2.8.1

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: b98c697126632e45ed3dfc739db33485690e62eb
4
- data.tar.gz: 9ab5998082caef35ab68faa2193986bd46574ebd
3
+ metadata.gz: dd36ebf747e5d7267d9ebc733be37f3e44fe9a03
4
+ data.tar.gz: 09ea3cc54099fe93a3a1e8344989a6fe635d34d8
5
5
  SHA512:
6
- metadata.gz: fa170648c998124add0388d410af347dc2133ec4b8cd3b3716ef470d6e5040cd9c6842f1eab48ce9ebdcf0f281ed2e8ac720408fc2f3a6d8e2e9a69226279c28
7
- data.tar.gz: a985480e774bedda8e3b6f3628d00e3b857b28f36d7246a6ff9616079a26cf02b1135ec402a5c9e6ae7dd90771d2976168565f11831ae61b2efbcd2147c11b48
6
+ metadata.gz: 53b4870d90edfe19ef2bfedea402a9e1eb23452fb451170bdd14644226b55a95016020b1c3c35a2c654366e3e671a24880b52581a9eea1076131594f8c363268
7
+ data.tar.gz: c211186914ba9feb78535ad85e7018bd4b60718054e948b737a8531df5cbe2340830b881804246698e31f079b8fd39de3b83eb63ba558a2c244db1354deaacdc
@@ -29,6 +29,7 @@ require File.expand_path '../phony/countries/croatia', __FILE__
29
29
  require File.expand_path '../phony/countries/china', __FILE__
30
30
  require File.expand_path '../phony/countries/georgia', __FILE__
31
31
  require File.expand_path '../phony/countries/germany', __FILE__
32
+ require File.expand_path '../phony/countries/guinea', __FILE__
32
33
  require File.expand_path '../phony/countries/india', __FILE__
33
34
  require File.expand_path '../phony/countries/indonesia', __FILE__
34
35
  require File.expand_path '../phony/countries/ireland', __FILE__
@@ -31,7 +31,8 @@ Phony.define do
31
31
  # USA, Canada, etc.
32
32
  #
33
33
  country '1',
34
- trunk('1 ', normalize: true) | # http://en.wikipedia.org/wiki/Trunk_prefix
34
+ # The US has a delimiter between NDC and local number.
35
+ trunk('1%s', normalize: true) | # http://en.wikipedia.org/wiki/Trunk_prefix
35
36
  fixed(3) >> split(3,4),
36
37
  :invalid_ndcs => ['911']
37
38
 
@@ -302,7 +303,9 @@ Phony.define do
302
303
  country '221', none >> split(4,5) # Senegal http://www.wtng.info/wtng-221-sn.html
303
304
  country '222', none >> split(4,4) # Mauritania http://www.wtng.info/wtng-222-mr.html
304
305
  country '223', none >> split(4,4) # Mali http://www.wtng.info/wtng-223-ml.html
305
- country '224', none >> split(4,4) # Guinea http://www.wtng.info/wtng-224-gn.html
306
+
307
+ # country '224' # Guinea, see special file
308
+
306
309
  country '225', none >> split(4,4) # Côte d'Ivoire http://www.wtng.info/wtng-225-ci.html
307
310
  country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
308
311
  country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
@@ -0,0 +1,44 @@
1
+ # Guinea (sometimes Guinea-Conakry; officially Republic of Guinea)
2
+ # http://www.itu.int/oth/T020200005B/en
3
+
4
+ land_ndcs_with_4_digits = [
5
+ '3031', # Boké
6
+ '3046', # Boussoura
7
+ *['3041', '3043', '3045', '3047'], # Conakry
8
+ '3069', # Delaba
9
+ '3081', # Faranah
10
+ '3024', # Fria
11
+ '3097', # Guéckédou
12
+ '3032', # Kamsar
13
+ '3071', # Kankan
14
+ '3061', # Kindia
15
+ '3098', # Kissidougou
16
+ '3051', # Labé
17
+ '3094', # Macenta
18
+ '3068', # Mamou
19
+ '3091', # N'Zérékoré
20
+ '3053', # Pita
21
+ '3042' # Sangoya
22
+ ]
23
+
24
+ land_ndcs_with_5_digits = [
25
+ '30613' # Télimélé
26
+ ]
27
+
28
+ mobile_ndcs_with_3_digits = [
29
+ ('660'..'669').to_a, # Areeba
30
+ ('620'..'629').to_a, # Orange
31
+ ('650'..'659').to_a, # Cellcom
32
+ ('630'..'639').to_a, # Intercel
33
+ ('600'..'609').to_a # Sotelgui
34
+ ]
35
+
36
+ Phony.define do
37
+ country '224',
38
+ one_of(land_ndcs_with_5_digits) >> split(2, 2) | # 2-2-2-2
39
+ one_of(land_ndcs_with_4_digits) >> split(2, 2) | # 2-2-2-2
40
+ one_of(mobile_ndcs_with_3_digits) >> split(2, 2, 2) | # 3-2-2-2
41
+ match(/^(7\d{2})\d{6}/) >> split(2, 2) | # voip numbers
42
+ fixed(3) >> split(2, 2, 2) | # catch all formatter
43
+ fixed(4) >> split(2, 2) # catch all formatter
44
+ end
@@ -20,13 +20,13 @@ module Phony
20
20
  def self.instance
21
21
  @instance ||= new
22
22
  end
23
-
23
+
24
24
  # Get the Country object for the given CC.
25
25
  #
26
26
  def [] cc
27
27
  countries[cc.size][cc]
28
28
  end
29
-
29
+
30
30
  # Clean number of all non-numeric characters, initial zeros or (0).
31
31
  #
32
32
  @@basic_cleaning_pattern = /\A00?|\(0\)|\D/
@@ -40,7 +40,7 @@ module Phony
40
40
  def clean! number
41
41
  number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
42
42
  end
43
-
43
+
44
44
  # Adds the country code to the front
45
45
  # if it does not already start with it.
46
46
  #
@@ -114,6 +114,8 @@ module Phony
114
114
  @international_relative_format % [cc, space, ndc] :
115
115
  @international_relative_format % [cc, nil, nil]
116
116
  when :national
117
+ # Replaces the %s in the trunk code with a "space".
118
+ trunk = trunk % space if trunk && trunk.size > 1
117
119
  ndc && !ndc.empty? ?
118
120
  @national_format % [trunk, ndc] :
119
121
  @national_format % [trunk, nil]
@@ -153,7 +155,7 @@ module Phony
153
155
  country, cc, rest = split_cc vanity_number
154
156
  "#{cc}#{country.vanity_to_number(rest)}"
155
157
  end
156
-
158
+
157
159
  def split_cc rest
158
160
  presumed_cc = ''
159
161
  1.upto(3) do |i|
@@ -163,14 +165,14 @@ module Phony
163
165
  end
164
166
  # This line is never reached as CCs are in prefix code.
165
167
  end
166
-
168
+
167
169
  def plausible? number, hints = {}
168
170
  normalized = clean number
169
171
 
170
172
  # False if it fails the basic check.
171
173
  #
172
174
  return false unless (4..15) === normalized.size
173
-
175
+
174
176
  country, cc, rest = split_cc normalized
175
177
 
176
178
  # Country code plausible?
@@ -11,7 +11,7 @@ module Phony
11
11
  #
12
12
  def initialize code, options = {}
13
13
  @code = code
14
- @trunk_code_replacement = /\A#{code.rstrip}/
14
+ @trunk_code_replacement = /\A#{code.gsub(%r{%s}, '')}/
15
15
  @normalize = options[:normalize] || options[:normalize].nil?
16
16
  @split = options[:split]
17
17
  end
@@ -531,7 +531,13 @@ describe 'plausibility' do
531
531
  it_is_correct_for 'Guadeloupe (French Department of)', :samples => '+590 123 456 789'
532
532
  it_is_correct_for 'Guatemala (Republic of)', :samples => ['+502 19 123 456 789',
533
533
  '+502 2 123 4567']
534
- it_is_correct_for 'Guinea', :samples => '+224 1234 5678'
534
+ context 'test' do
535
+ it_is_correct_for 'Guinea', :samples => [
536
+ '+224 664 12 34 56',
537
+ '+224 30 31 12 34',
538
+ '+224 3041 12 34'
539
+ ]
540
+ end
535
541
  it_is_correct_for 'Guinea-Bissau', :samples => '+245 728 6998'
536
542
  it_is_correct_for 'Guyana', :samples => '+592 263 1234'
537
543
  it_is_correct_for 'Honduras (Republic of)', :samples => '+504 12 961 637'
@@ -772,7 +772,8 @@ describe 'country descriptions' do
772
772
  it_splits '50221234567', ['502', '2', '123', '4567']
773
773
  end
774
774
  describe 'Guinea' do
775
- it_splits '22412345678', ['224', false, '1234', '5678']
775
+ it_splits '22430311234', ['224', '3031', '12', '34']
776
+ it_splits '224662123456', ['224', '662', '12', '34', '56']
776
777
  end
777
778
  describe 'Guinea-Bissau' do
778
779
  it_splits '2453837652', ['245', false, '383', '7652']
@@ -77,6 +77,9 @@ describe Phony::CountryCodes do
77
77
  it 'formats Cambodia correctly' do
78
78
  @countries.formatted('85512239123', :format => :national).should eql '012 239 123'
79
79
  end
80
+ it 'formats the US correctly' do
81
+ @countries.formatted('18005551212', :format => :national, :spaces => :-).should eql '1-800-555-1212'
82
+ end
80
83
  end
81
84
  context 'default' do
82
85
  it "should format swiss numbers" do
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.7.1
4
+ version: 2.8.1
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-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-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
@@ -31,6 +31,7 @@ files:
31
31
  - lib/phony/countries/croatia.rb
32
32
  - lib/phony/countries/georgia.rb
33
33
  - lib/phony/countries/germany.rb
34
+ - lib/phony/countries/guinea.rb
34
35
  - lib/phony/countries/india.rb
35
36
  - lib/phony/countries/indonesia.rb
36
37
  - lib/phony/countries/ireland.rb