tracking_number 0.8.0 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/tracking_number/usps.rb +6 -6
- data/lib/tracking_number/version.rb +1 -1
- data/test/usps_tracking_number_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a1676f2d893d95708b47cd37c7458b822458ea0
|
4
|
+
data.tar.gz: 63f9151dd0ba5e99c598414479196002e8cc55b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 851d1e6a199f751c90f56c0460cfbcf6a158c78d4de2ba265d3d981cd2580e90bde2b4f792631d0b72df7135cc6c7a4edb53547a3797fa26719e1841d7bc0760
|
7
|
+
data.tar.gz: 5ec61555863d9eb6df8df98375a0657d0c8a7b892f1f053c989211d5152c0175b2f9f4e78407d3a77dafcd73a7cece76223405b360b63c31c0608ef43859f76a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.5
|
data/lib/tracking_number/usps.rb
CHANGED
@@ -6,13 +6,13 @@ module TrackingNumber
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class USPS91 < USPS
|
9
|
-
SEARCH_PATTERN = [/(\b9\s*[
|
10
|
-
VERIFY_PATTERN = /^(9[
|
9
|
+
SEARCH_PATTERN = [/(\b9\s*[145]\s*(([0-9]\s*){20,20}\b))/, /(\b([0-9]\s*){20,20}\b)/]
|
10
|
+
VERIFY_PATTERN = /^(9[145][0-9]{19,19})([0-9])$/
|
11
11
|
|
12
12
|
# Sometimes these numbers will appear without the leading 91 or 94, though, so we need to account for that case
|
13
13
|
|
14
14
|
def decode
|
15
|
-
# Application ID: 91 or 94
|
15
|
+
# Application ID: 91 or 94 or 95
|
16
16
|
# Service Code: 2 Digits
|
17
17
|
# Mailer Id: 8 Digits
|
18
18
|
# Package Id: 9 Digits
|
@@ -27,7 +27,7 @@ module TrackingNumber
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def matches
|
30
|
-
if self.tracking_number =~ /^9[
|
30
|
+
if self.tracking_number =~ /^9[145]/
|
31
31
|
self.tracking_number.scan(VERIFY_PATTERN).flatten
|
32
32
|
else
|
33
33
|
"91#{self.tracking_number}".scan(VERIFY_PATTERN).flatten
|
@@ -35,7 +35,7 @@ module TrackingNumber
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def valid_checksum?
|
38
|
-
if self.tracking_number =~ /^9[
|
38
|
+
if self.tracking_number =~ /^9[145]/
|
39
39
|
return true if weighted_usps_checksum_valid?(tracking_number)
|
40
40
|
else
|
41
41
|
if weighted_usps_checksum_valid?("91#{self.tracking_number}")
|
@@ -146,4 +146,4 @@ module TrackingNumber
|
|
146
146
|
return check == check_digit
|
147
147
|
end
|
148
148
|
end
|
149
|
-
end
|
149
|
+
end
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class USPSTrackingNumberTest < Minitest::Test
|
4
4
|
context "a USPS tracking number" do
|
5
|
-
["9101 1234 5678 9000 0000 13", "7196 9010 7560 0307 7385", "9400 1112 0108 0805 4830 16"].each do |valid_number|
|
5
|
+
["9101 1234 5678 9000 0000 13", "7196 9010 7560 0307 7385", "9400 1112 0108 0805 4830 16", "9505 5110 6960 5048 6006 24"].each do |valid_number|
|
6
6
|
should "return usps with valid 22 digit number: #{valid_number}" do
|
7
7
|
should_be_valid_number(valid_number, TrackingNumber::USPS91, :usps)
|
8
8
|
end
|