From 5fe4706486aac3844538d158e8f99b94218ee0e4 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Fri, 18 Feb 2022 11:58:45 -0800 Subject: [PATCH 1/2] Add state search - for granularity & jmp-register Note that this is not quite complete yet, since we need to pull in the STATE_MAP stuff used elsewhere to make it work properly. But it will at least work for every state/province/territory that is not Quebec for now, which is way better than nothing. Quebec users will get the same fallbacks they had before. --- lib/tel_selections.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 6c266121462b04f9e7c4747bdd56973fa80d58e6..2c15068988304bb315600c274e25787d27900e0d 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -170,6 +170,7 @@ class TelSelections npaNxx: [:NpaNxx, /\A(?:[2-9][0-9]{2}){2}\Z/], npaNxxx: [:NpaNxxx, /\A(?:[2-9][0-9]{2}){2}[0-9]\Z/], zip: [:PostalCode, /\A\d{5}(?:-\d{4})?\Z/], + state: [:State, /\A[a-zA-Z]{2}\Z/], localVanity: [:LocalVanity, /\A~(.+)\Z/] }.each do |k, args| klass = const_set( From a086018fd133bd18fb6374cc490a71512d24e5a0 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 21 Feb 2022 09:36:47 -0500 Subject: [PATCH 2/2] Finish state search and add test --- lib/tel_selections.rb | 25 ++++++++++++++++++------- test/test_tel_selections.rb | 5 +++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 2c15068988304bb315600c274e25787d27900e0d..3006a63a94e760e27ca8f5588593c97df5d4d779 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -170,7 +170,6 @@ class TelSelections npaNxx: [:NpaNxx, /\A(?:[2-9][0-9]{2}){2}\Z/], npaNxxx: [:NpaNxxx, /\A(?:[2-9][0-9]{2}){2}[0-9]\Z/], zip: [:PostalCode, /\A\d{5}(?:-\d{4})?\Z/], - state: [:State, /\A[a-zA-Z]{2}\Z/], localVanity: [:LocalVanity, /\A~(.+)\Z/] }.each do |k, args| klass = const_set( @@ -187,6 +186,22 @@ class TelSelections end end + class State + Q.register(/\A[a-zA-Z]{2}\Z/, &method(:new)) + + STATE_MAP = { + "QC" => "PQ" + }.freeze + + def initialize(state) + @state = STATE_MAP.fetch(state.upcase, state.upcase) + end + + def iris_query + { state: @state } + end + end + class CityState Q.register(/\A([^,]+)\s*,\s*([a-zA-Z]{2})\Z/, &method(:new)) @@ -203,17 +218,13 @@ class TelSelections "west durham" => "Durham" }.freeze - STATE_MAP = { - "QC" => "PQ" - }.freeze - def initialize(city, state) @city = CITY_MAP.fetch(city.downcase, city) - @state = STATE_MAP.fetch(state.upcase, state.upcase) + @state = State.new(state) end def iris_query - { city: @city, state: @state } + @state.iris_query.merge(city: @city) end end end diff --git a/test/test_tel_selections.rb b/test/test_tel_selections.rb index f090c052646c07e007bcd8d53fbe7f0980d9d3bf..1285fd05dc99a78cc8f30a039d67d6a7ac77a0b5 100644 --- a/test/test_tel_selections.rb +++ b/test/test_tel_selections.rb @@ -119,6 +119,11 @@ class TelSelectionsTest < Minitest::Test assert_equal({ localVanity: "mboa" }, q.iris_query) end + def test_for_state + q = TelSelections::ChooseTel::Q.for("ON") + assert_equal({ state: "ON" }, q.iris_query) + end + def test_for_citystate q = TelSelections::ChooseTel::Q.for("Toronto, ON") assert_equal({ city: "Toronto", state: "ON" }, q.iris_query)