Sha256: 74d02093321e65705ac831b7023f13966cf53b8618aadc5f9b41d4a0ca3cea0c
Contents?: true
Size: 997 Bytes
Versions: 2
Compression:
Stored size: 997 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, FedExSmartPost, FedExGround, FedExGround18, FedExGround96, USPS91, USPS20, USPS13, DHLExpress, DHLExpressAir, 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tracking_number-0.10.1 | lib/tracking_number.rb |
tracking_number-0.10.0 | lib/tracking_number.rb |