Skip to content

Commit

Permalink
Normalized number uses prefix instead of country as prefix
Browse files Browse the repository at this point in the history
This only affects you if you use the custom formats introduced in the commit of two hours ago.
  • Loading branch information
Narnach committed Jul 12, 2011
1 parent dab994b commit 45e34ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/number_recognizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def valid_or_correct_mobile?(country_bias=nil)

def normalized_number
parse unless @parsed
"#{country}#{local_number}"
"#{prefix}#{local_number}"
end

def correct(country_bias=nil)
Expand Down
9 changes: 5 additions & 4 deletions spec/number_recognizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,15 @@

describe "custom format" do
it 'should use the custom country' do
NumberRecognizer.add_format :country => "Utopia", :mobile=>true, :format => /(99)(9\d{8})/, :country_code=>999
NumberRecognizer.add_format :country => "Utopia", :mobile=>true, :format => /(999)(\d{8})/, :country_code=>99
@nc = NumberRecognizer.new('0099912345678')
@nc.should be_valid
@nc.should be_mobile
@nc.country.should == '999'
@nc.prefix.should == '99'
@nc.local_number.should == '912345678'
@nc.country.should == '99'
@nc.prefix.should == '999'
@nc.local_number.should == '12345678'
@nc.country_name.should == 'Utopia'
@nc.normalized_number.should == "99912345678"
end
end
end

0 comments on commit 45e34ee

Please sign in to comment.