Class: Capybara::Selector
- Inherits:
-
Object
- Object
- Capybara::Selector
- Defined in:
- lib/capybara/selector.rb
Defined Under Namespace
Classes: Normalized
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #call(locator) ⇒ Object
- #failure_message(&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.
48 49 50 51 |
# File 'lib/capybara/selector.rb', line 48 def initialize(name, &block) @name = name instance_eval(&block) end |
Instance Attribute Details
#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
17 18 19 |
# File 'lib/capybara/selector.rb', line 17 def add(name, &block) all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block) end |
.all ⇒ Object
13 14 15 |
# File 'lib/capybara/selector.rb', line 13 def all @selectors ||= {} end |
.normalize(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capybara/selector.rb', line 25 def normalize(*args) normalized = Normalized.new normalized. = if args.last.is_a?(Hash) then args.pop else {} end if args[1] normalized.selector = all[args[0]] normalized.locator = args[1] else normalized.selector = all.values.find { |s| s.match?(args[0]) } normalized.locator = args[0] end normalized.selector ||= all[Capybara.default_selector] xpath = normalized.selector.call(normalized.locator) if xpath.respond_to?(:to_xpaths) normalized.xpaths = xpath.to_xpaths else normalized.xpaths = [xpath.to_s].flatten end normalized end |
.remove(name) ⇒ Object
21 22 23 |
# File 'lib/capybara/selector.rb', line 21 def remove(name) all.delete(name.to_sym) end |
Instance Method Details
#call(locator) ⇒ Object
68 69 70 |
# File 'lib/capybara/selector.rb', line 68 def call(locator) @xpath.call(locator) end |
#failure_message(&block) ⇒ Object
63 64 65 66 |
# File 'lib/capybara/selector.rb', line 63 def (&block) @failure_message = block if block @failure_message end |
#match(&block) ⇒ Object
58 59 60 61 |
# File 'lib/capybara/selector.rb', line 58 def match(&block) @match = block if block @match end |
#match?(locator) ⇒ Boolean
72 73 74 |
# File 'lib/capybara/selector.rb', line 72 def match?(locator) @match and @match.call(locator) end |
#xpath(&block) ⇒ Object
53 54 55 56 |
# File 'lib/capybara/selector.rb', line 53 def xpath(&block) @xpath = block if block @xpath end |