barcodevalidation 2.3.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -9
- data/barcodevalidation.gemspec +1 -3
- data/lib/barcodevalidation/digit.rb +0 -1
- data/lib/barcodevalidation/digit_sequence.rb +4 -1
- data/lib/barcodevalidation/gtin/base.rb +2 -2
- data/lib/barcodevalidation/gtin/check_digit.rb +0 -1
- data/lib/barcodevalidation/invalid_gtin.rb +20 -0
- data/lib/barcodevalidation/mixin/value_object.rb +0 -6
- data/lib/barcodevalidation/version.rb +1 -1
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1472674218493f67abaf42f2c94c4009ca1aabb07180cee0bfd9ef3c6c2fed5
|
4
|
+
data.tar.gz: f8aa280b1ca3ad091d13c4a1391d7598b82cbcd5db3d9a3c92c65cdb4ce2407b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87096371c819a9efa4f2493edf47ae2d21cccb16922e9b1661aa11de5fcf82aab7a2031ba8ec2660d6026003f905488c793d996c65bc21ab3e0fd44255e672f4
|
7
|
+
data.tar.gz: 7eaebe15a7d9ff6c8922b46ec6c1cea2b392235c5b2d245038456ae10c3e72618c5b20c465f1f13094cda06fae3aa123dd3c1fdd189c8f717e9fa04875c6c390
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
barcodevalidation
|
2
2
|
=================
|
3
3
|
|
4
|
-
[![Build Status][
|
4
|
+
[![Build Status][ci-badge]][ci]
|
5
5
|
[![Gem Version][rubygems-badge]][rubygems]
|
6
6
|
|
7
|
-
[
|
8
|
-
[
|
7
|
+
[ci]: <https://buildkite.com/marketplacer/barcodevalidation>
|
8
|
+
[ci-badge]: <https://badge.buildkite.com/d0d578653bc319cd41e9adb2ac23f1c0d59cf56ee6cc329d78.svg?branch=main>
|
9
9
|
[rubygems]: <https://badge.fury.io/rb/barcodevalidation>
|
10
10
|
[rubygems-badge]: <https://badge.fury.io/rb/barcodevalidation.svg>
|
11
11
|
|
@@ -40,20 +40,26 @@ and it's pretty flexible about what you give it.
|
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
gtin = BarcodeValidation.scan("937179-004167")
|
43
|
-
# => #<BarcodeValidation::GTIN(937179004167)>
|
43
|
+
# => #<BarcodeValidation::GTIN::GTIN12(937179004167)>
|
44
44
|
gtin.to_s # => "937179004167"
|
45
45
|
gtin.valid? # => true
|
46
46
|
gtin.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(7)>
|
47
47
|
gtin.first(6) # => #<BarcodeValidation::DigitSequence(937179)>
|
48
48
|
gtin.slice(0..5) # => #<BarcodeValidation::DigitSequence(937179)>
|
49
|
+
gtin.to_gtin_13 # => #<BarcodeValidation::GTIN::GTIN13(0937179004167)>
|
50
|
+
gtin.to_all_valid
|
51
|
+
# => [#<BarcodeValidation::GTIN::GTIN12(937179004167)>,
|
52
|
+
#<BarcodeValidation::GTIN::GTIN123(0937179004167)>]
|
49
53
|
|
50
54
|
bad = BarcodeValidation.scan(937_179_004_162)
|
51
|
-
# => #<BarcodeValidation::
|
55
|
+
# => #<BarcodeValidation::InvalidGTIN(937179004162)>
|
52
56
|
bad.valid? # => false
|
53
57
|
bad.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(2) invalid: expected 7>
|
54
58
|
bad.check_digit.valid? # => false
|
55
59
|
bad.check_digit.actual # => #<BarcodeValidation::Digit(2)>
|
56
60
|
bad.check_digit.expected # => #<BarcodeValidation::Digit(7)>
|
61
|
+
bad.to_gtin_13 # => #<BarcodeValidation::InvalidGTIN(937179004162)>
|
62
|
+
bad.to_all_valid # => []
|
57
63
|
```
|
58
64
|
|
59
65
|
|
@@ -97,11 +103,10 @@ bin/rubocop --help
|
|
97
103
|
|
98
104
|
|
99
105
|
|
100
|
-
|
106
|
+
Tests & Publishing
|
101
107
|
----------------------
|
102
108
|
|
103
|
-
Code is automatically tested with each push, on
|
104
|
-
Marketplacer's internal Buildkite.
|
109
|
+
Code is automatically tested with each push on Buildkite. Assuming all tests pass, commits on `main` will be parsed with [Semantic Release](https://github.com/semantic-release/semantic-release) to produce new Git tags, and to publish to RubyGems.
|
105
110
|
|
106
111
|
|
107
112
|
|
@@ -133,4 +138,4 @@ This project is licensed under the [MIT License]. See [LICENSE.md] for
|
|
133
138
|
the full text.
|
134
139
|
|
135
140
|
[MIT License]: <https://opensource.org/licenses/MIT>
|
136
|
-
[LICENSE.md]: <https://github.com/marketplacer/barcodevalidation/blob/
|
141
|
+
[LICENSE.md]: <https://github.com/marketplacer/barcodevalidation/blob/main/LICENSE.md>
|
data/barcodevalidation.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require "barcodevalidation/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.required_ruby_version = "
|
8
|
+
spec.required_ruby_version = ">= 2.5"
|
9
9
|
spec.name = "barcodevalidation"
|
10
10
|
spec.version = BarcodeValidation::VERSION
|
11
11
|
spec.authors = ["Marketplacer"]
|
@@ -24,6 +24,4 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files
|
25
25
|
.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
|
-
|
28
|
-
spec.add_runtime_dependency "adamantium"
|
29
27
|
end
|
@@ -6,7 +6,6 @@ require_relative "error/argument_error_class"
|
|
6
6
|
module BarcodeValidation
|
7
7
|
class DigitSequence < Array
|
8
8
|
extend Forwardable
|
9
|
-
include Adamantium::Flat
|
10
9
|
include Mixin::ValueObject
|
11
10
|
|
12
11
|
delegate to_s: :join
|
@@ -32,6 +31,10 @@ module BarcodeValidation
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
34
|
+
def *(other)
|
35
|
+
self.class.new(super)
|
36
|
+
end
|
37
|
+
|
35
38
|
ArgumentError = Error::ArgumentErrorClass.new(DigitSequence)
|
36
39
|
end
|
37
40
|
end
|
@@ -56,12 +56,12 @@ module BarcodeValidation
|
|
56
56
|
is_a?(GTIN14) ? self : transcode_to(GTIN14)
|
57
57
|
end
|
58
58
|
|
59
|
-
private
|
60
|
-
|
61
59
|
def check_digit
|
62
60
|
CheckDigit.new(last, expected: expected_check_digit)
|
63
61
|
end
|
64
62
|
|
63
|
+
private
|
64
|
+
|
65
65
|
def expected_check_digit
|
66
66
|
(MODULUS - weighted_checkable_digit_sum) % MODULUS
|
67
67
|
end
|
@@ -22,5 +22,25 @@ module BarcodeValidation
|
|
22
22
|
|
23
23
|
@error.inspect
|
24
24
|
end
|
25
|
+
|
26
|
+
def to_all_valid
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_gtin_8
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_gtin_12
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_gtin_13
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_gtin_14
|
43
|
+
self
|
44
|
+
end
|
25
45
|
end
|
26
46
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "adamantium"
|
4
|
-
|
5
3
|
module BarcodeValidation
|
6
4
|
module Mixin
|
7
5
|
module ValueObject
|
@@ -10,10 +8,6 @@ module BarcodeValidation
|
|
10
8
|
end
|
11
9
|
|
12
10
|
module ClassMethods
|
13
|
-
# Memoizes return values based on the inputs
|
14
|
-
def new(*args)
|
15
|
-
(@__new_cache ||= {})[args] ||= super
|
16
|
-
end
|
17
11
|
end
|
18
12
|
|
19
13
|
def eql?(other)
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodevalidation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marketplacer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: adamantium
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: A RubyGem to parse and validate barcodes
|
28
14
|
email:
|
29
15
|
- it@marketplacer.com
|
@@ -62,7 +48,7 @@ require_paths:
|
|
62
48
|
- lib
|
63
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
50
|
requirements:
|
65
|
-
- - "
|
51
|
+
- - ">="
|
66
52
|
- !ruby/object:Gem::Version
|
67
53
|
version: '2.5'
|
68
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -71,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
57
|
- !ruby/object:Gem::Version
|
72
58
|
version: '0'
|
73
59
|
requirements: []
|
74
|
-
|
75
|
-
rubygems_version: 2.7.6.2
|
60
|
+
rubygems_version: 3.2.33
|
76
61
|
signing_key:
|
77
62
|
specification_version: 4
|
78
63
|
summary: Parses and validates barcodes
|