tracking_number 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/data/couriers/fedex.json +6 -4
- data/lib/data/couriers/ontrac.json +2 -2
- data/lib/data/couriers/usps.json +1 -0
- data/lib/tracking_number/base.rb +21 -1
- data/lib/tracking_number/unknown.rb +12 -0
- data/lib/tracking_number/version.rb +1 -1
- data/lib/tracking_number.rb +6 -9
- data/test/test_helper.rb +2 -2
- data/test/tracking_number_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 223298ed208018a34846ad4ecad1c92cca231fd9fba0e323097ef9b5b6fd16c5
|
4
|
+
data.tar.gz: ffbc69fe1a53b1c88b8d3c4602fe50d2e9ecb8116e391a196658fa53fafa91c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b47d582e0c50e0d4be14bf7c462b1f90b8b8d9a6406f209c05344b9e4b73c958cc75577d3054f56549e953d4ac75e4a886d4f6257315c6ad80802edfa90bbdb
|
7
|
+
data.tar.gz: b404e9f543ef4cb52471dd1ee1f0bdad9f77c62c56f70fcd1e17dfb89e3a5d529c64109510bc40ccb12d66f07fd84b3a75dff06cb27e83b659d35223a0e8fae9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
tracking_number changelog
|
2
2
|
|
3
|
+
# [1.5.0](https://github.com/jkeen/tracking_number/compare/v1.4.1...v1.5.0) (2023-08-14)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* include partnership indicator in inspect ([834a8c4](https://github.com/jkeen/tracking_number/commit/834a8c461ef7c58bff9e1e3ea43e65f6d11c3897))
|
9
|
+
* update to tracking_number_data 1.6.0 ([6c6293e](https://github.com/jkeen/tracking_number/commit/6c6293edc31de905163d0cee2a76e5b0e27c5f62))
|
10
|
+
|
3
11
|
## [1.4.1](https://github.com/jkeen/tracking_number/compare/v1.4.0...v1.4.1) (2023-05-19)
|
4
12
|
|
5
13
|
# [1.4.0](https://github.com/jkeen/tracking_number/compare/v1.3.5...v1.4.0) (2023-05-15)
|
@@ -99,7 +99,7 @@
|
|
99
99
|
")?",
|
100
100
|
"(?<SerialNumber>",
|
101
101
|
"(?<SCNC>([0-9]\\s*){2})",
|
102
|
-
"(?<ServiceType>
|
102
|
+
"(?<ServiceType>2\\s*9\\s*)",
|
103
103
|
"(?<ShipperId>([0-9]\\s*){8})",
|
104
104
|
"(?<PackageId>([0-9]\\s*){11}|([0-9]\\s*){7})",
|
105
105
|
")",
|
@@ -146,9 +146,11 @@
|
|
146
146
|
],
|
147
147
|
"invalid": [
|
148
148
|
"9261292700768711948020",
|
149
|
-
"
|
150
|
-
"420
|
151
|
-
"
|
149
|
+
"92001903060085300042901077",
|
150
|
+
"420 11213 61290983497923666231",
|
151
|
+
"92 6129098349792366623 5",
|
152
|
+
"9400 1112 0108 0805 4830 16",
|
153
|
+
"9361 2898 7870 0317 6337 95"
|
152
154
|
]
|
153
155
|
}
|
154
156
|
},
|
@@ -19,7 +19,7 @@
|
|
19
19
|
}
|
20
20
|
}
|
21
21
|
},
|
22
|
-
"tracking_url": "http://www.ontrac.com/
|
22
|
+
"tracking_url": "http://www.ontrac.com/tracking/?number=%s",
|
23
23
|
"test_numbers": {
|
24
24
|
"valid": [
|
25
25
|
"C11031500001879",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
}
|
53
53
|
}
|
54
54
|
},
|
55
|
-
"tracking_url": "http://www.ontrac.com/
|
55
|
+
"tracking_url": "http://www.ontrac.com/tracking/?number=%s",
|
56
56
|
"test_numbers": {
|
57
57
|
"valid": [
|
58
58
|
"D10011354453707",
|
data/lib/data/couriers/usps.json
CHANGED
data/lib/tracking_number/base.rb
CHANGED
@@ -97,12 +97,31 @@ module TrackingNumber
|
|
97
97
|
TrackingNumber::ChecksumValidations.send(method_name, serial_number, check_digit, checksum_info)
|
98
98
|
end
|
99
99
|
|
100
|
+
def checksum?
|
101
|
+
!!self.class.const_get(:VALIDATION)[:checksum]
|
102
|
+
end
|
103
|
+
|
104
|
+
LENGTH_WEIGHT = 0.1
|
105
|
+
CHECKSUM_WEIGHT = 5.0
|
106
|
+
|
107
|
+
def confidence
|
108
|
+
(checksum? ? CHECKSUM_WEIGHT : 0) + tracking_number.length * LENGTH_WEIGHT
|
109
|
+
end
|
110
|
+
|
100
111
|
def to_s
|
101
112
|
tracking_number
|
102
113
|
end
|
103
114
|
|
104
115
|
def inspect
|
105
|
-
format('#<%s:%#0x %s>', self.class.to_s, object_id, tracking_number)
|
116
|
+
format('#<%s:%#0x %s%s>', self.class.to_s, object_id, tracking_number, partnership_inspect)
|
117
|
+
end
|
118
|
+
|
119
|
+
def partnership_inspect
|
120
|
+
if shipper? ^ carrier?
|
121
|
+
' (partnership)'
|
122
|
+
else
|
123
|
+
''
|
124
|
+
end
|
106
125
|
end
|
107
126
|
|
108
127
|
def info
|
@@ -169,6 +188,7 @@ module TrackingNumber
|
|
169
188
|
return unless (partner_tn = find_matching_partner)
|
170
189
|
|
171
190
|
possible_twin = partner_tn.send(:find_matching_partner)
|
191
|
+
|
172
192
|
if possible_twin.instance_of?(self.class) && possible_twin.tracking_number == tracking_number
|
173
193
|
partner_hash[partner_data[:partner_type].to_sym] = partner_tn
|
174
194
|
partner_hash[partner_tn.partner_data[:partner_type].to_sym] = self
|
data/lib/tracking_number.rb
CHANGED
@@ -39,16 +39,13 @@ module TrackingNumber
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.detect(tracking_number, match: :carrier)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
break
|
49
|
-
end
|
42
|
+
all_matches = search(tracking_number, match: match)
|
43
|
+
|
44
|
+
if all_matches.empty?
|
45
|
+
Unknown.new(tracking_number)
|
46
|
+
else
|
47
|
+
all_matches.max_by(&:confidence)
|
50
48
|
end
|
51
|
-
tn
|
52
49
|
end
|
53
50
|
|
54
51
|
def self.detect_all(tracking_number)
|
data/test/test_helper.rb
CHANGED
@@ -51,9 +51,9 @@ class Minitest::Test
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def should_fail_on_check_digit_changes(valid_number)
|
54
|
-
digits = valid_number.gsub(/\s/, "").chars.to_a
|
54
|
+
digits = valid_number.gsub(/\s/, "").chars.compact.to_a
|
55
55
|
last = digits.pop.to_i
|
56
|
-
digits << (last
|
56
|
+
digits << (last <= 2 ? last + 3 : last - 3).to_s
|
57
57
|
invalid_number = digits.join
|
58
58
|
t = TrackingNumber.new(invalid_number)
|
59
59
|
assert !t.valid?, "#{invalid_number} reported as a valid #{t.class}, and it shouldn't be"
|
@@ -200,7 +200,7 @@ class TrackingNumberTest < Minitest::Test
|
|
200
200
|
|
201
201
|
context "searching numbers that have partners" do
|
202
202
|
partnership_number = "420 11213 92 6129098349792366623 8"
|
203
|
-
single_number = "
|
203
|
+
single_number = "92001903060085300042901077"
|
204
204
|
|
205
205
|
search_string = ["number that matches two services", partnership_number, " number that matches only one: ", single_number, "let's see if that does it"].join(' ')
|
206
206
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tracking_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Keen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|