<commit_before>require "nagios_config"

module Html2nagioscontacts
  class Nagios
    DISALLOWED_CHARS = /[\\~!$%&*#"|'<>?,()={}\^]/i
    DISALLOWED_CHARS_NAME = /\W/i

    # returns a NagiosConfig::Config object
    def create_contacts(source)
      builder = NagiosConfig::Builder.new
      source.each do |c|
        builder.define "Contact" do |contact|
          contact.use = 'generic-contact'
          contact.contact_name = c['name']
          contact.alias = c['alias']
          contact.email = c['email']
        end
      end
      builder.root
    end

    # Make sure there are no string literals which are forbidden in a nagios config object
    def prepare_source(source)
      source.each do |c|
        c['email'].gsub! DISALLOWED_CHARS, ''
        c['email'].gsub! /\s/, ''
        c['alias'] = c['name'].gsub DISALLOWED_CHARS, '_'
        c['name'] = c['alias'].gsub DISALLOWED_CHARS_NAME, ''
      end
      source
    end

    def contacts2string(contacts)
      output = <<-EOS
# This file is automatically generated by html2nagioscontacts
# Changes to this file will be overwritten
# Last update: #{Time.now.to_s}

      EOS
      output += NagiosConfig::Formater.new.format(contacts)
      output
    end

  end
end<commit_msg>Fixed Typo<commit_after>require "nagios_config"

module Html2nagioscontacts
  class Nagios
    DISALLOWED_CHARS = /[\\~!$%&*#"|'<>?,()={}\^]/i
    DISALLOWED_CHARS_NAME = /\W/i

    # returns a NagiosConfig::Config object
    def create_contacts(source)
      builder = NagiosConfig::Builder.new
      source.each do |c|
        builder.define "contact" do |contact|
          contact.use = 'generic-contact'
          contact.contact_name = c['name']
          contact.alias = c['alias']
          contact.email = c['email']
        end
      end
      builder.root
    end

    # Make sure there are no string literals which are forbidden in a nagios config object
    def prepare_source(source)
      source.each do |c|
        c['email'].gsub! DISALLOWED_CHARS, ''
        c['email'].gsub! /\s/, ''
        c['alias'] = c['name'].gsub DISALLOWED_CHARS, '_'
        c['name'] = c['alias'].gsub DISALLOWED_CHARS_NAME, ''
      end
      source
    end

    def contacts2string(contacts)
      output = <<-EOS
# This file is automatically generated by html2nagioscontacts
# Changes to this file will be overwritten
# Last update: #{Time.now.to_s}

      EOS
      output += NagiosConfig::Formater.new.format(contacts)
      output
    end

  end
end
{'fraction_non_alphanumeric': 0.12305233719536555, 'fraction_numerical': 0.0023971234518577705, 'mean_word_length': 2.5568181818181817, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '7228145', 'n_tokens_mistral': 829, 'n_tokens_neox': 810, 'n_words': 196}