Class: Capybara::Selector
- Inherits:
-
Object
- Object
- Capybara::Selector
- Defined in:
- lib/capybara/selector.rb
Instance Attribute Summary collapse
-
#custom_filters ⇒ Object
readonly
Returns the value of attribute custom_filters.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #call(locator) ⇒ Object
-
#css(&block) ⇒ Object
Same as xpath, but wrap in XPath.css().
- #failure_message(&block) ⇒ Object
- #filter(name, &block) ⇒ Object
-
#initialize(name, &block) ⇒ Selector
constructor
A new instance of Selector.
- #match(&block) ⇒ Object
- #match?(locator) ⇒ Boolean
- #xpath(&block) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Selector
Returns a new instance of Selector.
20 21 22 23 24 25 26 |
# File 'lib/capybara/selector.rb', line 20 def initialize(name, &block) @name = name @custom_filters = {} @match = nil @failure_message = nil instance_eval(&block) end |
Instance Attribute Details
#custom_filters ⇒ Object (readonly)
Returns the value of attribute custom_filters.
3 4 5 |
# File 'lib/capybara/selector.rb', line 3 def custom_filters @custom_filters end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/capybara/selector.rb', line 3 def name @name end |
Class Method Details
.add(name, &block) ⇒ Object
11 12 13 |
# File 'lib/capybara/selector.rb', line 11 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
7 8 9 |
# File 'lib/capybara/selector.rb', line 7 def all @selectors ||= {} end |
.remove(name) ⇒ Object
15 16 17 |
# File 'lib/capybara/selector.rb', line 15 def remove(name) all.delete(name.to_sym) end |
Instance Method Details
#call(locator) ⇒ Object
51 52 53 |
# File 'lib/capybara/selector.rb', line 51 def call(locator) @xpath.call(locator) end |
#css(&block) ⇒ Object
Same as xpath, but wrap in XPath.css().
34 35 36 37 38 39 |
# File 'lib/capybara/selector.rb', line 34 def css(&block) if block @xpath = xpath { |*args| XPath.css(block.call(*args)) } end @xpath end |
#failure_message(&block) ⇒ Object
46 47 48 49 |
# File 'lib/capybara/selector.rb', line 46 def (&block) @failure_message = block if block @failure_message end |
#filter(name, &block) ⇒ Object
59 60 61 |
# File 'lib/capybara/selector.rb', line 59 def filter(name, &block) @custom_filters[name] = block end |
#match(&block) ⇒ Object
41 42 43 44 |
# File 'lib/capybara/selector.rb', line 41 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
55 56 57 |
# File 'lib/capybara/selector.rb', line 55 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
28 29 30 31 |
# File 'lib/capybara/selector.rb', line 28 def xpath(&block) @xpath = block if block @xpath end |