Class: Capybara::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/selector.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_filtersObject (readonly)

Returns the value of attribute custom_filters.



3
4
5
# File 'lib/capybara/selector.rb', line 3

def custom_filters
  @custom_filters
end

#nameObject (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

.allObject



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 failure_message(&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

Returns:

  • (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