diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-03-10 00:33:32 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-10 00:33:32 +0000 |
commit | 1ab84247ca4b80afbd82afe7539b3449636344c4 (patch) | |
tree | 9ca5e3bee3a07b68c9d900ff129b69bc740405c2 /actionpack/lib/action_view/helpers/number_helper.rb | |
parent | b6fb79c531a0079274f7b459302e6290c9183f28 (diff) | |
parent | 4458edc882b229ea44602da20a6440a6f233f1c8 (diff) | |
download | rails-1ab84247ca4b80afbd82afe7539b3449636344c4.tar.gz rails-1ab84247ca4b80afbd82afe7539b3449636344c4.tar.bz2 rails-1ab84247ca4b80afbd82afe7539b3449636344c4.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/guides/files/stylesheets/main.css
railties/guides/rails_guides/generator.rb
railties/guides/source/index.erb.textile
Diffstat (limited to 'actionpack/lib/action_view/helpers/number_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index e622f97b9e..539f43c6e3 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -15,6 +15,7 @@ module ActionView # * <tt>:country_code</tt> - Sets the country code for the phone number. # # ==== Examples + # number_to_phone(5551234) # => 555-1234 # number_to_phone(1235551234) # => 123-555-1234 # number_to_phone(1235551234, :area_code => true) # => (123) 555-1234 # number_to_phone(1235551234, :delimiter => " ") # => 123 555 1234 @@ -37,7 +38,8 @@ module ActionView str << if area_code number.gsub!(/([0-9]{1,3})([0-9]{3})([0-9]{4}$)/,"(\\1) \\2#{delimiter}\\3") else - number.gsub!(/([0-9]{1,3})([0-9]{3})([0-9]{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3") + number.gsub!(/([0-9]{0,3})([0-9]{3})([0-9]{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3") + number.starts_with?('-') ? number.slice!(1..-1) : number end str << " x #{extension}" unless extension.blank? str |