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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcd4cc3dc63f4c3c777b6fa47524189ac10d07b2b1257bbabb0642af66e2fd9c
4
- data.tar.gz: 915ef1d78e0f7040b129d4fb5b3d830c4cf98a1e67901fe25ff9833821c6ef79
3
+ metadata.gz: 223298ed208018a34846ad4ecad1c92cca231fd9fba0e323097ef9b5b6fd16c5
4
+ data.tar.gz: ffbc69fe1a53b1c88b8d3c4602fe50d2e9ecb8116e391a196658fa53fafa91c0
5
5
  SHA512:
6
- metadata.gz: 2f49e3e02b3e22e8464c0b9b0f9c94c742a13518f6f4966bf0122bb5cb6283cbf59ddca06b2489456c61674864c43ffd6f9dd2df5da5ce7d44640ffa72acbe15
7
- data.tar.gz: 39d0d30954d429e86398d4558bfb001591356f5d6b47eb0295c2985f828482dff3dc64aedbc74dbb3f71bc39e6971a5303b3bd1e9c2a2b5be548ecb41ca6eb40
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>([0-9]\\s*){2})",
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
- "420 11213 6129098349792366623 8",
150
- "420 92 6129098349792366623 8",
151
- "11213 92 6129098349792366623 8"
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/trackingres.asp?tracking_number=%s",
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/trackingres.asp?tracking_number=%s",
55
+ "tracking_url": "http://www.ontrac.com/tracking/?number=%s",
56
56
  "test_numbers": {
57
57
  "valid": [
58
58
  "D10011354453707",
@@ -143,6 +143,7 @@
143
143
  "9505 5110 6960 5048 6006 24",
144
144
  "9101 1234 5678 9000 0000 13",
145
145
  "92748931507708513018050063",
146
+ "92001903060085300042901077",
146
147
  "9400 1112 0108 0805 4830 16",
147
148
  "9361 2898 7870 0317 6337 95",
148
149
  "9405803699300124287899"
@@ -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
@@ -22,6 +22,18 @@ module TrackingNumber
22
22
  false
23
23
  end
24
24
 
25
+ def shipper?
26
+ false
27
+ end
28
+
29
+ def carrier?
30
+ false
31
+ end
32
+
33
+ def partnership?
34
+ false
35
+ end
36
+
25
37
  def decode
26
38
  {}
27
39
  end
@@ -1,3 +1,3 @@
1
1
  module TrackingNumber
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -39,16 +39,13 @@ module TrackingNumber
39
39
  end
40
40
 
41
41
  def self.detect(tracking_number, match: :carrier)
42
- tn = nil
43
- (TYPES + [Unknown]).each do |test_klass|
44
- tn = test_klass.new(tracking_number)
45
- if tn.valid? && (!match || match == :all)
46
- break
47
- elsif tn.valid? && tn.send("#{match}?")
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 < 2 ? last + 3 : last - 3).to_s
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 = "0307 1790 0005 2348 3741"
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.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-05-19 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport