Path: blob/trunk/rb/lib/selenium/webdriver/bidi/network/url_pattern.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require 'uri'2021module Selenium22module WebDriver23class BiDi24module UrlPattern25module_function2627def format_pattern(url_patterns, pattern_type)28case pattern_type29when :string30to_url_string_pattern(url_patterns)31when :url32to_url_pattern(url_patterns)33else34raise ArgumentError, "Unknown pattern type: #{pattern_type}"35end36end3738def to_url_pattern(*url_patterns)39url_patterns.flatten.map do |url_pattern|40uri = URI.parse(url_pattern)4142{43type: 'pattern',44protocol: uri.scheme || '',45hostname: uri.host || '',46port: uri.port.to_s,47pathname: uri.path || '',48search: uri.query || ''49}50end51end5253def to_url_string_pattern(*url_patterns)54url_patterns.flatten.map do |url_pattern|55{56type: 'string',57pattern: url_pattern58}59end60end61end62end # BiDi63end # WebDriver64end # Selenium656667