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().
- #filter(name, &block) ⇒ Object
-
#initialize(name, &block) ⇒ Selector
constructor
A new instance of Selector.
- #label(label = nil) ⇒ Object
- #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 27 |
# File 'lib/capybara/selector.rb', line 20 def initialize(name, &block) @name = name @custom_filters = {} @match = nil @label = 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
52 53 54 |
# File 'lib/capybara/selector.rb', line 52 def call(locator) @xpath.call(locator) end |
#css(&block) ⇒ Object
Same as xpath, but wrap in XPath.css().
35 36 37 38 39 40 |
# File 'lib/capybara/selector.rb', line 35 def css(&block) if block @xpath = xpath { |*args| XPath.css(block.call(*args)) } end @xpath end |
#filter(name, &block) ⇒ Object
60 61 62 |
# File 'lib/capybara/selector.rb', line 60 def filter(name, &block) @custom_filters[name] = block end |
#label(label = nil) ⇒ Object
47 48 49 50 |
# File 'lib/capybara/selector.rb', line 47 def label(label=nil) @label = label if label @label end |
#match(&block) ⇒ Object
42 43 44 45 |
# File 'lib/capybara/selector.rb', line 42 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
56 57 58 |
# File 'lib/capybara/selector.rb', line 56 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
29 30 31 32 |
# File 'lib/capybara/selector.rb', line 29 def xpath(&block) @xpath = block if block @xpath end |