Class: Capybara::Selector::Filter
- Inherits:
-
Object
- Object
- Capybara::Selector::Filter
- Defined in:
- lib/capybara/selector/filter.rb
Instance Method Summary collapse
- #default ⇒ Object
- #default? ⇒ Boolean
-
#initialize(name, block, options = {}) ⇒ Filter
constructor
A new instance of Filter.
- #matches?(node, value) ⇒ Boolean
- #skip?(value) ⇒ Boolean
Constructor Details
#initialize(name, block, options = {}) ⇒ Filter
Returns a new instance of Filter.
5 6 7 8 9 10 |
# File 'lib/capybara/selector/filter.rb', line 5 def initialize(name, block, ={}) @name = name @block = block @options = @options[:valid_values] = [true,false] if [:boolean] end |
Instance Method Details
#default ⇒ Object
16 17 18 |
# File 'lib/capybara/selector/filter.rb', line 16 def default @options[:default] end |
#default? ⇒ Boolean
12 13 14 |
# File 'lib/capybara/selector/filter.rb', line 12 def default? @options.has_key?(:default) end |
#matches?(node, value) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/capybara/selector/filter.rb', line 20 def matches?(node, value) return true if skip?(value) if !valid_value?(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
37 38 39 |
# File 'lib/capybara/selector/filter.rb', line 37 def skip?(value) @options.has_key?(:skip_if) && value == @options[:skip_if] end |