Skip to content

Commit

Permalink
Fix bug when ean has zero as last digit (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sousajunior authored and costafacchini committed May 13, 2019
1 parent 952a13f commit 7037f35
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/br_documents/gtin/gtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def valid_checksum?
(i + 1).even? ? (even += number.to_i) : (odd += number.to_i * 3)
end

@code.chars.last.to_i == (10 - (odd + even) % 10)
@code.chars.last.to_i == ((10 - (odd + even)) % 10)
end
end
end
2 changes: 1 addition & 1 deletion lib/br_documents/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BrDocuments
VERSION = "0.1.0"
VERSION = "0.1.1"
end
6 changes: 6 additions & 0 deletions spec/gtin/gtin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
it { is_expected.to be_valid }
end

context 'when the final digit is zero' do
subject { described_class.new('7898417964120') }

it { is_expected.to be_valid }
end

context 'when the number of digits is different of 8, 13 or 14' do
subject { described_class.new('12345678901234560') }

Expand Down

0 comments on commit 7037f35

Please sign in to comment.