I had this idea for (yet another) package tracking web service, and in the process of making it I got really into tracking numbers.

So I wrote this gem, which made it possible to detect and identify tracking numbers, and to tell if it’s even valid.

1
2t = TrackingNumber.new("MYSTERY_TRACKING_NUMBER")
3t.valid? #=> false
4t.carrier #=> :unknown
5
6t = TrackingNumber.new("1Z879E930346834440")
7t.valid? #=> true
8t.carrier #=> :ups

Also, can take a block of text and find all the valid tracking numbers within it.

 1
 2text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit,
 3sed do eiusmod tempor incididunt ut labore et dolore
 4magna aliqua. Ut enim ad minim veniam, 1Z879E930346834440
 5nostrud exercitation ullamco laboris nisi ut aliquip ex
 6ea commodo consequat. Duis aute 9611020987654312345672 dolor
 7in reprehenderit in voluptate velit esse cillum dolore eu
 8fugiat nulla pariatur. Excepteur sint occaecat cupidatat
 9non proident, sunt in culpa qui officia deserunt mollit
10anim id est laborum."
11
12TrackingNumber.search(text)
13
14#=> [TrackingNumber, TrackingNumber]
15

There’s a lot more information baked into a tracking number than you’d think.

Start a discussion