~singpolyma/sgx-jmp

a086018fd133bd18fb6374cc490a71512d24e5a0 — Stephen Paul Weber 11 months ago 5fe4706
Finish state search and add test
2 files changed, 23 insertions(+), 7 deletions(-)

M lib/tel_selections.rb
M test/test_tel_selections.rb
M lib/tel_selections.rb => lib/tel_selections.rb +18 -7
@@ 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

M test/test_tel_selections.rb => test/test_tel_selections.rb +5 -0
@@ 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)