container6346 0.0.1 → 0.0.2
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 +4 -4
- data/lib/container6346.rb +12 -64
- 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: 90240bbc312d1409b952d439e64a1ab73b6bd537fcd571f47c916c615f6a373e
|
4
|
+
data.tar.gz: 9832e0497fb9404be4b4ed17d9da46d1edf88b66efe6becb714008ae526512b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1e2ea8ffc3c62b273e2aa4abbe74053b45ec24f06a83bfe04b8fb9e2f50af59f6b5d0c2f569d0ea379c5a2285240d7ac9b4ce700bc971d5a0ffa08ba7dfb94
|
7
|
+
data.tar.gz: 446816c665c2212f7cb696c7e9cfe7f389061a51366a0fecb4446b3a4db7869c552467eb0b3c559c0bfe16b6804caeed3e51426bd66f58a3a2100daff0a713fe
|
data/lib/container6346.rb
CHANGED
@@ -1,36 +1,16 @@
|
|
1
1
|
module Container6346
|
2
2
|
|
3
3
|
MAPPING = {
|
4
|
-
"A" => 10,
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"H" => 18,
|
12
|
-
"I" => 19,
|
13
|
-
"J" => 20,
|
14
|
-
"K" => 21,
|
15
|
-
"L" => 23,
|
16
|
-
"M" => 24,
|
17
|
-
"N" => 25,
|
18
|
-
"O" => 26,
|
19
|
-
"P" => 27,
|
20
|
-
"Q" => 28,
|
21
|
-
"R" => 29,
|
22
|
-
"S" => 30,
|
23
|
-
"T" => 31,
|
24
|
-
"U" => 32,
|
25
|
-
"V" => 34,
|
26
|
-
"W" => 35,
|
27
|
-
"X" => 36,
|
28
|
-
"Y" => 37,
|
29
|
-
"Z" => 38
|
4
|
+
"A" => 10, "B" => 12, "C" => 13, "D" => 14,
|
5
|
+
"E" => 15, "F" => 16, "G" => 17, "H" => 18,
|
6
|
+
"I" => 19, "J" => 20, "K" => 21, "L" => 23,
|
7
|
+
"M" => 24, "N" => 25, "O" => 26, "P" => 27,
|
8
|
+
"Q" => 28, "R" => 29, "S" => 30, "T" => 31,
|
9
|
+
"U" => 32, "V" => 34, "W" => 35, "X" => 36,
|
10
|
+
"Y" => 37, "Z" => 38
|
30
11
|
}
|
31
12
|
|
32
|
-
|
33
|
-
def self.validate_container?(container)
|
13
|
+
def self.validate_container?(container) # ie: "XXXU1234567"
|
34
14
|
regex = /^[a-z]{3}[ujz]\d{7}/i
|
35
15
|
if not regex.match(container)
|
36
16
|
raise "Invalid container #{container}"
|
@@ -44,54 +24,22 @@ module Container6346
|
|
44
24
|
self.validate?(owner_code, category_identifier, serial_number, check_digit)
|
45
25
|
end
|
46
26
|
|
47
|
-
|
48
|
-
|
27
|
+
# https://en.wikipedia.org/wiki/ISO_6346#Identification_system
|
49
28
|
def self.validate?(owner_code, category_identifier, serial_number, check_digit)
|
50
|
-
if not owner_code.length == 3
|
51
|
-
raise "Invalid owner code"
|
52
|
-
end
|
53
|
-
owner_code
|
54
|
-
if not category_identifier.length == 1 # todo ...
|
55
|
-
raise "Invalid category identifier "
|
56
|
-
end
|
57
|
-
if not self.only_digits?(serial_number) or serial_number.length != 6
|
58
|
-
raise 'Invalid serial number'
|
59
|
-
end
|
60
|
-
if not self.only_digits?(check_digit) or check_digit.length != 1
|
61
|
-
raise 'Invalid Check digit'
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
29
|
list = []
|
66
30
|
|
67
|
-
owner_code.each_char
|
68
|
-
list.push(MAPPING[c])
|
69
|
-
end
|
70
|
-
|
31
|
+
owner_code.each_char {|c| list.push(MAPPING[c])}
|
71
32
|
list.push(MAPPING[category_identifier])
|
72
|
-
|
73
|
-
serial_number.each_char do |c|
|
74
|
-
list.push(c.to_i)
|
75
|
-
end
|
76
|
-
|
33
|
+
serial_number.each_char {|c| list.push(c.to_i)}
|
77
34
|
|
78
35
|
sum = 0
|
79
|
-
list.each_with_index
|
80
|
-
sum += value * 2**index
|
81
|
-
end
|
36
|
+
list.each_with_index {|value, index| sum += value * 2**index}
|
82
37
|
|
83
38
|
generated_digit = sum - ((sum/11)*11)
|
84
39
|
if generated_digit == 10 then
|
85
40
|
generated_digit = 0
|
86
41
|
end
|
87
42
|
|
88
|
-
|
89
43
|
check_digit == "#{generated_digit}"
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
def self.only_digits?(string)
|
95
|
-
string !~ /\D/
|
96
44
|
end
|
97
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: container6346
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bimmy
|
@@ -17,7 +17,7 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/container6346.rb
|
20
|
-
homepage:
|
20
|
+
homepage: https://github.com/bitmold/Container6346
|
21
21
|
licenses: []
|
22
22
|
metadata: {}
|
23
23
|
post_install_message:
|