Class: Playwright::UrlMatcher
- Inherits:
-
Object
- Object
- Playwright::UrlMatcher
- Defined in:
- lib/playwright/url_matcher.rb
Instance Method Summary collapse
- #as_pattern ⇒ Object
-
#initialize(url, base_url:) ⇒ UrlMatcher
constructor
A new instance of UrlMatcher.
- #match?(target_url) ⇒ Boolean
Constructor Details
#initialize(url, base_url:) ⇒ UrlMatcher
Returns a new instance of UrlMatcher.
5 6 7 8 9 |
# File 'lib/playwright/url_matcher.rb', line 5 def initialize(url, base_url:) @url = url @base_url = base_url validate_glob_pattern if @url.is_a?(String) end |
Instance Method Details
#as_pattern ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/playwright/url_matcher.rb', line 11 def as_pattern case @url when String { glob: @url } when Regexp regex = JavaScript::Regex.new(@url) { regexSource: regex.source, regexFlags: regex.flag } else nil end end |
#match?(target_url) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/playwright/url_matcher.rb', line 23 def match?(target_url) case @url when String joined_url == target_url || File.fnmatch?(@url, target_url) when Regexp @url.match?(target_url) else false end end |