Sha256: c73f1faa66bd7fd93ed2c1cf8d39ea35d52c3264380b13bd00e961aa766e9004
Contents?: true
Size: 975 Bytes
Versions: 2
Compression:
Stored size: 975 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, 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tracking_number-0.9.1 | lib/tracking_number.rb |
tracking_number-0.9.0 | lib/tracking_number.rb |