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().
- #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.
39 40 41 42 43 44 45 46 |
# File 'lib/capybara/selector.rb', line 39 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.
23 24 25 |
# File 'lib/capybara/selector.rb', line 23 def custom_filters @custom_filters end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
23 24 25 |
# File 'lib/capybara/selector.rb', line 23 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/capybara/selector.rb', line 23 def name @name end |
Class Method Details
.add(name, &block) ⇒ Object
30 31 32 |
# File 'lib/capybara/selector.rb', line 30 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
26 27 28 |
# File 'lib/capybara/selector.rb', line 26 def all @selectors ||= {} end |
.remove(name) ⇒ Object
34 35 36 |
# File 'lib/capybara/selector.rb', line 34 def remove(name) all.delete(name.to_sym) end |
Instance Method Details
#call(locator) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/capybara/selector.rb', line 71 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().
55 56 57 58 59 |
# File 'lib/capybara/selector.rb', line 55 def css(&block) @format = :css @css = block if block @css end |
#filter(name, options = {}, &block) ⇒ Object
83 84 85 |
# File 'lib/capybara/selector.rb', line 83 def filter(name, ={}, &block) @custom_filters[name] = Filter.new(name, block, ) end |
#label(label = nil) ⇒ Object
66 67 68 69 |
# File 'lib/capybara/selector.rb', line 66 def label(label=nil) @label = label if label @label end |
#match(&block) ⇒ Object
61 62 63 64 |
# File 'lib/capybara/selector.rb', line 61 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
79 80 81 |
# File 'lib/capybara/selector.rb', line 79 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
48 49 50 51 52 |
# File 'lib/capybara/selector.rb', line 48 def xpath(&block) @format = :xpath @xpath = block if block @xpath end |