Sha256: c1d010e81fde30341ea838f06cd2e7f20e8a5e72e479dd65e0e07b65ac894259

Contents?: true

Size: 418 Bytes

Versions: 4

Compression:

Stored size: 418 Bytes

Contents

class TrackingNumber
  class DHL < Base
    SEARCH_PATTERN = /(\b([0-9]\s*){11,11}\b)/
    VERIFY_PATTERN = /^([0-9]{10,10})([0-9])$/
    def carrier
      :dhl
    end

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

    def valid_checksum?
      # standard mod 7 check
      sequence, check_digit = matches
      return true if sequence.to_i % 7 == check_digit.to_i
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tracking_number-0.4.0 lib/dhl.rb
tracking_number-0.3.2 lib/dhl.rb
tracking_number-0.3.1 lib/dhl.rb
tracking_number-0.3.0 lib/dhl.rb