class SubstitutionContext

Public Class Methods

new() click to toggle source
# File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 2
def initialize
  @substitute = '?'
end

Public Instance Methods

match(matches, attribute, matcher) click to toggle source
# File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 12
def match(matches, attribute, matcher)
  matches.find_all { |node| node[attribute] =~ Regexp.new(matcher) }
end
substitute!(selector, values) click to toggle source
# File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 6
def substitute!(selector, values)
  while !values.empty? && substitutable?(values.first) && selector.index(@substitute)
    selector.sub! @substitute, matcher_for(values.shift)
  end
end

Private Instance Methods

matcher_for(value) click to toggle source
# File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 17
def matcher_for(value)
  value.to_s.inspect # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
end
substitutable?(value) click to toggle source
# File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 21
def substitutable?(value)
  value.is_a?(String) || value.is_a?(Regexp)
end