Class: SubstitutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb

Instance Method Summary collapse

Constructor Details

#initializeSubstitutionContext

Returns a new instance of SubstitutionContext.


2
3
4
# File 'lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb', line 2

def initialize
  @substitute = '?'
end

Instance Method Details

#match(matches, attribute, matcher) ⇒ Object


16
17
18
# File 'lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb', line 16

def match(matches, attribute, matcher)
  matches.find_all { |node| node[attribute] =~ Regexp.new(matcher) }
end

#substitute!(selector, values, format_for_presentation = false) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb', line 6

def substitute!(selector, values, format_for_presentation = false)
  selector = selector.dup

  while !values.empty? && substitutable?(values.first) && selector.index(@substitute)
    selector.sub! @substitute, matcher_for(values.shift, format_for_presentation)
  end

  selector
end