tracking_number 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tracking_number/checksum_validations.rb +26 -0
- data/lib/tracking_number/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9afbba036e56d456901b4dcd0c3b0ee1626e104113831edd5ae8f63a3cfdae7c
|
4
|
+
data.tar.gz: 000e731bcda5a5729fda6171f9bcb2c409d09054dd15b191cb7c57e931be7d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e098f919430d362155a398423664a414bd81673c4f658916f3155569ade1e0d257bbc91a5df591567d87045c100df4eeeadf900209c0ef0a815170ee0c86b569
|
7
|
+
data.tar.gz: dec2cba1b5a505c3fa25e93c63a90e0081333366260a8162da8efd6b31dfe63d54bbacda3b1ac91ddb808e62fc175703487b98eedc4f4ab31c4d04efb961c8a2
|
@@ -60,6 +60,32 @@ module TrackingNumber
|
|
60
60
|
# standard mod 7 check
|
61
61
|
return true if sequence.to_i % 7 == check_digit.to_i
|
62
62
|
end
|
63
|
+
|
64
|
+
def validates_mod_37_36?(sequence, check_digit, extras = {})
|
65
|
+
# From https://esolutions.dpd.com/dokumente/DPD_Parcel_Label_Specification_2.4.1_EN.pdf
|
66
|
+
|
67
|
+
mod = 36
|
68
|
+
weights = {A: 10, B: 11, C: 12, D: 13, E: 14, F: 15, G: 16, H: 17, I: 18, J: 19, K: 20, L: 21, M: 22, N: 23, O: 24, P: 25, Q: 26, R: 27, S: 28, T: 29, U: 30, V: 31, W: 32, X: 33, Y: 34, Z: 35}
|
69
|
+
cd = mod
|
70
|
+
sequence.chars.to_a.each do |char, i|
|
71
|
+
val = (char =~ /[A-Za-z]/ ? weights[char.to_sym] : char.to_i)
|
72
|
+
|
73
|
+
cd = val + cd
|
74
|
+
cd = cd - mod if cd > mod
|
75
|
+
cd = cd * 2
|
76
|
+
cd = cd - (mod + 1) if cd > mod
|
77
|
+
end
|
78
|
+
|
79
|
+
cd = (mod + 1) - cd
|
80
|
+
cd = 0 if cd == mod
|
81
|
+
computed = if cd >= 10
|
82
|
+
weights.find { |a, val| val == cd }[0].to_s
|
83
|
+
else
|
84
|
+
cd.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
computed == check_digit
|
88
|
+
end
|
63
89
|
end
|
64
90
|
end
|
65
91
|
end
|