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

- (Selector) initialize(name, &block)

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

- (Object) custom_filters (readonly)

Returns the value of attribute custom_filters



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

def custom_filters
  @custom_filters
end

- (Object) format (readonly)

Returns the value of attribute format



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

def format
  @format
end

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

Class Method Details

+ (Object) add(name, &block)



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

+ (Object) all



26
27
28
# File 'lib/capybara/selector.rb', line 26

def all
  @selectors ||= {}
end

+ (Object) remove(name)



34
35
36
# File 'lib/capybara/selector.rb', line 34

def remove(name)
  all.delete(name.to_sym)
end

Instance Method Details

- (Object) call(locator)



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

- (Object) css(&block)

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

- (Object) filter(name, options = {}, &block)



83
84
85
# File 'lib/capybara/selector.rb', line 83

def filter(name, options={}, &block)
  @custom_filters[name] = Filter.new(name, block, options)
end

- (Object) label(label = nil)



66
67
68
69
# File 'lib/capybara/selector.rb', line 66

def label(label=nil)
  @label = label if label
  @label
end

- (Object) match(&block)



61
62
63
64
# File 'lib/capybara/selector.rb', line 61

def match(&block)
  @match = block if block
  @match
end

- (Boolean) match?(locator)

Returns:

  • (Boolean)


79
80
81
# File 'lib/capybara/selector.rb', line 79

def match?(locator)
  @match and @match.call(locator)
end

- (Object) xpath(&block)



48
49
50
51
52
# File 'lib/capybara/selector.rb', line 48

def xpath(&block)
  @format = :xpath
  @xpath = block if block
  @xpath
end