Sha256: e4849632bb311e7aeb6c69c80a26db20e056a62b6fb38b2a7f51015caec9ec14

Contents?: true

Size: 959 Bytes

Versions: 5

Compression:

Stored size: 959 Bytes

Contents

# 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 'tracking_number/base'
require 'tracking_number/usps'
require 'tracking_number/fedex'
require 'tracking_number/ups'
require 'tracking_number/dhl'
require 'tracking_number/ontrac'

if defined?(ActiveModel::EachValidator)
  require 'tracking_number/active_model_validator'
end

module 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)
    self.detect(tracking_number)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tracking_number-0.8.6 lib/tracking_number.rb
tracking_number-0.8.5 lib/tracking_number.rb
tracking_number-0.8.0 lib/tracking_number.rb
tracking_number-0.7.0 lib/tracking_number.rb
tracking_number-0.6.0 lib/tracking_number.rb