<commit_before>class HTMLEntities
  InstructionError = Class.new(RuntimeError)

  class Encoder #:nodoc:
    INSTRUCTIONS = [:basic, :named, :decimal, :hexadecimal]

    def initialize(flavor, instructions)
      @flavor = flavor
      instructions << :basic if (instructions.empty?)
      validate_instructions(instructions)
      build_basic_entity_encoder(instructions)
      build_extended_entity_encoder(instructions)
    end

    def encode(source)
      string = source.to_s.dup
      string.gsub!(basic_entity_regexp){ encode_basic($&) }
      string.gsub!(extended_entity_regexp){ encode_extended($&) }<commit_msg>Clearer and avoids unnecessary mutation.<commit_after>class HTMLEntities
  InstructionError = Class.new(RuntimeError)

  class Encoder #:nodoc:
    INSTRUCTIONS = [:basic, :named, :decimal, :hexadecimal]

    def initialize(flavor, instructions)
      @flavor = flavor
      instructions = [:basic] if instructions.empty?
      validate_instructions(instructions)
      build_basic_entity_encoder(instructions)
      build_extended_entity_encoder(instructions)
    end

    def encode(source)
      string = source.to_s.dup
      string.gsub!(basic_entity_regexp){ encode_basic($&) }
      string.gsub!(extended_entity_regexp){ encode_extended($&) }
{'fraction_non_alphanumeric': 0.09905660377358491, 'fraction_numerical': 0.0, 'mean_word_length': 4.348739495798319, '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': '6689824', 'n_tokens_mistral': 398, 'n_tokens_neox': 385, 'n_words': 70}