container_number_validator 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34b22ae8669d103abab55fef56b4e8fd1a20e2bb
|
|
4
|
+
data.tar.gz: d8082766414fb2c9f75b9f57efbdf9860474447a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cffdd72a4f72dd8b10c889d1e5da3b59ba3dc6dee80b28b8e4666279a878b6ec85dbce4a4d9f2641b0305b11a94403c88af0d6504ecd8841a83fdf6f8f109034
|
|
7
|
+
data.tar.gz: 8dc11368b99af48e3de041e9b79ba54409ccc09f6241c40fb4dd56bd4d52d6f7cac2697509c0573ccc5743fb4a845632a5e21819d781a6ca7130945b55418cc6
|
|
@@ -54,11 +54,14 @@ module ContainerNumberValidator
|
|
|
54
54
|
weights[i] = digit.to_i * WEIGHTS[i].to_i
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
weights.reduce(:+) % 11
|
|
57
|
+
checksum = weights.reduce(:+) % 11
|
|
58
|
+
|
|
59
|
+
# When checksum equals 10 the last digit will equal 0
|
|
60
|
+
checksum == 10 ? 0 : checksum
|
|
58
61
|
end
|
|
59
62
|
module_function :calculate_checksum
|
|
60
63
|
|
|
61
64
|
end
|
|
62
65
|
|
|
63
66
|
require 'container_number_validator/version'
|
|
64
|
-
require 'container_number_validator/adapters/active_model' if defined?(ActiveModel)
|
|
67
|
+
require 'container_number_validator/adapters/active_model' if defined?(ActiveModel)
|
|
@@ -43,4 +43,21 @@ describe ContainerNumberValidator do
|
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
|
+
|
|
47
|
+
context 'passes on numbers with checksum of 10' do
|
|
48
|
+
%w{ZIMU1380440 fciu8384900}.each do |value|
|
|
49
|
+
it "with #{value }" do
|
|
50
|
+
expect(subject.validate('ZIMU1380440')).to be_true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'Comprehensive test with real life examples' do
|
|
56
|
+
IO.readlines('./spec/fixtures/container_numbers.txt').each do |value|
|
|
57
|
+
it "passes with #{value}" do
|
|
58
|
+
value.strip!
|
|
59
|
+
expect(subject.validate(value)).to be_true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
46
63
|
end
|