Permalink
Browse files

+ norway, + regexp splitter slightly rewritten

  • Loading branch information...
1 parent fc827a4 commit dcba1edf0fc90c699703e8fbdc555310bfa39080 @floere committed Feb 22, 2011
@@ -1,5 +1,11 @@
-area_code = Phony::NationalSplitters::None.instance_for
-national_code = Phony::LocalSplitters::Regex.instance_for [2,2,2,2], /^[489].*$/ => [3,2,3]
-handler = Phony::NationalCode.new area_code, national_code
+# Norway. Complete plan available here:
+# http://www.npt.no/pt_internet/e_164/nummerplaner.html
+#
+# (5-digit special numbers and 01 is missing)
+#
+handler = Phony::NationalCode.new(
+ Phony::NationalSplitters::None.instance_for,
+ Phony::LocalSplitters::Regex.instance_for(/^[1].*$/ => [3], /^[489].*$/ => [3,2,3], :fallback => [2,2,2,2])
+)
Phony::Countries::Norway = Phony::Country.new handler
@@ -18,14 +18,14 @@ class Regex
#
# Note: Not cached.
#
- def self.instance_for fallback, mapping
- new fallback, mapping
+ def self.instance_for mapping
+ new mapping
end
# Initialize with a regex => format mapping.
#
- def initialize fallback, mapping
- @fallback = fallback
+ def initialize mapping
+ @fallback = mapping.delete(:fallback) || [12]
@mapping = mapping
end
@@ -4,15 +4,15 @@
describe 'instance_for' do
it 'does not cache' do
- described_class.instance_for([],{}).should_not equal(described_class.instance_for([],{}))
+ described_class.instance_for({}).should_not equal(described_class.instance_for({}))
end
end
describe 'split' do
before(:each) do
- # Norway.
+ # Norway as example.
#
- @splitter = described_class.instance_for [2,2,2,2], /^[489].*$/ => [3,2,3]
+ @splitter = described_class.instance_for /^[489].*$/ => [3,2,3], :fallback => [2,2,2,2]
end
it 'splits a number correctly' do
@splitter.split('21234567').should == ['21','23','45','67']

0 comments on commit dcba1ed

Please sign in to comment.