Module: RuboCop::Cop::Capybara::CssSelector Private
- Defined in:
- lib/rubocop/cop/capybara/mixin/css_selector.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helps parsing css selector.
Class Method Summary collapse
- .attribute?(selector) ⇒ Boolean private
- .attributes(selector) ⇒ Array<String> private
- .classes(selector) ⇒ Array<String> private
- .id(selector) ⇒ String private
- .id?(selector) ⇒ Boolean private
- .multiple_selectors?(selector) ⇒ Boolean private
- .pseudo_classes(selector) ⇒ Array<String> private
Class Method Details
.attribute?(selector) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 48 def attribute?(selector) selector.start_with?('[') end |
.attributes(selector) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 59 def attributes(selector) CssAttributesParser.new(selector).parse end |
.classes(selector) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 39 def classes(selector) selector.scan(/\.([\w-]*)/).flatten end |
.id(selector) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 17 def id(selector) return unless id?(selector) selector.delete('#').gsub(selector.scan(/[^\\]([>,+~.].*)/).join, '') end |
.id?(selector) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 28 def id?(selector) selector.start_with?('#') end |
.multiple_selectors?(selector) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 82 def multiple_selectors?(selector) normalize = selector.gsub(/(\\[>,+~]|\(.*\))/, '') normalize.match?(/[ >,+~]/) end |
.pseudo_classes(selector) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 |
# File 'lib/rubocop/cop/capybara/mixin/css_selector.rb', line 68 def pseudo_classes(selector) # Attributes must be excluded or else the colon in the `href`s URL # will also be picked up as pseudo classes. # "a:not([href='http://example.com']):enabled" => "a:not():enabled" ignored_attribute = selector.gsub(/\[.*?\]/, '') # "a:not():enabled" => ["not()", "enabled"] ignored_attribute.scan(/:([^:]*)/).flatten end |