Class: Capybara::Selector

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

Defined Under Namespace

Classes: Filter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Returns the value of attribute custom_filters.



23
24
25
# File 'lib/capybara/selector.rb', line 23

def custom_filters
  @custom_filters
end

#formatObject (readonly)

Returns the value of attribute format.



23
24
25
# File 'lib/capybara/selector.rb', line 23

def format
  @format
end

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

.allObject



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, options={}, &block)
  @custom_filters[name] = Filter.new(name, block, options)
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

Returns:

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