Module: Trackerific

Defined in:
lib/trackerific.rb,
lib/ups.rb,
lib/usps.rb,
lib/fedex.rb,
lib/trackerific_event.rb,
lib/trackerific_details.rb

Overview

Trackerific is a UPS, FedEx and USPS tracking provider.

Defined Under Namespace

Classes: Base, Details, Error, Event, FedEx, UPS, USPS

Instance Method Summary (collapse)

Instance Method Details

- (Trackerific::Base) tracking_service(package_id)

Checks a string for a valid package tracking service

Examples:

Find out which service provider will track a valid FedEx number

include Trackerific
tracking_service "183689015000001" # => Trackerific::FedEx

Parameters:

  • package_id (String)

    the package identifier

Returns:

  • (Trackerific::Base)

    the Trackerific class that can track the given package id, or nil if none found.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trackerific.rb', line 77

def tracking_service(package_id)
  case package_id
    when /^.Z/, /^[HK].{10}$/ then Trackerific::UPS
    when /^96.{20}$/ then Trackerific::FedEx
    else case package_id.length
      when 13, 20, 22, 30 then Trackerific::USPS
      when 12, 15, 19 then Trackerific::FedEx
      else nil
    end
  end
end