Class: Capybara::Selector
- Inherits:
-
Object
- Object
- Capybara::Selector
- Defined in:
- lib/capybara/selector.rb
Defined Under Namespace
Classes: Filter
Instance Attribute Summary collapse
-
#custom_filters ⇒ Object
readonly
Returns the value of attribute custom_filters.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#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().
- #describe(&block) ⇒ Object
- #description(options = {}) ⇒ Object
- #filter(name, options = {}, &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.
43 44 45 46 47 48 49 50 51 |
# File 'lib/capybara/selector.rb', line 43 def initialize(name, &block) @name = name @custom_filters = {} @match = nil @label = nil @failure_message = nil @description = nil instance_eval(&block) end |
Instance Attribute Details
#custom_filters ⇒ Object (readonly)
Returns the value of attribute custom_filters.
27 28 29 |
# File 'lib/capybara/selector.rb', line 27 def custom_filters @custom_filters end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
27 28 29 |
# File 'lib/capybara/selector.rb', line 27 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/capybara/selector.rb', line 27 def name @name end |
Class Method Details
.add(name, &block) ⇒ Object
34 35 36 |
# File 'lib/capybara/selector.rb', line 34 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
30 31 32 |
# File 'lib/capybara/selector.rb', line 30 def all @selectors ||= {} end |
.remove(name) ⇒ Object
38 39 40 |
# File 'lib/capybara/selector.rb', line 38 def remove(name) all.delete(name.to_sym) end |
Instance Method Details
#call(locator) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/capybara/selector.rb', line 80 def call(locator) if @format==:css @css.call(locator) else @xpath.call(locator) end end |
#css(&block) ⇒ Object
Same as xpath, but wrap in XPath.css().
60 61 62 63 64 |
# File 'lib/capybara/selector.rb', line 60 def css(&block) @format = :css @css = block if block @css end |
#describe(&block) ⇒ Object
96 97 98 |
# File 'lib/capybara/selector.rb', line 96 def describe &block @description = block end |
#description(options = {}) ⇒ Object
76 77 78 |
# File 'lib/capybara/selector.rb', line 76 def description(={}) (@description && @description.call()).to_s end |
#filter(name, options = {}, &block) ⇒ Object
92 93 94 |
# File 'lib/capybara/selector.rb', line 92 def filter(name, ={}, &block) @custom_filters[name] = Filter.new(name, block, ) end |
#label(label = nil) ⇒ Object
71 72 73 74 |
# File 'lib/capybara/selector.rb', line 71 def label(label=nil) @label = label if label @label end |
#match(&block) ⇒ Object
66 67 68 69 |
# File 'lib/capybara/selector.rb', line 66 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
88 89 90 |
# File 'lib/capybara/selector.rb', line 88 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
53 54 55 56 57 |
# File 'lib/capybara/selector.rb', line 53 def xpath(&block) @format = :xpath @xpath = block if block @xpath end |