Skip to content

Commit

Permalink
Fixes #95.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Hietbrink committed Nov 12, 2015
1 parent afa07ee commit 257cd2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/phony_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def self.normalize_number(number, options = {})
if not (number =~ /\A\+/) # if we don't have a +
if Phony.plausible?("#{_default_country_number}#{number}") || !Phony.plausible?(number) || country_code_from_number(number).nil?
number = "#{_default_country_number}#{number}"
elsif (number =~ /^0[^0]/) && Phony.plausible?("#{_default_country_number}#{number.gsub(/^0/, '')}")
# If the number starts with ONE zero (two might indicate a country code)
# and this is a plausible number for the default_country
# we prefer that one.
number = "#{_default_country_number}#{number.gsub(/^0/, '')}"
end
end
# number = "#{_default_country_number}#{number}" unless Phony.plausible?(number)
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/phony_rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
expect(PhonyRails.normalize_number('2318725305', country_code: 'US')).to eq('+12318725305')
expect(PhonyRails.normalize_number('2318725305', default_country_code: 'US')).to eq('+12318725305')
expect(PhonyRails.normalize_number('+2318725305', default_country_code: 'US')).to eq('+2318725305')
# expect(Phony.plausible?("#{PhonyRails.country_number_for('US')}02318725305")).to be_truthy
expect(PhonyRails.normalize_number('02318725305', default_country_code: 'US')).to eq('+12318725305')
end

it "should pass Github issue #89" do
Expand Down Expand Up @@ -141,6 +143,15 @@
}).to raise_error(ArgumentError)
end

it "should pass Github issue #95" do
number = '02031234567'
expect(number.phony_normalized(default_country_code: 'GB')).to eq('+442031234567')
end

it 'should pass Github issue #121' do
number = '06-87-73-83-58'
expect(number.phony_normalized(default_country_code: 'FR')).to eq('+33687738358')
end
end

it "should not change original String" do
Expand Down

0 comments on commit 257cd2f

Please sign in to comment.