<commit_before>module Faker
  class Internet < Base
    class << self

      def email(name = nil)
        [user_name(name), domain_name].join('@')
      end

      def free_email(name = nil)
        [user_name(name), fetch('internet.free_email')].join('@')
      end

      def safe_email(name = nil)
        [user_name(name), 'example.'+ sample(%w[org com net])].join('@')
      end

      def user_name(specifier = nil, separators = %w(. _))
        with_locale(:en) do
          if specifier.respond_to?(:scan)
            return specifier.scan(/\w+/).shuffle.join(sample(separators)).downcase
          elsif specifier.kind_of?(Integer)
            # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
            raise ArgumentError, "Given argument is too large" if specifier > 10**6
            tries = 0 # Don't try forever in case we get something like 1_000_000.
            begin
              result = user_name(nil, separators)
              tries += 1
            end while result.length < specifier && tries < 7
            return result * (specifier/result.length + 1) if specifier > 0
          elsif specifier.kind_of?(Range)
            tries = 0
            begin
              result = user_name(specifier.min, separators)
              tries += 1
            end while !specifier.include?(result.length) && tries < 7
            return result[0...specifier.max]
          end

          sample([
            Char.prepare(Name.first_name),
            [Name.first_name, Name.last_name].map{ |name|
              Char.prepare(name)
            }.join(sample(separators))
          ])
        end
      end

      def password(min_length = 8, max_length = 16, mix_case = true, special_chars = false)
        temp = Lorem.characters(min_length)
        diff_length = max_length - min_length
        if diff_length > 0
          diff_rand = rand(diff_length + 1)
          temp += Lorem.characters(diff_rand)
        end

        if mix_case
          temp.chars.each_with_index do |char, index|
            temp[index] = char.upcase if index.even?
          end
        end

        if special_chars
          chars = %w(! @ # $ % ^ & *)
          rand(min_length).times do |i|
            temp[i] = chars[rand(chars.length)]
          end
        end

        temp
      end

      def domain_name
        with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
      end

      def fix_umlauts(string='')
        Char.fix_umlauts(string)
      end

      def domain_word
        return Char.prepare(Company.name.split(' ')[1]) if Config.locale == 'uk'
        Char.prepare(Company.name.split(' ').first)
      end

      def domain_suffix
        fetch('internet.domain_suffix')
      end
<commit_msg>Fix internet domain word (#957)<commit_after>module Faker
  class Internet < Base
    class << self

      def email(name = nil)
        [user_name(name), domain_name].join('@')
      end

      def free_email(name = nil)
        [user_name(name), fetch('internet.free_email')].join('@')
      end

      def safe_email(name = nil)
        [user_name(name), 'example.'+ sample(%w[org com net])].join('@')
      end

      def user_name(specifier = nil, separators = %w(. _))
        with_locale(:en) do
          if specifier.respond_to?(:scan)
            return specifier.scan(/\w+/).shuffle.join(sample(separators)).downcase
          elsif specifier.kind_of?(Integer)
            # If specifier is Integer and has large value, Argument error exception is raised to overcome memory full error
            raise ArgumentError, "Given argument is too large" if specifier > 10**6
            tries = 0 # Don't try forever in case we get something like 1_000_000.
            begin
              result = user_name(nil, separators)
              tries += 1
            end while result.length < specifier && tries < 7
            return result * (specifier/result.length + 1) if specifier > 0
          elsif specifier.kind_of?(Range)
            tries = 0
            begin
              result = user_name(specifier.min, separators)
              tries += 1
            end while !specifier.include?(result.length) && tries < 7
            return result[0...specifier.max]
          end

          sample([
            Char.prepare(Name.first_name),
            [Name.first_name, Name.last_name].map{ |name|
              Char.prepare(name)
            }.join(sample(separators))
          ])
        end
      end

      def password(min_length = 8, max_length = 16, mix_case = true, special_chars = false)
        temp = Lorem.characters(min_length)
        diff_length = max_length - min_length
        if diff_length > 0
          diff_rand = rand(diff_length + 1)
          temp += Lorem.characters(diff_rand)
        end

        if mix_case
          temp.chars.each_with_index do |char, index|
            temp[index] = char.upcase if index.even?
          end
        end

        if special_chars
          chars = %w(! @ # $ % ^ & *)
          rand(min_length).times do |i|
            temp[i] = chars[rand(chars.length)]
          end
        end

        temp
      end

      def domain_name
        with_locale(:en) { [Char.prepare(domain_word), domain_suffix].join('.') }
      end

      def fix_umlauts(string='')
        Char.fix_umlauts(string)
      end

      def domain_word
        with_locale(:en) { Char.prepare(Company.name.split(' ').first) }
      end

      def domain_suffix
        fetch('internet.domain_suffix')
      end

{'fraction_non_alphanumeric': 0.10583153347732181, 'fraction_numerical': 0.009359251259899209, 'mean_word_length': 1.8600102933607823, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '6848266', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1604, 'n_words': 399}