barcodevalidation 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 62d88d4ad5b5997e2318941173c5b21271306c9c
4
- data.tar.gz: 195ab587c4db244d0648d4a3f1c80445ee0831e1
3
+ metadata.gz: dac677100702afe680ec1161c2ecbfa9426df4ba
4
+ data.tar.gz: c2d7360b4dacc32286a59ffa6f67dccc1f04ebb5
5
5
  SHA512:
6
- metadata.gz: 3c89e3dfd4c8074e297f2c2d05274aa07019094911efc45ac08ef4fff71353d46ab47d8552861a74fea837e5d3d1342bea9bd856810be420b7b65bfee7016e6d
7
- data.tar.gz: bad7d58ad27909f78d598a6ff9351544936bc063fc02a007b4fcce81bff05347f7409a231be964ac02bdd980e7ae4305c8b7a3e8b39482b48c6acbd6f06a99df
6
+ metadata.gz: 0c388ac3ad8bad464cc111c1a5f2e8fe6a4de37d978fb4fdc87f7dbf5439849acc0b218f213a222d820cce8f43bff37bdb7ef8ea42b94e072c3eaf19b4afc7f5
7
+ data.tar.gz: 98a5889fea125fff15c609b272a810d1b8b553ce0fc6b2a24e121478ffda6d5f86d2f624fb5e8a5328cc660304d543611b4cb833f4ae9a44bb7ea6ec876d776d
@@ -2,6 +2,8 @@ require "barcodevalidation/version"
2
2
 
3
3
  module Barcodevalidation
4
4
  def self.valid?(barcode)
5
+ Integer(barcode)
6
+
5
7
  parts = ('%018d' % barcode).to_s.chars.map(&:to_i)
6
8
  checksum = parts.pop
7
9
  parts
@@ -17,5 +19,8 @@ module Barcodevalidation
17
19
 
18
20
  calculated_checksum = ((calculated_checksum.to_f / 10).ceil * 10) - calculated_checksum
19
21
  checksum == calculated_checksum
22
+
23
+ rescue ArgumentError
24
+ false #we only accept numeric barcodes
20
25
  end
21
26
  end
@@ -1,3 +1,3 @@
1
1
  module Barcodevalidation
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,6 +8,7 @@ class TestBarcodevalidation < MiniTest::Test
8
8
  def test_valid_barcodes
9
9
  [
10
10
  937179004167,
11
+ '937179004167',
11
12
  9312631133233
12
13
  ].each { |barcode| assert Barcodevalidation.valid?(barcode), barcode }
13
14
  end
@@ -18,7 +19,18 @@ class TestBarcodevalidation < MiniTest::Test
18
19
  1234567890123, #invalid check digit
19
20
  50140424, #invalid check digit
20
21
  5420056646861,
21
- 10004336
22
+ 10004336,
23
+ '48cm',
24
+ 1, #make sure only valid length barcodes are accepted
25
+ 22,
26
+ 333,
27
+ 4444,
28
+ 55555,
29
+ 666666,
30
+ 777777,
31
+ 99999999,
32
+ 12345678901,
33
+ 123456789012345
22
34
  ].each { |barcode| refute Barcodevalidation.valid?(barcode), barcode }
23
35
  end
24
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barcodevalidation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Harper