Posts tagged with #tracking numbers

Dev Stuff

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
2
3
4
5
6
7
  t = TrackingNumber.new("MYSTERY_TRACKING_NUMBER")
  t.valid? #=> false
  t.carrier #=> :unknown

  t = TrackingNumber.new("1Z879E930346834440")
  t.valid? #=> true
  t.carrier #=> :ups

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

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

  TrackingNumber.search(text)

  #=> [TrackingNumber, TrackingNumber]

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

Ruby Gem active
Tracking Number