barcodevalidation 0.0.3 → 0.0.4

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: 62176c66c6af66908a64e5c4c17ee608ac32fd23
4
- data.tar.gz: 1b391c84a1e285b2f7a05864387eb0063a5055fc
3
+ metadata.gz: c72c46bf313a6a31fa50ae03db6897304cf6faca
4
+ data.tar.gz: c1a2eb265bdaefb33517c456321b8a7f9680cf0c
5
5
  SHA512:
6
- metadata.gz: 4b27ac3cda18acb878c9d78095da8ca16a68036e4ce083bc6cc196d0e98a5793a0f8dda2eaa8bbf25d0e45189b6f3df38f86605211f90672e013fe7d42eaae15
7
- data.tar.gz: b499d57b1a9893a594be89e460a1149be99b5b8eb84f45fd672b1e44b52e3d1eb6da31eb67125b8e383ad1cc5a95b0c056242793247de9077cd1412f7d449657
6
+ metadata.gz: 6bc2e3eaeea800512b9ae6762743805f9012fc074faba3ee4f1c0c1531b973c7fd06a1594f7f9cef4b9396700c98fef562a18b343a6f9e7714ae19e7359fdccb
7
+ data.tar.gz: addc2a455b9f1527787d257a489c42a5840ab93202b96d065c1cc48c56d5096ebaefafb4074a3ad3ac8445bf16edfb664a805fb4c11299b9c93b67db33e79102
@@ -2,12 +2,11 @@ require "barcodevalidation/version"
2
2
 
3
3
  module Barcodevalidation
4
4
  def self.valid?(barcode)
5
- Integer(barcode)
5
+ barcode = barcode.to_s
6
+ return false unless [8, 10, 12, 13].include?(barcode.length)
6
7
 
7
- parts = ('%018d' % barcode).to_s.chars.map(&:to_i)
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 = ((calculated_checksum.to_f / 10).ceil * 10) - 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
@@ -1,3 +1,3 @@
1
1
  module Barcodevalidation
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,7 +9,8 @@ class TestBarcodevalidation < MiniTest::Test
9
9
  [
10
10
  937179004167,
11
11
  '937179004167',
12
- 9312631133233
12
+ 9312631133233,
13
+ '0753759137885'
13
14
  ].each { |barcode| assert Barcodevalidation.valid?(barcode), barcode }
14
15
  end
15
16
 
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.3
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: 2014-09-17 00:00:00.000000000 Z
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.2.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: