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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6cc354ab8bec0969d5ee99653b5ba5f84022c0b04246d3167f29fa3c090ba6e
4
- data.tar.gz: 83cb2e829315d7efd4b7a541e6d82b36965b99c0502b70cd071e3c2c818b1a9d
3
+ metadata.gz: 9afbba036e56d456901b4dcd0c3b0ee1626e104113831edd5ae8f63a3cfdae7c
4
+ data.tar.gz: 000e731bcda5a5729fda6171f9bcb2c409d09054dd15b191cb7c57e931be7d0d
5
5
  SHA512:
6
- metadata.gz: 87cbfb9075a3afa2d5092ec7ace7a4403c9e33729cbe8e42ea36dd7b59464ca496495e2ec459ef1f8857fccafb0212f8e4177e71bbac82183913f9eceb52ddf8
7
- data.tar.gz: 7e52110a5825a5a42c81ff03c9ef1b8e85b9e5cda23be4e56ba23b05deed17eb23aae7de6b568f89b82052e5c83b6fde7555b48dc7b331e1f5cf7b73fc66f6aa
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
@@ -1,3 +1,3 @@
1
1
  module TrackingNumber
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracking_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Keen