<commit_before># Identify if tracking numbers are valid, and which service they belong to

# Information on validating tracking numbers found here:
# http://answers.google.com/answers/threadview/id/207899.html

require 'base'
require 'usps'
require 'fedex'
require 'ups'
require 'dhl'
require 'ontrac'

class TrackingNumber
  TYPES = [UPS, FedExExpress, FedExGround, FedExGround18, FedExGround96, USPS91, USPS20, USPS13, DHL, OnTrac]

  def self.search(body)
    TYPES.collect { |type| type.search(body) }.flatten
  end

  def self.detect(tracking_number)
    detected = TYPES.collect do |test|
      t = test.new(tracking_number)
      t if t.valid?
    end
    found = detected.compact.first

    return found if found
    return Unknown.new(tracking_number)
  end

  def self.new(tracking_number)<commit_msg>when creating a new TrackingNumber enumerate until a valid class is found - no point in checking the other classes if one has already been found<commit_after># Identify if tracking numbers are valid, and which service they belong to

# Information on validating tracking numbers found here:
# http://answers.google.com/answers/threadview/id/207899.html

require 'base'
require 'usps'
require 'fedex'
require 'ups'
require 'dhl'
require 'ontrac'

class TrackingNumber
  TYPES = [UPS, FedExExpress, FedExGround, FedExGround18, FedExGround96, USPS91, USPS20, USPS13, DHL, OnTrac]

  def self.search(body)
    TYPES.collect { |type| type.search(body) }.flatten
  end

  def self.detect(tracking_number)
    tn = nil
    for test_klass in (TYPES+[Unknown])
      tn = test_klass.new(tracking_number)
      break if tn.valid?
    end
    return tn
  end

  def self.new(tracking_number)
{'fraction_non_alphanumeric': 0.08811354228267297, 'fraction_numerical': 0.018923713778829097, 'mean_word_length': 4.142857142857143, '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': '7622253', 'n_tokens_mistral': 592, 'n_tokens_neox': 558, 'n_words': 171}