Class: Capybara::Selector::CSS::Splitter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/capybara/selector/css.rb |
Instance Method Summary
- #split(css)
- #parse_block(start, final, strio) private
- #parse_paren(strio) private
- #parse_square(strio) private
- #parse_string(quote, strio) private
Instance Method Details
#parse_block(start, final, strio) (private)
# File 'lib/capybara/selector/css.rb', line 69
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) (private)
[ GitHub ]# File 'lib/capybara/selector/css.rb', line 65
def parse_paren(strio) parse_block('(', ')', strio) end
#parse_square(strio) (private)
[ GitHub ]# File 'lib/capybara/selector/css.rb', line 61
def parse_square(strio) parse_block('[', ']', strio) end
#parse_string(quote, strio) (private)
#split(css)
[ GitHub ]# File 'lib/capybara/selector/css.rb', line 33
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.clear else selector << char end end selectors << selector.strip end selectors end