Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

! split unrecognized irish NDCs more intelligently

  • Loading branch information...
commit 1b370929a87db52549445bcf76560f6659df55ae 1 parent 4159ad9
@floere authored
View
2  lib/phony/countries/ireland.rb
@@ -71,6 +71,6 @@
one_of(ndcs_with_6_subscriber_digits) >> split(6) |
one_of(freefone) >> split(6) |
match(/^(8\d).+$/) >> split(3,4) | # mobile
- none >> split(0)
+ fixed(3) >> split(6)
end
View
4 lib/phony/country_codes.rb
@@ -73,7 +73,9 @@ def format_cc_ndc format, space, cc, zero, ndc
@international_relative_format % [cc, space, ndc] :
@international_relative_format % [cc, nil, nil]
when :national
- (ndc.empty? ? EMPTY_STRING : @national_format) % [zero, ndc]
+ ndc && !ndc.empty? ?
+ @national_format % [zero, ndc] :
+ @national_format % [zero, nil]
when :local
EMPTY_STRING
end
View
1  lib/phony/validators.rb
@@ -49,6 +49,7 @@ def plausible? number, hints = {}
# Element based checking.
#
return false unless ndc
+ return false if ndc.empty?
# CC.
#
View
2  spec/lib/phony/countries_spec.rb
@@ -121,7 +121,7 @@
Phony.split('353801234567').should == ['353', '80', '123', '4567'] # Mobile
Phony.split('353761234567').should == ['353', '76', '123', '4567'] # VoIP
Phony.split('353800123456').should == ['353', '800', '123456'] # Freefone
- Phony.split('353000123456').should == ['353', nil, '000123456'] # No NDC/local split for unrecognized
+ Phony.split('353000123456').should == ['353', '000', '123456'] # Default fixed 3 split for unrecognized
end
it 'handles italian numbers' do
Phony.split('3934869528').should == ['39', '3486', '952', '8'] # Mobile
View
8 spec/lib/phony/country_codes_spec.rb
@@ -62,6 +62,14 @@
it 'formats correctly' do
@countries.formatted('41443643532', :format => :national, :spaces => :-).should == '044-364-35-32'
end
+ context 'specific' do
+ it 'formats ireland correctly' do
+ @countries.formatted("3533451234", :format => :national).should == '0345 1234'
+ end
+ it 'formats ireland correctly' do
+ @countries.formatted("353411231234", :format => :national).should == '041 123 1234'
+ end
+ end
context 'default' do
it "should format swiss numbers" do
@countries.formatted('41443643532').should == '+41 44 364 35 32'
Please sign in to comment.
Something went wrong with that request. Please try again.