<commit_before>module Tagomatic

  class TagCleaner

    def process(tags_hash)
      artist = tags_hash['a']
      artist = Regexp.compile("[ -]*#{Regexp.escape(artist)}[ -]*", Regexp::IGNORECASE) if artist

      album = tags_hash['b']
      album = album.sub(artist, '') if artist and album
      tags_hash['b'] = album unless album.nil? or album.empty?

      album = Regexp.compile("[ -]*#{Regexp.escape(album)}[ -]*", Regexp::IGNORECASE) if album

      title = tags_hash['t']
      title = title.sub(artist, '') if artist and title
      title = title.sub(album, '') if album and title
      tags_hash['t'] = title unless title.nil? or title.empty?

      tags_hash
    end

  end<commit_msg>Refactored TagCleaner class a little bit.<commit_after>module Tagomatic

  class TagCleaner

    def process(tags_hash)
      @tags = tags_hash

      artist = get_regexp_for('a')
      replace_regexp_in_tag artist, 'b'
      replace_regexp_in_tag artist, 't'

      album = get_regexp_for('b')
      replace_regexp_in_tag album, 't'

      @tags
    end

    def get_regexp_for(tag_id)
      value = @tags[tag_id]
      return nil unless value
      Regexp.compile("[ -]*#{Regexp.escape(value)}[ -]*", Regexp::IGNORECASE)
    end

    def replace_regexp_in_tag(regexp, tag_id)
      value = @tags[tag_id]
      value = value.sub(regexp, '') if value
      @tags[tag_id] = value unless value.nil? or value.empty?
    end

  end
{'fraction_non_alphanumeric': 0.12833099579242638, 'fraction_numerical': 0.0, 'mean_word_length': 2.9749303621169916, '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': '1435964', 'n_tokens_mistral': 500, 'n_tokens_neox': 490, 'n_words': 113}