Skip to content

Commit

Permalink
Merge pull request #27 from espen/default_country_code
Browse files Browse the repository at this point in the history
Use default_country_code when normalizing.
This makes sure we don't replace country codes (as the country_code option does from v0.3.0).
  • Loading branch information
Joost Hietbrink committed May 8, 2013
2 parents 712b1ea + df2729a commit c78dc35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phony_rails/string_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class String
# "010-12341234".phony_formatted(:normalize => :NL)
def phony_formatted(options = {})
normalize_country_code = options.delete(:normalize)
s = (normalize_country_code ? PhonyRails.normalize_number(self, :country_code => normalize_country_code.to_s) : self.gsub(/\D/, ''))
s = (normalize_country_code ? PhonyRails.normalize_number(self, :default_country_code => normalize_country_code.to_s) : self.gsub(/\D/, ''))
return if s.blank?
Phony.formatted(s, options.reverse_merge(:format => :national))
end
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/phony_rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"+31-10-1234123".phony_formatted(:normalize => :NL, :format => :international, :spaces => '-').should eql('+31-10-1234123')
end

it "should phony_format String with country code different than normalized value" do
"+4790909090".phony_formatted(:normalize => :SE, :format => :international).should eql('+47 909 09 090')
end

end

it "should not change original String" do
Expand Down

0 comments on commit c78dc35

Please sign in to comment.