Class: Rails::Dom::Testing::Assertions::SelectorAssertions::SubstitutionContext

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeSubstitutionContext

Returns a new instance of SubstitutionContext.



9
10
11
# File 'lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb', line 9

def initialize
  @substitute = "?"
end

Instance Method Details

#match(matches, attribute, matcher) ⇒ Object



20
21
22
# File 'lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb', line 20

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

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



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

def substitute!(selector, values, format_for_presentation = false)
  selector.gsub @substitute do |match|
    next match[0] if values.empty? || !substitutable?(values.first)
    matcher_for(values.shift, format_for_presentation)
  end
end