phony 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2RlOWNmOWMwNDk4YzU1ODgyMmYyMTYzYmQ1MjdlYWU2MzY3MDA5OA==
4
+ OTIxZGU3ZmFlODE0ZGE2ZDAwYWVlODk5N2VhZWJkNDgxNDdlYzg1ZQ==
5
5
  data.tar.gz: !binary |-
6
- OTc1YjNlM2Y0ZTRhYzFiMjVhZGYzZjEzMDM1NDFmMDVhMjIxYzYzOQ==
7
- !binary "U0hBNTEy":
6
+ ODZmM2Q4MDE2YTQ1NGZjZjg0N2EyZTAwNzc2NDUyNTY1NzA3ZWY5Mw==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- NzQwNjNiYjVmNzMwM2M3YWIxOTU0MTc4MzRiZWMxYWFmYjQ2Y2NkMDdkNTU0
10
- N2QyNzIxZGMwZWFiYzNiM2Q5ZDBkMWEwN2U0Y2QxMjY0NjZjZmI2ODc3OGIz
11
- NWVkODNkY2NmMDkzOTA2YjA5NzJiZjc2MTYyNTc0NGMzNGZhMGI=
9
+ ZTA0OWFmMzAzYzVmZjU1ZGZmYjcxMjI5YjljMGE1NTY0ZjU1ZDk4ZjgzNzc5
10
+ ZTY0ZTFhMWIwYjI1ZTUyNWUxZWM1M2Q2NTVjNWI0OWM3MGI4ZGY5ODRhZjc3
11
+ MjM5MzEzNDc3ZmEzMmQwZmVlZGVhNjg0ZmJiZGIxZDIyODBjMTE=
12
12
  data.tar.gz: !binary |-
13
- Y2VmYmU3MDMzOGNkZGMyNjk2NTgzNjhlMmIzNDBlYWIyMDUzNzNlYzY2NGUz
14
- OWJhYTk2ZWQ5Zjk3ODUwYjc0NWRhYTVkYjk2YjlkNjkwY2QwMmJkODViMTli
15
- YmJlYTNlMGE4YTA0MWYyYzBlYTA5OGRlMGRlY2I4MmRjMmQ5YTY=
13
+ OWM1NTM1YTE5ZDQ3NjQ2NWNiNzQzNzIxMjM1NGY5MTc4NjMyNzZiZDg0ZjI4
14
+ ZjUwOTQ1OWM4NmM4MjJiYzM0MDQwNTVkMDdkZjY2NjdlMzMzYzEyMmMzM2Vm
15
+ YjJmMmEyOWZhMzI5ZGU0NmU4NTkyZTgxMmVjNTU5ZjQyYTI0ZGY=
@@ -3,16 +3,22 @@
3
3
 
4
4
  h1. Phony
5
5
 
6
- Used in e.g.: "airbnb.com":http://airbnb.com, "restorm.com":http://restorm.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
6
+ The (admittedly crazy) goal of this Gem is to be able to format/split all phone numbers in the world.
7
+
8
+ Used in: "airbnb.com":http://airbnb.com, "restorm.com":http://restorm.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
7
9
 
8
10
  There's also a Rails wrapper: https://github.com/joost/phony_rails.
9
11
 
10
12
  h2. Description
11
13
 
12
- This gem can normalize, format and split E164 numbers. E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. Here's an example from Australia: +61 412 345 678. 61 is the country code of Australia, 4 denotes a mobile number and 12 345 678 is the subscriber number.
13
- "More about E164 numbers in this Wiki":http://en.wikipedia.org/wiki/E.164.
14
+ This gem normalizes, formats and splits *E164 phone numbers*. A valid E164 phone number *must* include a country code.
15
+
16
+ E164 numbers are international numbers with a country dial prefix, usually an area code and a subscriber number. For example, the Austalian number number @+61 412 345 678@ can be broken down into the following components:
17
+ * a country code of @61@
18
+ * a mobile number denoted by the @4@ (specific to Australia)
19
+ * a subscriber number of @12 345 678@
14
20
 
