Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow unsupported countries to use a more conservative default.

  • Loading branch information...
commit 3851473b761e17555911e9a4e47ca22872735304 1 parent e62aa92
@mrchucho mrchucho authored
View
3  lib/phony.rb
@@ -8,6 +8,7 @@
require File.expand_path '../phony/national_splitters/variable', __FILE__
require File.expand_path '../phony/national_splitters/regex', __FILE__
require File.expand_path '../phony/national_splitters/none', __FILE__
+require File.expand_path '../phony/national_splitters/default', __FILE__
require File.expand_path '../phony/national_code', __FILE__
require File.expand_path '../phony/country', __FILE__
require File.expand_path '../phony/country_codes', __FILE__
@@ -96,4 +97,4 @@ def vanity_to_number vanity_number
end
-end
+end
View
4 lib/phony/countries.rb
@@ -461,7 +461,7 @@
country '878', fixed(2) >> split(3,2,2) # Universal Personal Telecommunication Service (UPT)
country '879', fixed(2) >> split(3,2,2) # Reserved for national non-commercial purposes
- country '880', fixed(2) >> split(3,2,2) # Bangladesh (People's Republic of)
+ country '880', default # Bangladesh (People's Republic of)
country '881', fixed(2) >> split(3,2,2) # International Mobile, shared code
country '882', fixed(2) >> split(3,2,2) # International Networks, shared code
country '883', fixed(2) >> split(3,2,2) # -
@@ -515,4 +515,4 @@
country '997', fixed(2) >> split(3,2,2) # Spare code
country '998', fixed(2) >> split(3,2,2) # Uzbekistan (Republic of)
country '999', fixed(2) >> split(3,2,2) # Reserved for possible future use within the Telecommunications for Disaster Relief (TDR) concept
-end
+end
View
12 lib/phony/country_codes.rb
@@ -43,7 +43,15 @@ def formatted number, options = {}
# Formats country code and national destination code.
#
def format_cc_ndc_local format, space, cc, ndc, *parts
- "#{format_cc_ndc(format, space, cc, ndc)}#{format_local(space, parts)}"
+ cc_ndc = format_cc_ndc(format, space, cc, ndc)
+ local = \
+ if parts.empty?
+ cc_ndc = cc_ndc.slice(0...cc_ndc.size-1)
+ EMPTY_STRING
+ else
+ format_local(space, parts) unless parts.empty?
+ end
+ "#{cc_ndc}#{local}"
end
def format_cc_ndc format, space, cc, ndc
case format
@@ -119,4 +127,4 @@ def add country_code, country
end
-end
+end
View
5 lib/phony/dsl.rb
@@ -73,6 +73,9 @@ def one_of *ndcs
def match regex, options = {}
NationalSplitters::Regex.instance_for regex, options[:on_fail_take]
end
+ def default
+ NationalSplitters::Default.instance_for
+ end
# Local splitters.
#
@@ -88,4 +91,4 @@ def matched_split options = {}
end
-end
+end
View
17 lib/phony/national_splitters/default.rb
@@ -0,0 +1,17 @@
+module Phony
+
+ module NationalSplitters
+
+ class Default < DSL
+
+ def self.instance_for
+ new
+ end
+
+ def split number
+ number
+ end
+
+ end
+ end
+end
View
13 spec/lib/phony_spec.rb
@@ -127,6 +127,17 @@
Phony.format('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'
end
end
+ describe '"unsupported" countries' do
+ it 'should format as a single block' do
+ Phony.format('88032155605220').should == '+880 32155605220'
+ end
+ it 'should format as a single block, regardless of format' do
+ Phony.format('8801819372205', :format => :international).should == '+880 1819372205'
+ end
+ it 'should format as a single block, respecting custom spaces' do
+ Phony.format('8801819372205', :spaces => :-).should == '+880-1819372205'
+ end
+ end
end
describe "national" do
it "should format swiss numbers" do
@@ -238,4 +249,4 @@
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.