# 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 16
    def match(matches, attribute, matcher)
      matches.find_all { |node| node[attribute] =~ Regexp.new(matcher) }
    end

substitute!(selector, values, format_for_presentation = false) click to toggle source

    # 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

### Private Instance Methods

matcher_for(value, format_for_presentation) click to toggle source

    # File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 21
    def matcher_for(value, format_for_presentation)
      # Nokogiri doesn't like arbitrary values without quotes, hence inspect.
      if format_for_presentation
        value.inspect # Avoid to_s so Regexps aren't put in quotes.
      else
        value.to_s.inspect
      end
    end

substitutable?(value) click to toggle source

    # File lib/rails/dom/testing/assertions/selector_assertions/substitution_context.rb, line 30
    def substitutable?(value)
      value.is_a?(String) || value.is_a?(Regexp)
    end