<commit_before>module Stowaway
  class Matcher
    def match?(line, file)
      @line, @file = line, file
      html_attr_ref? ||
      haml_attr_ref? ||
      rails_js_ref?  ||
      rails_css_ref? ||
      css_url_ref?
    end

    private

    def html_attr_ref?
      exp = /(src|link|href|:href)\s?[=|=>]\s?(["|'])(%s)(\2)/
      direct_or_public_dir_match?(exp)
    end

    def haml_attr_ref?
      exp = /(:src|:link|:href)(\s?=>\s?)(["|'])(%s)(\3)/
      direct_or_public_dir_match?(exp)
    end

    def rails_js_ref?
      return false unless @line =~ /=?\s(javascript_include_tag)?\s(["|'])(.+)(\2)/
      params = $3.gsub(/[\s|"]/, "").split(",")
      params.each do |f|
          return true if "/public/javascripts/#{f}" == @file.root_path || 
                         "/public/javascripts/#{f}.js" == @file.root_path
      end
      false<commit_msg>added fallback for matching on name<commit_after>module Stowaway
  class Matcher
    def match?(line, file)
      @line, @file = line, file
      html_attr_ref? ||
      haml_attr_ref? ||
      rails_js_ref?  ||
      rails_css_ref? ||
      css_url_ref?   ||
      line.include?(file.name)
    end

    private

    def html_attr_ref?
      exp = /(src|link|href|:href)\s?[=|=>]\s?(["|'])(%s)(\2)/
      direct_or_public_dir_match?(exp)
    end

    def haml_attr_ref?
      exp = /(:src|:link|:href)(\s?=>\s?)(["|'])(%s)(\3)/
      direct_or_public_dir_match?(exp)
    end

    def rails_js_ref?
      return false unless @line =~ /=?\s(javascript_include_tag)?\s(["|'])(.+)(\2)/
      params = $3.gsub(/[\s|"]/, "").split(",")
      params.each do |f|
          return true if "/public/javascripts/#{f}" == @file.root_path || 
                         "/public/javascripts/#{f}.js" == @file.root_path
      end
      false
{'fraction_non_alphanumeric': 0.19810267857142858, 'fraction_numerical': 0.004464285714285714, 'mean_word_length': 2.345149253731343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '625973', 'n_tokens_mistral': 693, 'n_tokens_neox': 673, 'n_words': 109}