phonie 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -100,6 +100,8 @@ Currently tested on:
100
100
  [BY] Belarus
101
101
  [BZ] Belize
102
102
  [CA] Canada
103
+ [CH] Switzerland
104
+ [CN] China
103
105
  [CR] Costa Rica
104
106
  [CY] Cyprus
105
107
  [CZ] Czech Republic
@@ -1,12 +1,12 @@
1
1
  module Phonie
2
- class Country < Struct.new(:name, :country_code, :char_2_code, :iso_3166_code, :area_code, :local_number_format, :mobile_format, :full_number_length, :number_format)
2
+ class Country < Struct.new(:name, :country_code, :char_2_code, :iso_3166_code, :area_code, :local_number_format, :mobile_format, :full_number_length, :number_format, :national_dialing_prefix)
3
3
  def self.load
4
4
  data_file = File.join(File.dirname(__FILE__), 'data', 'phone_countries.yml')
5
5
 
6
6
  all = []
7
7
  YAML.load(File.read(data_file)).each do |c|
8
8
  next unless c[:area_code] && c[:local_number_format]
9
- all << Country.new(c[:name], c[:country_code], c[:char_2_code], c[:iso_3166_code], c[:area_code], c[:local_number_format], c[:mobile_format], c[:full_number_length], c[:number_format])
9
+ all << Country.new(c[:name], c[:country_code], c[:char_2_code], c[:iso_3166_code], c[:area_code], c[:local_number_format], c[:mobile_format], c[:full_number_length], c[:number_format], c[:national_dialing_prefix])
10
10
  end
11
11
  all
12
12
  end
@@ -77,6 +77,15 @@ module Phonie
77
77
  end
78
78
  end
79
79
 
80
+ def national_dialing_prefix
81
+ prefix = super
82
+ if prefix == "None"
83
+ nil
84
+ else
85
+ prefix
86
+ end
87
+ end
88
+
80
89
  private
81
90
 
82
91
  def number_format_regex
@@ -282,6 +282,10 @@
282
282
  :iso_3166_code: CN
283
283
  :name: China
284
284
  :international_dialing_prefix: '00'
285
+ :area_code: 1[3458]|2[0-9]|[3456789][0-9][0-9]
286
+ :local_number_format: \d{4,10}
287
+ :mobile_format: 1[3458]\d{9}
288
+ :number_format: \d{8,12}
285
289
  -
286
290
  :country_code: '960'
287
291
  :national_dialing_prefix: None
@@ -1202,6 +1206,10 @@
1202
1206
  :iso_3166_code: CH
1203
1207
  :name: Switzerland
1204
1208
  :international_dialing_prefix: '00'
1209
+ :area_code: 21|22|24|26|27|31|32|33|34|41|43|44|51|52|55|56|58|61|62|71|74|76|77|78|79|81|91
1210
+ :mobile_format: (74|76|77|78|79)\d{7}
1211
+ :local_number_format: \d{7}
1212
+ :number_format: \d{9}
1205
1213
  -
1206
1214
  :country_code: '974'
1207
1215
  :national_dialing_prefix: None
@@ -1,3 +1,3 @@
1
1
  module Phonie
2
- VERSION = '2.0.2'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ ## Switzerland
4
+ class CHTest < Phonie::TestCase
5
+
6
+ def test_local
7
+ parse_test('+41213459020', '41', '21', '3459020', 'Switzerland', false)
8
+ end
9
+
10
+ def test_mobile
11
+ parse_test('+41743459020', '41', '74', '3459020', 'Switzerland', true)
12
+ end
13
+ end
14
+
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ ## China
4
+ class CNTest < Phonie::TestCase
5
+ def test_local
6
+ parse_test('+863721234567', '86', '372', '1234567', 'China', false)
7
+ end
8
+
9
+ def test_mobile
10
+ parse_test('8613123456789', '86', '13', '123456789', 'China', true)
11
+ end
12
+ end
@@ -24,4 +24,11 @@ class CountryTest < Phonie::TestCase
24
24
  assert_equal "Norway", countries.first.name
25
25
  end
26
26
 
27
+ def test_national_dialing_prefix
28
+ tonga = Phonie::Country.find_by_country_code('TO')
29
+ assert_nil tonga.national_dialing_prefix
30
+
31
+ us_and_a = Phonie::Country.find_by_country_code('US')
32
+ assert_equal '1', us_and_a.national_dialing_prefix
33
+ end
27
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phonie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-06-29 00:00:00.000000000 Z
16
+ date: 2013-07-23 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activemodel
@@ -109,7 +109,9 @@ files:
109
109
  - test/countries/by_test.rb
110
110
  - test/countries/bz_test.rb
111
111
  - test/countries/ca_test.rb
112
+ - test/countries/ch_test.rb
112
113
  - test/countries/cl_test.rb
114
+ - test/countries/cn_test.rb
113
115
  - test/countries/cr_test.rb
114
116
  - test/countries/cy_test.rb
115
117
  - test/countries/cz_test.rb
@@ -188,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
190
  version: '0'
189
191
  segments:
190
192
  - 0
191
- hash: -4097196119145454561
193
+ hash: -2285805841961836759
192
194
  required_rubygems_version: !ruby/object:Gem::Requirement
193
195
  none: false
194
196
  requirements:
@@ -197,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
199
  version: '0'
198
200
  segments:
199
201
  - 0
200
- hash: -4097196119145454561
202
+ hash: -2285805841961836759
201
203
  requirements: []
202
204
  rubyforge_project:
203
205
  rubygems_version: 1.8.23
@@ -224,7 +226,9 @@ test_files:
224
226
  - test/countries/by_test.rb
225
227
  - test/countries/bz_test.rb
226
228
  - test/countries/ca_test.rb
229
+ - test/countries/ch_test.rb
227
230
  - test/countries/cl_test.rb
231
+ - test/countries/cn_test.rb
228
232
  - test/countries/cr_test.rb
229
233
  - test/countries/cy_test.rb
230
234
  - test/countries/cz_test.rb