<commit_before>class Email < ActiveRecord::Base
  validates :newsletter_id, presence: true
  after_create :refresh_sitemap
  after_create :check_for_welcome
  after_create :prep_remove_unsubscribe
  include AlgoliaSearch

  extend FriendlyId
  friendly_id :subject, use: :slugged

  def self.remove_unsubscribe_tag
    html_doc = Nokogiri::HTML(self.raw_html)
  end

  def self.remove_unsubscribe email_id
    @email = Email.find email_id
    @newsletter = Newsletter.find @email.newsletter_id
    if !@email.raw_html.nil? 
      @html = Nokogiri::HTML(@email.raw_html)
      @html.css('a').each do |el|
        if el.text.downcase.include? "unsubscribe"
          el['href'] = ""
          el.content = ""
          puts 'Found unsubscribe'
          puts 'Saving change'
        end
        
        if el.text.downcase.include? "subscription preferences"
          el['href'] = ""
          el.content = ""
          puts 'Found subscription preferences'
          puts 'Saving change'<commit_msg>Fix index<commit_after>class Email < ActiveRecord::Base
  validates :newsletter_id, presence: true
  after_create :refresh_sitemap
  after_create :check_for_welcome
  after_create :prep_remove_unsubscribe
  include AlgoliaSearch

  algoliasearch do
    # associated index settings can be configured from here
  end

  extend FriendlyId
  friendly_id :subject, use: :slugged

  def self.remove_unsubscribe_tag
    html_doc = Nokogiri::HTML(self.raw_html)
  end

  def self.remove_unsubscribe email_id
    @email = Email.find email_id
    @newsletter = Newsletter.find @email.newsletter_id
    if !@email.raw_html.nil? 
      @html = Nokogiri::HTML(@email.raw_html)
      @html.css('a').each do |el|
        if el.text.downcase.include? "unsubscribe"
          el['href'] = ""
          el.content = ""
          puts 'Found unsubscribe'
          puts 'Saving change'
        end
        
        if el.text.downcase.include? "subscription preferences"
          el['href'] = ""
          el.content = ""
          puts 'Found subscription preferences'
          puts 'Saving change'
{'fraction_non_alphanumeric': 0.09269932756964457, 'fraction_numerical': 0.0, 'mean_word_length': 2.7941712204007287, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6916533', 'n_tokens_mistral': 646, 'n_tokens_neox': 646, 'n_words': 145}