class Watir::Locators::Element::SelectorBuilder::RegexpDisassembler
Public Class Methods
new(regexp)
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 9 def initialize(regexp) @regexp = regexp @regexp_source = regexp.source end
Public Instance Methods
substrings()
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 14 def substrings @substrings ||= begin strs = extract_strings(Regexp::Parser.parse(@regexp), [+'']) strs.map!(&:downcase) if @regexp.casefold? strs.reject(&:empty?).uniq end end
Private Instance Methods
extract_strings(expression, strings)
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 36 def extract_strings(expression, strings) expression.each do |exp| if optional?(exp) strings.push(+'') next end if %i[meta set].include?(exp.type) strings.push(+'') next end if exp.terminal? case exp.type when :literal strings.last << (exp.text * min_repeat(exp)) when :escape strings.last << (exp.char * min_repeat(exp)) else strings.push(+'') end else min_repeat(exp).times { extract_strings(exp, strings) } end strings.push(+'') unless fixed_repeat?(exp) end strings end
fixed_repeat?(exp)
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 28 def fixed_repeat?(exp) min_repeat(exp) == (exp.quantifier&.max || 1) end
min_repeat(exp)
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 24 def min_repeat(exp) exp.quantifier&.min || 1 end
optional?(exp)
click to toggle source
# File lib/watir/locators/element/selector_builder/regexp_disassembler.rb, line 32 def optional?(exp) min_repeat(exp).zero? end