Class: Capybara::Selector::XPathBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/selector/builders/xpath_builder.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.attribute_conditions(attributes) ⇒ Object

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.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capybara/selector/builders/xpath_builder.rb', line 10

def attribute_conditions(attributes)
  attributes.map do |attribute, value|
    case value
    when XPath::Expression
      XPath.attr(attribute)[value]
    when Regexp
      XPath.attr(attribute)[regexp_to_xpath_conditions(value)]
    when true
      XPath.attr(attribute)
    when false, nil
      !XPath.attr(attribute)
    else
      XPath.attr(attribute) == value.to_s
    end
  end.reduce(:&)
end

.class_conditions(classes) ⇒ Object

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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/capybara/selector/builders/xpath_builder.rb', line 27

def class_conditions(classes)
  case classes
  when XPath::Expression, Regexp
    attribute_conditions(class: classes)
  else
    Array(classes).map do |klass|
      if klass.start_with?('!') && !klass.start_with?('!!!')
        !XPath.attr(:class).contains_word(klass.slice(1..-1))
      else
        XPath.attr(:class).contains_word(klass.sub(/^!!/, ''))
      end
    end.reduce(:&)
  end
end