Path: blob/trunk/rb/lib/selenium/webdriver/bidi/network/url_pattern.rb
4057 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 BiDi24#25# @api private26#2728module UrlPattern29module_function3031def format_pattern(url_patterns, pattern_type)32case pattern_type33when :string34to_url_string_pattern(url_patterns)35when :url36to_url_pattern(url_patterns)37else38raise ArgumentError, "Unknown pattern type: #{pattern_type}"39end40end4142def to_url_pattern(*url_patterns)43url_patterns.flatten.map do |url_pattern|44uri = URI.parse(url_pattern)4546{47type: 'pattern',48protocol: uri.scheme || '',49hostname: uri.host || '',50port: uri.port.to_s,51pathname: uri.path || '',52search: uri.query || ''53}54end55end5657def to_url_string_pattern(*url_patterns)58url_patterns.flatten.map do |url_pattern|59{60type: 'string',61pattern: url_pattern62}63end64end65end66end # BiDi67end # WebDriver68end # Selenium697071