aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/number_helper/number_to_phone_converter.rb')
-rw-r--r--activesupport/lib/active_support/number_helper/number_to_phone_converter.rb21
1 files changed, 10 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
index 9828bec053..af2ee56d91 100644
--- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
+++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
@@ -1,10 +1,9 @@
module ActiveSupport
module NumberHelper
- class NumberToPhoneConverter < NumberConverter
+ class NumberToPhoneConverter < NumberConverter #:nodoc:
def convert
- str = ''
- str << country_code(opts[:country_code])
- str << convert_to_phone_number(@number.to_s.strip)
+ str = country_code(opts[:country_code])
+ str << convert_to_phone_number(number.to_s.strip)
str << phone_ext(opts[:extension])
end
@@ -19,18 +18,18 @@ module ActiveSupport
end
def convert_with_area_code(number)
- number.gsub(/(\d{1,3})(\d{3})(\d{4}$)/,"(\\1) \\2#{delimiter}\\3")
+ number.gsub!(/(\d{1,3})(\d{3})(\d{4}$)/,"(\\1) \\2#{delimiter}\\3")
+ number
end
def convert_without_area_code(number)
- number.tap { |n|
- n.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
- n.slice!(0, 1) if begins_with_delimiter?(n)
- }
+ number.gsub!(/(\d{0,3})(\d{3})(\d{4})$/,"\\1#{delimiter}\\2#{delimiter}\\3")
+ number.slice!(0, 1) if start_with_delimiter?(number)
+ number
end
- def begins_with_delimiter?(number)
- number.start_with?(delimiter) && !delimiter.blank?
+ def start_with_delimiter?(number)
+ delimiter.present? && number.start_with?(delimiter)
end
def delimiter