Sha256: b51908240d4dfe9920c938fe042f1d89c33bcf95b65ee6560383a52362eedc2f
Contents?: true
Size: 854 Bytes
Versions: 2
Compression:
Stored size: 854 Bytes
Contents
class SubstitutionContext def initialize @substitute = '?' end 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 def match(matches, attribute, matcher) matches.find_all { |node| node[attribute] =~ Regexp.new(matcher) } end private 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}\"" end end def substitutable?(value) [ Symbol, Numeric, String, Regexp ].any? { |type| value.is_a? type } end end
Version data entries
2 entries across 2 versions & 1 rubygems