Format tel for human reader

Stephen Paul Weber created

Change summary

lib/tel_selections.rb       | 3 ++-
test/test_tel_selections.rb | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)

Detailed changes

lib/tel_selections.rb 🔗

@@ -115,7 +115,8 @@ class TelSelections
 			end
 
 			def to_s
-				"#{@tel} (#{@locality}, #{@region})"
+				@tel =~ /\A\+1(\d{3})(\d{3})(\d+)\Z/
+				"(#{$1}) #{$2}-#{$3} (#{@locality}, #{@region})"
 			end
 		end
 

test/test_tel_selections.rb 🔗

@@ -66,7 +66,7 @@ class TelSelectionsTest < Minitest::Test
 		end
 
 		def test_to_s
-			assert_equal "+15551234567 (Toronto, ON)", @tn.to_s
+			assert_equal "(555) 123-4567 (Toronto, ON)", @tn.to_s
 		end
 
 		def test_tel
@@ -75,7 +75,7 @@ class TelSelectionsTest < Minitest::Test
 
 		def test_option
 			assert_equal(
-				{ label: "+15551234567 (Toronto, ON)", value: "+15551234567" },
+				{ label: "(555) 123-4567 (Toronto, ON)", value: "+15551234567" },
 				@tn.option
 			)
 		end