Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #27 from espen/default_country_code

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...
commit c78dc3581544ea1a75a4cee3f0ec4f6e7c2a901f 2 parents 712b1ea + df2729a
@joost authored
View
2  lib/phony_rails/string_extensions.rb
@@ -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
View
4 spec/lib/phony_rails_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.