barcodevalidation 0.0.3 → 0.0.4
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/barcodevalidation.rb +4 -5
- data/lib/barcodevalidation/version.rb +1 -1
- data/test/test_barcodevalidation.rb +2 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c72c46bf313a6a31fa50ae03db6897304cf6faca
|
4
|
+
data.tar.gz: c1a2eb265bdaefb33517c456321b8a7f9680cf0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc2e3eaeea800512b9ae6762743805f9012fc074faba3ee4f1c0c1531b973c7fd06a1594f7f9cef4b9396700c98fef562a18b343a6f9e7714ae19e7359fdccb
|
7
|
+
data.tar.gz: addc2a455b9f1527787d257a489c42a5840ab93202b96d065c1cc48c56d5096ebaefafb4074a3ad3ac8445bf16edfb664a805fb4c11299b9c93b67db33e79102
|
data/lib/barcodevalidation.rb
CHANGED
@@ -2,12 +2,11 @@ require "barcodevalidation/version"
|
|
2
2
|
|
3
3
|
module Barcodevalidation
|
4
4
|
def self.valid?(barcode)
|
5
|
-
|
5
|
+
barcode = barcode.to_s
|
6
|
+
return false unless [8, 10, 12, 13].include?(barcode.length)
|
6
7
|
|
7
|
-
parts = ('
|
8
|
-
return false unless [8, 10, 12, 13].include?(barcode.to_s.length)
|
8
|
+
parts = barcode.rjust(18, '0').chars.map(&:to_i)
|
9
9
|
checksum = parts.pop
|
10
|
-
parts
|
11
10
|
|
12
11
|
calculated_checksum = 0
|
13
12
|
parts.each_with_index do |part, index|
|
@@ -18,7 +17,7 @@ module Barcodevalidation
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
calculated_checksum =
|
20
|
+
calculated_checksum = ((calculated_checksum.to_f / 10).ceil * 10) - calculated_checksum
|
22
21
|
checksum == calculated_checksum
|
23
22
|
|
24
23
|
rescue ArgumentError
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodevalidation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Harper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,11 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.1
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Barcode validation library
|
111
111
|
test_files:
|
112
112
|
- test/minitest_helper.rb
|
113
113
|
- test/test_barcodevalidation.rb
|
114
|
-
has_rdoc:
|