15
- The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
21
+ Learn more about E164 numbers "here":http://en.wikipedia.org/wiki/E.164.
16
22
 
17
23
  Currently handles 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, 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, and Vietnamese numbers.
18
24
 
@@ -22,9 +28,15 @@ If it doesn't, please "enter an issue":http://github.com/floere/phony/issues.
22
28
 
23
29
  h2. Installation
24
30
 
25
- <pre><code>gem install phony</code></pre>
31
+ Using with Rails? Check out: https://github.com/joost/phony_rails.
32
+
33
+ With Bundler:
34
+ Append @gem 'phony'@ to your @Gemfile@ and @bundle install@ it.
35
+
36
+ Without Bundler:
37
+ Run @gem install phony@ from your command line.
26
38
 
27
- h2(#examples). Some examples
39
+ h2(#usage). Usage
28
40
 
29
41
  h3(#plausibility). Plausibility
30
42
 
@@ -24,6 +24,7 @@ require File.expand_path '../phony/countries/austria', __FILE__
24
24
  require File.expand_path '../phony/countries/bangladesh', __FILE__
25
25
  require File.expand_path '../phony/countries/belarus', __FILE__
26
26
  require File.expand_path '../phony/countries/brazil', __FILE__
27
+ require File.expand_path '../phony/countries/cambodia', __FILE__
27
28
  require File.expand_path '../phony/countries/china', __FILE__
28
29
  require File.expand_path '../phony/countries/georgia', __FILE__
29
30
  require File.expand_path '../phony/countries/germany', __FILE__
@@ -67,13 +68,13 @@ module Phony
67
68
  super %Q{Phony could not normalize the given number. Is it a phone number?}
68
69
  end
69
70
  end
70
-
71
+
71
72
  # Phony uses a single country codes instance.
72
73
  #
73
74
  @codes = CountryCodes.instance
74
75
 
75
76
  class << self
76
-
77
+
77
78
  # Get the Country for the given CC.
78
79
  #
79
80
  # Example:
@@ -20,7 +20,7 @@
20
20
  # Note: The ones that are commented are defined in their special files.
21
21
  #
22
22
  Phony.define do
23
-
23
+
24
24
  # Reserved.
25
25
  #
26
26
  country '0', fixed(1) >> split(10) # Reserved.
@@ -854,12 +854,6 @@ Phony.define do
854
854
  country '853', todo # Macao, China
855
855
  country '854', todo # Spare code
856
856
 
857
- # Cambodia (Kingdom of)
858
- # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
859
- country '855',
860
- match(/^(1\d{1})/) >> split(3, 3) |
861
- fixed(2) >> matched_split(/^\d{6}$/ => [3,3], /^\d{7}$/ => [3,4])
862
-
863
857
  # Lao People's Democratic Republic http://www.wtng.info/wtng-856-la.html, https://www.numberingplans.com
864
858
  country '856',
865
859
  one_of('30') >> split(3,4) | # geographic
@@ -0,0 +1,86 @@
1
+ # Cambodia (Kingdom of)
2
+ # http://en.wikipedia.org/wiki/Telecommunications_in_Cambodia#Mobile_networks
3
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
4
+ # http://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000230001MSWE.doc
5
+
6
+ ndcs = [
7
+ '23', # Phnom Penh
8
+ '24', # Kandal
9
+ '25', # Kampong Speu
10
+ '26', # Kampong Chhnang
11
+ '32', # Takeo
12
+ '33', # Kampot
13
+ '34', # Sihanoukville
14
+ '35', # Koh Kong
15
+ '36', # Kep
16
+ '42', # Kampong Cham
17
+ '43', # Prey Veng
18
+ '44', # Svay Rieng
19
+ '52', # Pursat
20
+ '53', # Battambang
21
+ '54', # Banteay Meanchey
22
+ '55', # Pailin
23
+ '62', # Kampong Thom
24
+ '63', # Siem Reap
25
+ '64', # Preah Vihear
26
+ '65', # Oddar Meanchey
27
+ '72', # Kratie
28
+ '73', # Mondulkiri
29
+ '74', # Stung Treng
30
+ '75', # Ratanakiri
31
+ ]
32
+
33
+ six_digit_mobile_prefixes = [
34
+ '60', # Beeline
35
+ '66', # Beeline
36
+ '67', # Beeline
37
+ '68', # Beeline
38
+ '90', # Beeline
39
+ '11', # Mobitel
40
+ '17', # Mobitel
41
+ '61', # Mobitel
42
+ '77', # Mobitel
43
+ '78', # Mobitel
44
+ '85', # Mobitel
45
+ '89', # Mobitel
46
+ '92', # Mobitel
47
+ '95', # Mobitel
48
+ '99', # Mobitel
49
+ '18', # Excell
50
+ '13', # qb
51
+ '80', # qb
52
+ '83', # qb
53
+ '84', # qb
54
+ '10', # Smart
55
+ '15', # Smart
56
+ '16', # Smart
57
+ '69', # Smart
58
+ '70', # Smart
59
+ '81', # Smart
60
+ '86', # Smart
61
+ '87', # Smart
62
+ '93', # Smart
63
+ '98', # Smart
64
+ ]
65
+
66
+ seven_digit_mobile_prefixes = [
67
+ '31', # Beeline
68
+ '38', # CooTel
69
+ '76', # Mobitel
70
+ '88', # Metfone
71
+ '96', # Smart
72
+ '97', # Metfone
73
+ ]
74
+
75
+ six_or_seven_digit_mobile_prefixes = [
76
+ '12' # Mobitel
77
+ ]
78
+
79
+ Phony.define do
80
+ country '855', one_of(six_digit_mobile_prefixes) >> matched_split(/^[1-9]/ => [3, 3]) |
81
+ one_of(seven_digit_mobile_prefixes) >> matched_split(/^[2-9]/ => [3, 4]) |
82
+ one_of(six_or_seven_digit_mobile_prefixes) >> matched_split(
83
+ /^[2-9]\d{5}$/ => [3, 3], /^[1-9]\d{6}$/ => [3, 4]
84
+ ) |
85
+ one_of(ndcs) >> matched_split(/^[2-9]\d{5}$/ => [3, 3], /^[2-9]\d{6}$/ => [3, 4])
86
+ end
@@ -4,93 +4,95 @@
4
4
  #
5
5
 
6
6
  ndcs_2digit = [
7
- '02', # Milan
8
- '06', # Rome (including State of Vatican City) and Aprilia
7
+ '02', # Milan
8
+ '06', # Rome (including State of Vatican City) and Aprilia
9
9
  ]
10
10
 
11
- ndcs = [
12
- '010', # Genoa
13
- '011', # Turin
14
- '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
15
- '0125', # Ivrea
16
- '0131', # Alessandria
17
- '0141', # Asti
18
- '015', # Biella
19
- '0161', # Vercelli
20
- '0165', # Aosta, Courmayeur
21
- '0166', # Cervinia
22
- '0171', # Cuneo
23
- '0185', # Tigullio
24
- '0187', # La Spezia and Cinque Terre
25
- '019', # Savona
26
- '030', # Brescia
27
- '031', # Como
28
- '0321', # Novara
29
- '0331', # Varese
30
- '0341', # Lecco
31
- '0342', # Sondrio
32
- '035', # Bergamo
33
- '0369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
34
- '0376', # Mantua
35
- '0382', # Pavia
36
- '039', # Monza
37
- '040', # Trieste
38
- '041', # Venice
39
- '0425', # Rovigo
40
- '0432', # Udine
41
- '0444', # Vicenza
42
- '045', # Verona
43
- '0461', # Trento
44
- '0471', # Bolzano
45
- '0481', # Gorizia
46
- '049', # Padua
47
- '050', # Pisa
48
- '051', # Bologna
49
- '0521', # Parma
50
- '0522', # Reggio nell'Emilia
51
- '0523', # Piacenza
52
- '0532', # Ferrara
53
- '0536', # Sassuolo
54
- '0541', # Rimini
55
- '0549', # San Marino (Most Serene Republic of San Marino)
56
- '055', # Florence
57
- '0573', # Pistoia
58
- '0577', # Siena
59
- '0586', # Livorno
60
- '059', # Modena
61
- '070', # Cagliari
62
- '071', # Ancona
63
- '075', # Perugia
64
- '0769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
65
- '0771', # Fondi
66
- '0773', # Latina
67
- '0775', # Frosinone
68
- '0789', # Olbia and Costa Smeralda
69
- '079', # Sassari
70
- '080', # Bari
71
- '081', # Naples
72
- '0823', # Caserta
73
- '0824', # Benevento
74
- '0825', # Avellino
75
- '085', # Pescara
76
- '0865', # Isernia
77
- '0871', # Chieti
78
- '0872', # Lanciano
79
- '0873', # Vasto
80
- '0874', # Campobasso
81
- '0875', # Termoli
82
- '0881', # Foggia
83
- '089', # Salerno
84
- '090', # Messina
85
- '091', # Palermo
86
- '092', # Agrigento
87
- '095', # Catania
88
- '0961', # Catanzaro
89
- '0965', # Reggio di Calabria
90
- '0971', # Potenza
91
- '099', # Taranto
92
- ]
11
+ ndcs_3digit = [
12
+ '010', # Genoa
13
+ '011', # Turin
14
+ '015', # Biella
15
+ '019', # Savona
16
+ '030', # Brescia
17
+ '031', # Como
18
+ '035', # Bergamo
19
+ '039', # Monza
20
+ '040', # Trieste
21
+ '041', # Venice
22
+ '045', # Verona
23
+ '049', # Padua
24
+ '050', # Pisa
25
+ '051', # Bologna
26
+ '055', # Florence
27
+ '059', # Modena
28
+ '070', # Cagliari
29
+ '071', # Ancona
30
+ '075', # Perugia
31
+ '079', # Sassari
32
+ '080', # Bari
33
+ '081', # Naples
34
+ '085', # Pescara
35
+ '089', # Salerno
36
+ '090', # Messina
37
+ '091', # Palermo
38
+ '092', # Agrigento
39
+ '095', # Catania
40
+ '099', # Taranto
41
+ ]
93
42
 
43
+ ndcs_4digit = [
44
+ '0122', # Sestrieres, Bardonecchia and other Susa Valley mountain resorts
45
+ '0125', # Ivrea
46
+ '0131', # Alessandria
47
+ '0141', # Asti
48
+ '0161', # Vercelli
49
+ '0165', # Aosta, Courmayeur
50
+ '0166', # Cervinia
51
+ '0171', # Cuneo
52
+ '0185', # Tigullio
53
+ '0187', # La Spezia and Cinque Terre
54
+ '0321', # Novara
55
+ '0331', # Varese
56
+ '0341', # Lecco
57
+ '0342', # Sondrio
58
+ '0369', # Mediaset Cologno Monzese and Segrate TV studios, geographical rate (used for polls, television programs, etc.)
59
+ '0376', # Mantua
60
+ '0382', # Pavia
61
+ '0425', # Rovigo
62
+ '0432', # Udine
63
+ '0444', # Vicenza
64
+ '0461', # Trento
65
+ '0471', # Bolzano
66
+ '0481', # Gorizia
67
+ '0521', # Parma
68
+ '0522', # Reggio nell'Emilia
69
+ '0523', # Piacenza
70
+ '0532', # Ferrara
71
+ '0536', # Sassuolo
72
+ '0541', # Rimini
73
+ '0549', # San Marino (Most Serene Republic of San Marino)
74
+ '0573', # Pistoia
75
+ '0577', # Siena
76
+ '0586', # Livorno
77
+ '0769', # RAI Saxa Rubra Studios, geographical rate (used for polls, television programs, etc.)
78
+ '0771', # Fondi
79
+ '0773', # Latina
80
+ '0775', # Frosinone
81
+ '0789', # Olbia and Costa Smeralda
82
+ '0823', # Caserta
83
+ '0824', # Benevento
84
+ '0825', # Avellino
85
+ '0865', # Isernia
86
+ '0871', # Chieti
87
+ '0872', # Lanciano
88
+ '0873', # Vasto
89
+ '0874', # Campobasso
90
+ '0875', # Termoli
91
+ '0881', # Foggia
92
+ '0961', # Catanzaro
93
+ '0965', # Reggio di Calabria
94
+ '0971', # Potenza
95
+ ]
94
96
 
95
97
  mobile = [
96
98
  '310',
@@ -153,8 +155,9 @@ service = [ # Not exhaustive.
153
155
 
154
156
  Phony.define do
155
157
  country '39', trunk('0', :normalize => false) |
156
- one_of(*service) >> split(3,3) |
157
- one_of(*mobile) >> split(3,4) |
158
- one_of(*ndcs_2digit) >> split(4,4) |
159
- one_of(*ndcs, :max_length => 3) >> split(3,4)
158
+ one_of(*service) >> split(3,3) |
159
+ one_of(*mobile) >> split(3,4) |
160
+ one_of(*ndcs_2digit) >> split(4,4) |
161
+ one_of(*ndcs_3digit) >> split(3,4) |
162
+ one_of(*ndcs_4digit) >> split(3,3)
160
163
  end
@@ -45,13 +45,28 @@ module Phony
45
45
  end
46
46
  end
47
47
 
48
- def countrify! number
49
- # The sensible default is to add the country code
50
- # if it does not already start with it.
51
- #
52
- # Note: This won't be correct in some cases, but it is the best we can do.
48
+ # TODO This is now in country_codes and country.
49
+ #
50
+ @@basic_cleaning_pattern = /\D/
51
+ def clean number
52
+ clean! number && number.dup
53
+ end
54
+ def clean! number
55
+ # Remove non-digit chars.
53
56
  #
54
- number.sub! /\b#{@cc}?/, @cc
57
+ number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
58
+ end
59
+
60
+ # Adds the country code to the front
61
+ # if it does not already start with it.
62
+ #
63
+ # Note: This won't be correct in some cases, but it is the best we can do.
64
+ #
65
+ def countrify number
66
+ countrify! number || number
67
+ end
68
+ def countrify! number
69
+ number.sub! /\A(?!#{@cc})?/, @cc
55
70
  end
56
71
 
57
72
  # Removes 0s from partially normalized numbers
@@ -63,11 +78,15 @@ module Phony
63
78
  # In some cases it doesn't, like Italy.
64
79
  #
65
80
  def normalize national_number
66
- @codes.each do |code|
67
- normalized = code.normalize national_number
68
- return normalized if normalized && !normalized.empty?
81
+ clean! national_number
82
+ normalized = @codes.reduce(national_number) do |number, code|
83
+ result = code.normalize number
84
+ break result if result
85
+ number
69
86
  end
70
- return nil
87
+ return unless normalized
88
+ countrify! normalized
89
+ normalized
71
90
  end
72
91
 
73
92
  # Tests for plausibility of this national number.
@@ -14,8 +14,7 @@ module Phony
14
14
  @international_relative_format = '00%s%s%s'
15
15
  @national_format = '%s%s'
16
16
 
17
- @normalize_format = '%s%s'
18
- @default_space = ' '
17
+ @default_space = ' '
19
18
  end
20
19
 
21
20
  def self.instance
@@ -27,6 +26,18 @@ module Phony
27
26
  def [] cc
28
27
  countries[cc.size][cc]
29
28
  end
29
+
30
+ # TODO This is now in country_codes and country.
31
+ #
32
+ @@basic_cleaning_pattern = /\A00?|\(0\)|\D/
33
+ def clean number
34
+ clean! number && number.dup
35
+ end
36
+ def clean! number
37
+ # Remove non-digit chars.
38
+ #
39
+ number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
40
+ end
30
41
 
31
42
  # 00 for the standard international call prefix.
32
43
  # http://en.wikipedia.org/wiki/List_of_international_call_prefixes
@@ -39,28 +50,15 @@ module Phony
39
50
  # * (0) anywhere.
40
51
  # * Non-digits.
41
52
  #
42
- @@basic_cleaning_pattern = /^00?|\(0\)|\D/
43
- def clean number
44
- clean! number && number.dup
45
- end
46
- def clean! number
47
- # Remove non-digit chars.
48
- #
49
- number.gsub!(@@basic_cleaning_pattern, EMPTY_STRING) || number
50
- end
51
53
  def normalize number, options = {}
52
- clean! number
53
- countrify! number, options
54
- country, cc, rest = split_cc number
55
- @normalize_format % [cc, country.normalize(rest)]
56
- end
57
-
58
- #
59
- #
60
- def countrify! number, options = {}
61
- if cc = options[:cc]
62
- self[cc].countrify! number
54
+ country = if cc = options[:cc]
55
+ self[cc]
56
+ else
57
+ clean! number
58
+ country, cc, number = split_cc number
59
+ country
63
60
  end
61
+ country.normalize number
64
62
  end
65
63
 
66
64
  # Splits this number into cc, ndc and locally split number parts.
@@ -27,7 +27,7 @@ module Phony
27
27
  # Note: Some cases, like Italy, don't remove the relative zero.
28
28
  #
29
29
  def normalize national_number
30
- national_number.gsub(/\A0+/, EMPTY_STRING)
30
+ national_number.gsub /\A0+/, EMPTY_STRING
31
31
  end
32
32
 
33
33
  end
@@ -22,9 +22,7 @@ module Phony
22
22
  national_number.gsub! @trunk_code_replacement, EMPTY_STRING if @split
23
23
  return [@code, national_number]
24
24
  end
25
-
26
- # Never normalizes.
27
- #
25
+
28
26
  def normalize national_number
29
27
  return national_number unless @normalize
30
28
  national_number.gsub @trunk_code_replacement, EMPTY_STRING
@@ -154,6 +154,7 @@ describe 'plausibility' do
154
154
  Phony.plausible?('+39 06 1234 4567').should be_true
155
155
  Phony.plausible?('+39 335 123 4567').should be_true
156
156
  Phony.plausible?('+39 335 123').should be_false
157
+ Phony.plausible?('+39 0471 123 456').should be_true
157
158
  end
158
159
  it 'is correct for German numbers' do
159
160
  Phony.plausible?('+49 209 169 - 0').should be_true # Gelsenkirchen
@@ -164,20 +165,20 @@ describe 'plausibility' do
164
165
  Phony.plausible?('+49 171 123 45678').should be_false
165
166
  Phony.plausible?('+49 177 123 1234').should be_true
166
167
  Phony.plausible?('+49 176 123 12345').should be_true
167
- # Phony.plausible?('+49 991 1234').should be_true # stricter 3 digit ndc rules
168
+ Phony.plausible?('+49 991 1234').should be_true # stricter 3 digit ndc rules
168
169
  Phony.plausible?('+49 2041 123').should be_true # Grandfathered numbers.
169
170
  Phony.plausible?('+49 2041 1234567').should be_true
170
- # Phony.plausible?('+49 2041 12345689').should be_false # Could be a call-through number
171
+ Phony.plausible?('+49 2041 12345689').should be_false # Could be a call-through number
171
172
  Phony.plausible?('+49 31234 123456').should be_true
172
- # Phony.plausible?('+49 31234 1234567').should be_false # Could be a call-through number
173
+ Phony.plausible?('+49 31234 1234567').should be_false # Could be a call-through number
173
174
  end
174
175
 
175
- it 'is correct for Isralian numbers' do
176
+ it 'is correct for Israelian numbers' do
176
177
  Phony.plausible?('+972 2 123 1234').should be_true
177
178
  Phony.plausible?('+972 59 123 1234').should be_true
178
179
  end
179
180
  it "is correct for US numbers" do
180
- # Sorry, still need E164 conform numbers.
181
+ # Still need E164 conform numbers.
181
182
  #
182
183
  Phony.plausible?('4346667777', cc: '1').should be_false
183
184
 
@@ -327,18 +328,53 @@ describe 'plausibility' do
327
328
  it_is_correct_for 'Burundi', :samples => '+257 1234 5678'
328
329
 
329
330
  it 'is correct for Cambodia' do
330
- # 7 digit identifiers
331
- Phony.plausible?("+855965787807").should be_true # Smart
332
- Phony.plausible?("+855312067777").should be_true # Beeline
333
- Phony.plausible?("+855383001801").should be_true # CooTel
334
- Phony.plausible?("+855973001801").should be_true # Metfone
335
- Phony.plausible?("+855883001801").should be_true # Metfone
336
- Phony.plausible?("+85510234567").should be_true # Smart
337
- Phony.plausible?("+85511234564").should be_true # Mobitel (former Mfone)
338
- Phony.plausible?("+855 12 236 142").should be_true # Mobitel
339
- Phony.plausible?("+855 234 601 183").should be_true # Long fixed line (Phnom Penh)
340
- Phony.plausible?("855 33 123 456").should be_true # Regular fixed line (Kampot)
341
- Phony.plausible?("+855102345678").should be_false # Too many digits for a 01 prefix
331
+ # http://en.wikipedia.org/wiki/Telecommunications_in_Cambodia#Mobile_networks
332
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
333
+ # http://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000230001MSWE.doc
334
+
335
+ Phony.plausible?("+855312345678").should be_true # Beeline (7 digit id)
336
+ Phony.plausible?("+85531234567").should be_false # Beeline (too short)
337
+ Phony.plausible?("+85560234567").should be_true # Beeline (6 digit id)
338
+ Phony.plausible?("+855602345678").should be_false # Beeline (too long)
339
+
340
+ Phony.plausible?("+855762345678").should be_true # Mobitel (7 digit id)
341
+ Phony.plausible?("+85576234567").should be_false # Mobitel (too short)
342
+ Phony.plausible?("+85517234567").should be_true # Mobitel (6 digit id)
343
+ Phony.plausible?("+855172345678").should be_false # Mobitel (too long)
344
+ Phony.plausible?("+85512234567").should be_true # Mobitel (6 digit id)
345
+ Phony.plausible?("+855121345678").should be_true # Mobitel (7 digit id)
346
+ Phony.plausible?("+85512123456").should be_false # Mobitel (6 digit invalid)
347
+
348
+ Phony.plausible?("+855383001801").should be_true # CooTel (7 digit id)
349
+ Phony.plausible?("+85538300180").should be_false # CooTel (too short)
350
+
351
+ Phony.plausible?("+85518234567").should be_true # Excell (6 digit id)
352
+ Phony.plausible?("+855182345678").should be_false # Excell (too long)
353
+
354
+ Phony.plausible?("+855882345678").should be_true # Metfone (7 digit id)
355
+ Phony.plausible?("+85588234567").should be_false # Metfone (too short)
356
+ Phony.plausible?("+855972345678").should be_true # Metfone (7 digit id)
357
+ Phony.plausible?("+85597234567").should be_false # Metfone (too short)
358
+
359
+ Phony.plausible?("+85513234567").should be_true # qb (6 digit id)
360
+ Phony.plausible?("+855132345678").should be_false # qb (too long)
361
+
362
+ Phony.plausible?("+855962345678").should be_true # Smart (7 digit id)
363
+ Phony.plausible?("+85596234567").should be_false # Smart (too short)
364
+ Phony.plausible?("+85510234567").should be_true # Smart (6 digit id)
365
+ Phony.plausible?("+855102345678").should be_false # Smart (too long)
366
+
367
+ # AXXXXX (A must be between 1 and 9)
368
+ Phony.plausible?("+85512023456").should be_false # invalid numbering plan
369
+ Phony.plausible?("+855380234567").should be_false # invalid numbering plan
370
+ Phony.plausible?("+85592123456").should be_true # valid for 6 digit id
371
+
372
+ Phony.plausible?("+85514234567").should be_false # invalid mobile operator
373
+ Phony.plausible?("+85527234567").should be_false # invalid ndc
374
+
375
+ Phony.plausible?("+85523471234").should be_true # Fixed line (NDC + '47' + 4 digit id)
376
+ Phony.plausible?("+855234712345").should be_true # Fixed line (NDC + '47' + 5 digit id)
377
+ Phony.plausible?("+85523123456").should be_false # Fixed line (NDC + invalid A)
342
378
  end
343
379
 
344
380
  it_is_correct_for 'Cameroon', :samples => '+237 7372 8186'
@@ -123,7 +123,7 @@ describe 'country descriptions' do
123
123
  it_splits '85512236142', ["855", "12", "236", "142"] # mobile (Mobitel)
124
124
  it_splits '855977100872', ["855", "97", "710", "0872"] # mobile (Metfone)
125
125
  it_splits '855234601183', ["855", "23", "460", "1183"] # Long fixed line (Phnom Penh)
126
- it_splits '85533123456', ["855", "33", "123", "456"] # Regular fixed line (Kampot)
126
+ it_splits '85533234567', ["855", "33", "234", "567"] # Regular fixed line (Kampot)
127
127
  end
128
128
  describe 'Chile' do
129
129
  it_splits '5621234567', ['56', '2', '1234567'] # Santiago
@@ -334,6 +334,7 @@ describe 'country descriptions' do
334
334
  it_splits '390141595661', ['39', '0141', '595', '661'] # Asti
335
335
  it_splits '3903123391', ['39', '031', '233', '91'] # Como
336
336
  it_splits '390909709511', ['39', '090', '970', '9511'] # Barcellona
337
+ it_splits '390471811353', ['39', '0471', '811', '353'] # Bolzano
337
338
  end
338
339
  describe 'Japan' do
339
340
  it_splits '81312345678', %w(81 3 1234 5678)
@@ -24,6 +24,7 @@ describe Phony::Country do
24
24
  national_code = Phony::NationalCode.new national_splitter, local_splitter
25
25
 
26
26
  @switzerland = Phony::Country.new national_code
27
+ @switzerland.with '41' # TODO Remove this kludge.
27
28
  end
28
29
 
29
30
  describe "split" do
@@ -33,7 +34,7 @@ describe Phony::Country do
33
34
  end
34
35
  describe 'normalize' do
35
36
  it "should handle ZH" do
36
- @switzerland.normalize('0443643532').should == '443643532'
37
+ @switzerland.normalize('0443643532').should == '41443643532'
37
38
  end
38
39
  end
39
40
  end
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.0.2
4
+ version: 2.1.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: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2014-01-06 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
@@ -19,10 +19,14 @@ extensions: []
19
19
  extra_rdoc_files:
20
20
  - README.textile
21
21
  files:
22
+ - README.textile
23
+ - lib/phony.rb
24
+ - lib/phony/countries.rb
22
25
  - lib/phony/countries/austria.rb
23
26
  - lib/phony/countries/bangladesh.rb
24
27
  - lib/phony/countries/belarus.rb
25
28
  - lib/phony/countries/brazil.rb
29
+ - lib/phony/countries/cambodia.rb
26
30
  - lib/phony/countries/china.rb
27
31
  - lib/phony/countries/georgia.rb
28
32
  - lib/phony/countries/germany.rb
@@ -54,7 +58,6 @@ files:
54
58
  - lib/phony/countries/united_kingdom.rb
55
59
  - lib/phony/countries/uruguay.rb
56
60
  - lib/phony/countries/zimbabwe.rb
57
- - lib/phony/countries.rb
58
61
  - lib/phony/country.rb
59
62
  - lib/phony/country_codes.rb
60
63
  - lib/phony/dsl.rb
@@ -69,8 +72,6 @@ files:
69
72
  - lib/phony/national_splitters/variable.rb
70
73
  - lib/phony/trunk_code.rb
71
74
  - lib/phony/vanity.rb
72
- - lib/phony.rb
73
- - README.textile
74
75
  - spec/functional/normalize_spec.rb
75
76
  - spec/functional/plausibility_spec.rb
76
77
  - spec/lib/phony/countries_spec.rb
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  version: '0'
107
108
  requirements: []
108
109
  rubyforge_project:
109
- rubygems_version: 2.0.3
110
+ rubygems_version: 2.2.0
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Fast international phone number (E164 standard) normalizing, splitting and