Permalink
Browse files

+ hungarian numbers, swiss specs

  • Loading branch information...
1 parent 9b37d4c commit 7a40c1c037d5147e8b335fbedb10dc4e405cd0e8 @floere committed Nov 19, 2010
View
1 lib/phony.rb
@@ -22,6 +22,7 @@
require File.expand_path '../phony/countries/all_other', __FILE__
require File.expand_path '../phony/countries/austria', __FILE__
require File.expand_path '../phony/countries/germany', __FILE__
+require File.expand_path '../phony/countries/hungary', __FILE__
require File.expand_path '../phony/countries/italy', __FILE__
require File.expand_path '../phony/country_codes', __FILE__
View
12 lib/phony/countries/all_other.rb
@@ -10,6 +10,12 @@ def self.fixed size, options = {}
Phony::Country.fixed options
end
+ # TODO
+ #
+ def self.with_cc cc
+ mapping[cc.size][cc.to_s]
+ end
+
# Defines a mapping of country code to all splitters/formatters.
#
# Note: The above fixed helper is used.
@@ -52,8 +58,10 @@ def self.mapping
# :mobile => %w{6 7}
# }
),
- '34' => fixed(2), # Spain
- '36' => fixed(2), # Hungary
+ '34' => fixed(2, # Spain
+ :local_format => [3, 4]
+ ),
+ '36' => Countries::Hungary,
'39' => Countries::Italy,
'40' => fixed(2), # Romania
View
4 lib/phony/countries/austria.rb
@@ -23,7 +23,7 @@
'517', # -
'662', # Salzburg
'720', #
- '732', # Linz
+ '732' # Linz
],
:mobile => [
'67',
@@ -44,7 +44,7 @@
'666',
'667',
'668',
- '669',
+ '669'
],
:service => [
'710',
View
23 lib/phony/countries/hungary.rb
@@ -0,0 +1,23 @@
+# Hungarian phone numbers.
+#
+# http://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary
+#
+Phony::Countries::Hungary = Phony::Country.configured :local_format => [3, 4], # Also captures 3, 3 on a fallback.
+ :local_special_format => [3, 3],
+ :ndc_fallback_length => 2,
+ :ndc_mapping => {
+ # 1 is Budapest.
+ # All others are captured using
+ # the fallback length 2.
+ #
+ :landline => [
+ '1'
+ ],
+ :mobile => [], # TODO
+ :service => [
+ '104',
+ '105',
+ '107',
+ '112'
+ ]
+ }
View
8 lib/phony/country.rb
@@ -57,9 +57,11 @@ def self.configured options = {}
local_splitter = Phony::LocalSplitter.instance_for options[:local_format] || [3, 2, 2]
national_code = Phony::NationalCode.new national_splitter, local_splitter
- service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => ndc_mapping[:service]
- service_local_splitter = Phony::LocalSplitter.instance_for options[:service_local_format] || [3, 3]
- service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter
+ if ndc_mapping[:service]
+ service_national_splitter = Phony::NationalSplitters::Variable.new nil, :service => ndc_mapping[:service]
+ service_local_splitter = Phony::LocalSplitter.instance_for options[:service_local_format] || [3, 3]
+ service_code = Phony::NationalCode.new service_national_splitter, service_local_splitter
+ end
new national_code, service_code
end
View
2 lib/phony/national_splitters/variable.rb
@@ -52,7 +52,7 @@ def optimize(ndc_ary)
ndcs[ndc.length] << ndc
end
keys = ndcs.keys
- @mapped_ndc_min_length = keys.min
+ @mapped_ndc_min_length = keys.min # || 1
@mapped_ndc_max_length = keys.max
ndcs
end
View
18 spec/lib/phony/countries/hungary_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe Phony::Countries::Hungary do
+
+ before(:each) do
+ @hungary = Phony::Countries::Hungary
+ end
+
+ describe "split" do
+ it "should handle Budapest" do
+ @hungary.split('12345678').should == ['1', '234', '5678']
+ end
+ it "should handle Cologne" do
+ @hungary.split('22123456').should == ['22', '123', '456']
+ end
+ end
+
+end
View
18 spec/lib/phony/countries/switzerland_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe 'Switzerland' do
+
+ before(:each) do
+ @switzerland = Phony::Countries.with_cc '41'
+ end
+
+ describe "split" do
+ it "works" do
+ @switzerland.split('443643532').should == ['44', '364', '35', '32']
+ end
+ it "works" do
+ @switzerland.split('800123456').should == ['800', '123', '456']
+ end
+ end
+
+end
View
6 spec/lib/phony_spec.rb
@@ -14,6 +14,9 @@
it "should handle german numbers" do
Phony.split('4976112345').should == ['49', '761', '123', '45']
end
+ it "should handle hungarian numbers" do
+ Phony.split('3612345678').should == ['36', '1', '234', '5678']
+ end
it "should handle italian numbers opinionatedly" do
Phony.split('3928061371').should == ['39', '2', '806', '1371']
end
@@ -26,8 +29,7 @@
it "should handle new zealand numbers" do
Phony.split('6491234567').should == ['64', '9', '123', '4567']
end
- # TODO
- #
+
it "should handle swiss service numbers" do
Phony.split('41800334455').should == ['41', '800', '334', '455']
end

0 comments on commit 7a40c1c

Please sign in to comment.