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.



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

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

Instance Attribute Details

#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



10
11
12
# File 'lib/capybara/selector.rb', line 10

def add(name, &block)
  all[name.to_sym] = Capybara::Selector.new(name.to_sym, &block)
end

.allObject



6
7
8
# File 'lib/capybara/selector.rb', line 6

def all
  @selectors ||= {}
end

.normalize(name_or_locator, locator = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/capybara/selector.rb', line 18

def normalize(name_or_locator, locator=nil)
  xpath = if locator
    all[name_or_locator.to_sym].call(locator)
  else
    selector = all.values.find { |s| s.match?(name_or_locator) }
    selector ||= all[Capybara.default_selector]
    selector.call(name_or_locator)
  end
  if xpath.respond_to?(:to_xpaths)
    xpath.to_xpaths
  else
    [xpath.to_s].flatten
  end
end

.remove(name) ⇒ Object



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

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

Instance Method Details

#call(locator) ⇒ Object



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

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

#match(&block) ⇒ Object



44
45
46
47
# File 'lib/capybara/selector.rb', line 44

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

#match?(locator) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#xpath(&block) ⇒ Object



39
40
41
42
# File 'lib/capybara/selector.rb', line 39

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