<commit_before>

module Fedora2To3PidRenamer::Manipulator
  class Base
    attr_reader :source, :config
    
    def self.output_for(*args)
      manipulator = new(*args)
      manipulator.run
      manipulator.output
    end
    
    def initialize(source, config)
      @source = source
      @config = config
    end
    
    def run
      raise 'run must be defined in sub-classes'
    end
    
    def output
      raise 'output must be defined in sub-classes'
    end
    
    private
    def change(text, before, after)
      pattern = Regexp.new("changeme:#{before}(#{end_of_string_or_non_word})")
      
      replacement = [
        config.changeme_replacement,
        after
      ].join(':') + first_capture_group
      
      text.gsub! pattern, replacement
    end
    
    def end_of_string_or_non_word 
      '$|\W'
    end
    
    def first_capture_group
      '\1'
    end
  end
end
<commit_msg>refactor of change method so that pattern and replacement are easier to compare<commit_after>

module Fedora2To3PidRenamer::Manipulator
  class Base
    attr_reader :source, :config
    
    def self.output_for(*args)
      manipulator = new(*args)
      manipulator.run
      manipulator.output
    end
    
    def initialize(source, config)
      @source = source
      @config = config
    end
    
    def run
      raise 'run must be defined in sub-classes'
    end
    
    def output
      raise 'output must be defined in sub-classes'
    end
    
    private
    def change(text, before, after)
      pattern = Regexp.new("changeme:#{before}(#{end_of_string_or_non_word})")      
      replacement = "#{changeme_replacement}:#{after}#{first_capture_group}"     
      text.gsub! pattern, replacement
    end
    
    def end_of_string_or_non_word 
      '$|\W'
    end
    
    def first_capture_group
      '\1'
    end
    
    def changeme_replacement
      config.changeme_replacement
    end
  end
end

{'fraction_non_alphanumeric': 0.07664422578974625, 'fraction_numerical': 0.0031071983428275505, 'mean_word_length': 2.193388429752066, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5893895', 'n_tokens_mistral': 610, 'n_tokens_neox': 617, 'n_words': 151}