Class: Capybara::Selector

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

Defined Under Namespace

Classes: Normalized

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Selector) initialize(name, &block)



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

def initialize(name, &block)
  @name = name
  instance_eval(&block)
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



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

def name
  @name
end

Class Method Details

+ (Object) add(name, &block)



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

+ (Object) all



13
14
15
# File 'lib/capybara/selector.rb', line 13

def all
  @selectors ||= {}
end

+ (Object) normalize(*args)



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.options = 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

+ (Object) remove(name)



21
22
23
# File 'lib/capybara/selector.rb', line 21

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

Instance Method Details

- (Object) call(locator)



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

def call(locator)
  @xpath.call(locator)
end

- (Object) failure_message(&block)



63
64
65
66
# File 'lib/capybara/selector.rb', line 63

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

- (Object) match(&block)



58
59
60
61
# File 'lib/capybara/selector.rb', line 58

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

- (Boolean) match?(locator)



72
73
74
# File 'lib/capybara/selector.rb', line 72

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

- (Object) xpath(&block)



53
54
55
56
# File 'lib/capybara/selector.rb', line 53

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