Class: TrackingNumber::FedExGround

Inherits:
FedEx
  • Object
show all
Defined in:
lib/tracking_number/fedex.rb

Constant Summary collapse

SEARCH_PATTERN =
/(\b([0-9]\s*){15,15}\b)/
VERIFY_PATTERN =
/^([0-9]{15,15})$/
LENGTH =
15

Instance Attribute Summary

Attributes inherited from Base

#original_number, #tracking_number

Instance Method Summary collapse

Methods inherited from FedEx

#carrier

Methods inherited from Base

#decode, #initialize, #inspect, scan, search, #to_s, #valid?, #valid_format?

Constructor Details

This class inherits a constructor from TrackingNumber::Base

Instance Method Details

#matchesObject



77
78
79
# File 'lib/tracking_number/fedex.rb', line 77

def matches
  self.tracking_number.scan(VERIFY_PATTERN).flatten
end

#valid_checksum?Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tracking_number/fedex.rb', line 81

def valid_checksum?
  sequence = tracking_number.chars.to_a.map(&:to_i)
  check_digit = sequence.pop
  total = 0
  sequence.reverse.each_with_index do |x, i|
    x *= 3 if i.even?
    total += x
  end
  check = total % 10
  check = (10 - check) unless (check.zero?)
  return true if check == check_digit.to_i
end