From 15ca96c2eaa988507053edc401a06f0dfad7e6da Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 31 Aug 2021 13:24:41 -0500 Subject: [PATCH] Format tel for human reader --- lib/tel_selections.rb | 3 ++- test/test_tel_selections.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 4e9eaf9f1df5074ce019cdae57cfb80ee03f97bd..8cc558c7273987bf70de6521837fd8a4bcc33493 100644 --- a/lib/tel_selections.rb +++ b/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 diff --git a/test/test_tel_selections.rb b/test/test_tel_selections.rb index cc80cd2835521c7d97d60c5208007332c1685f0f..78cae2ea58a372beafd1192e4a1edba15cb7a7c4 100644 --- a/test/test_tel_selections.rb +++ b/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