Class: Capybara::Selector::Filter

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

Instance Method Summary collapse

Constructor Details

#initialize(name, block, options = {}) ⇒ Filter

Returns a new instance of Filter.



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

def initialize(name, block, options={})
  @name = name
  @block = block
  @options = options
  @options[:valid_values] = [true,false] if options[:boolean]
end

Instance Method Details

#defaultObject



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

def default
  @options[:default]
end

#default?Boolean

Returns:

  • (Boolean)


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

def default?
  @options.has_key?(:default)
end

#matches?(node, value) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(node, value)
  return true if skip?(value)

  if @options.has_key?(:valid_values) && !Array(@options[:valid_values]).include?(value)
    msg = "Invalid value #{value.inspect} passed to filter #{@name} - "
    if default?
      warn msg + "defaulting to #{default}"
      value = default
    else
      warn msg + "skipping"
      return true
    end
  end

  @block.call(node, value)
end

#skip?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

def skip?(value)
  @options.has_key?(:skip_if) && value == @options[:skip_if]
end