<commit_before>require 'peoplefinder'

class Peoplefinder::EmailAddress < Mail::Address
  VALID_EMAIL_PATTERN = /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/

  def initialize(string)
    return false unless string =~ VALID_EMAIL_PATTERN
    super
  end

  def valid_domain?
    valid_login_domains.include?(domain)
  end

  def valid_format?
    address && address.match(VALID_EMAIL_PATTERN)
  end

  def valid_address?
    address ? (valid_format? && valid_domain?) : false
  end

  def inferred_last_name
    if multipart_local?
      local.split('.')[1]
    else
      local.split('.')[0]
    end
  end

  def inferred_first_name
    local.split('.')[0] if multipart_local?
  end

  def multipart_local?
    local.split('.').length > 1
  end

private

  def valid_login_domains
    Rails.configuration.valid_login_domains
  rescue
    []
  end
end
<commit_msg>Ensure 100% test coverage on travis<commit_after>require 'peoplefinder'

class Peoplefinder::EmailAddress < Mail::Address
  VALID_EMAIL_PATTERN = /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/

  def initialize(string)
    return false unless string =~ VALID_EMAIL_PATTERN
    super
  end

  def valid_domain?
    valid_login_domains.include?(domain)
  end

  def valid_format?
    address && address.match(VALID_EMAIL_PATTERN)
  end

  def valid_address?
    address ? (valid_format? && valid_domain?) : false
  end

  def inferred_last_name
    if multipart_local?
      local.split('.')[1]
    else
      local.split('.')[0]
    end
  end

  def inferred_first_name
    local.split('.')[0] if multipart_local?
  end

  def multipart_local?
    local.split('.').length > 1
  end

private

  def valid_login_domains
    Rails.configuration.try(:valid_login_domains) || []
  end
end

{'fraction_non_alphanumeric': 0.12200684150513112, 'fraction_numerical': 0.010832383124287344, 'mean_word_length': 3.2804878048780486, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7378114', 'n_tokens_mistral': 665, 'n_tokens_neox': 621, 'n_words': 122}