class Capybara::Selector::CSS::Splitter
Public Instance Methods
split(css)
click to toggle source
# File lib/capybara/selector/css.rb, line 30 def split(css) selectors = [] StringIO.open(css.to_s) do |str| selector = '' while (char = str.getc) case char when '[' selector += parse_square(str) when '(' selector += parse_paren(str) when '"', "'" selector += parse_string(char, str) when '\\' selector += char + str.getc when ',' selectors << selector.strip selector = '' else selector += char end end selectors << selector.strip end selectors end
Private Instance Methods
parse_block(start, final, strio)
click to toggle source
# File lib/capybara/selector/css.rb, line 66 def parse_block(start, final, strio) block = start while (char = strio.getc) case char when final return block + char when '\\' block += char + strio.getc when '"', "'" block += parse_string(char, strio) else block += char end end raise ArgumentError, "Invalid CSS Selector - Block end '#{final}' not found" end
parse_paren(strio)
click to toggle source
# File lib/capybara/selector/css.rb, line 62 def parse_paren(strio) parse_block('(', ')', strio) end
parse_square(strio)
click to toggle source
# File lib/capybara/selector/css.rb, line 58 def parse_square(strio) parse_block('[', ']', strio) end
parse_string(quote, strio)
click to toggle source
# File lib/capybara/selector/css.rb, line 83 def parse_string(quote, strio) string = quote while (char = strio.getc) string += char case char when quote return string when '\\' string += strio.getc end end raise ArgumentError, 'Invalid CSS Selector - string end not found' end