Permalink
Browse files

Merge branch 'master' of https://github.com/PugglePay/phony_rails

  • Loading branch information...
2 parents 8796c35 + e451dec commit f6018e53e630bbb2287c7d29f802b686f7e985a0 @joost committed Feb 13, 2013
Showing with 16 additions and 1 deletion.
  1. +4 −1 lib/phony_rails/string_extensions.rb
  2. +12 −0 spec/lib/phony_rails_spec.rb
@@ -5,7 +5,10 @@ class String
# "31612341234".phony_formatted # => '06 12341234'
# "31612341234".phony_formatted(:spaces => '-') # => '06-12341234'
def phony_formatted(options = {})
- Phony.formatted(self, options.reverse_merge(:format => :national))
+ normalized = PhonyRails.normalize_number(self)
+ if normalized
+ Phony.formatted(normalized, options.reverse_merge(:format => :national))
+ end
end
end
@@ -9,6 +9,18 @@
it "should phony_format a String" do
"31101234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-1234123')
end
+
+ it "should accept strings with non-digits in it" do
+ "+31-10-1234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-1234123')
+ end
+
+ it "returns nil if implausible phone" do
+ "this is not a phone".phony_formatted.should be_nil
+ end
+
+ it "returns nil on blank string" do
+ "".phony_formatted.should be_nil
+ end
end
describe 'PhonyRails#normalize_number' do

0 comments on commit f6018e5

Please sign in to comment.