barcodevalidation 2.6.0 → 2.7.0
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/README.md +3 -4
- data/barcodevalidation.gemspec +16 -16
- data/config/boot.rb +2 -2
- data/lib/barcodevalidation/digit.rb +1 -1
- data/lib/barcodevalidation/digit_sequence.rb +4 -0
- data/lib/barcodevalidation/error/argument_error_class.rb +1 -1
- data/lib/barcodevalidation/gtin/base.rb +15 -6
- data/lib/barcodevalidation/version.rb +1 -1
- data/lib/barcodevalidation.rb +1 -1
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6949efb809df8a20b1d2816bd27f5fada9ed3273f5ed52e1008c85169a29151
|
4
|
+
data.tar.gz: 120483828346597e8e418737d8bba2f7348104117008caf2e69245720f4f9eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451437593aad8dbf1ccd2c180be239c5b87c7503760cccae4e37583e1fdde899ddcbd8b3a3ab5eb4b53a1e1c6e6f7c3ae7c5155bfab6bd2ea83839c6da092a47
|
7
|
+
data.tar.gz: 84024a6d521aa3dbe7a205d37fbb3f7c5efaec448fb2ab6d43a8b4e58b2d9ccae349ba91020cec18f2d02a4806a8ff646a6eb33e1494dd5f2476d50335a6675a
|
data/README.md
CHANGED
@@ -134,11 +134,10 @@ bin/rake
|
|
134
134
|
|
135
135
|
#### Code Quality Checks
|
136
136
|
|
137
|
-
|
137
|
+
[StandardRB](https://github.com/standardrb/standard) is used to enforce coding standards.
|
138
138
|
|
139
139
|
```
|
140
|
-
bin/
|
141
|
-
bin/rubocop --help
|
140
|
+
bin/standardrb
|
142
141
|
```
|
143
142
|
|
144
143
|
|
@@ -163,7 +162,7 @@ Gem, created using `bundler gem barcodevalidation`.
|
|
163
162
|
* `bundle`: Runs Bundler, in the correct way
|
164
163
|
* `console`: development console (equiv. to `bin/bundle exec pry`)
|
165
164
|
* `rake`: Runs Rake (equivalent to `bin/bundle exec rake`)
|
166
|
-
* `
|
165
|
+
* `standardrb`: Runs standardrb (equivalent to `bin/bundle exec standardrb`)
|
167
166
|
* `setup`: Sets up the project to be ready for development
|
168
167
|
* `config/boot.rb`: Prepares dependencies before loading the library
|
169
168
|
* `lib/`: Source files; this directory is added to Ruby's load path
|
data/barcodevalidation.gemspec
CHANGED
@@ -5,23 +5,23 @@ $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 = ">=
|
9
|
-
spec.name
|
10
|
-
spec.version
|
11
|
-
spec.authors
|
12
|
-
spec.email
|
8
|
+
spec.required_ruby_version = ">= 3.1"
|
9
|
+
spec.name = "barcodevalidation"
|
10
|
+
spec.version = BarcodeValidation::VERSION
|
11
|
+
spec.authors = ["Marketplacer"]
|
12
|
+
spec.email = ["it@marketplacer.com"]
|
13
13
|
|
14
|
-
spec.summary
|
15
|
-
spec.description
|
16
|
-
spec.homepage
|
17
|
-
spec.license
|
14
|
+
spec.summary = "Parses and validates barcodes"
|
15
|
+
spec.description = "A RubyGem to parse and validate barcodes"
|
16
|
+
spec.homepage = "https://github.com/marketplacer/#{spec.name}"
|
17
|
+
spec.license = "MIT"
|
18
18
|
|
19
|
-
spec.files
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
spec.bindir
|
24
|
-
spec.executables
|
25
|
-
|
19
|
+
spec.files = %w[LICENSE.md README.md barcodevalidation.gemspec
|
20
|
+
config/*.rb lib/**/*.rb]
|
21
|
+
.flat_map { |pattern| Dir.glob(pattern) }
|
22
|
+
.reject { |f| File.directory?(f) }
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files
|
25
|
+
.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
end
|
data/config/boot.rb
CHANGED
@@ -24,9 +24,9 @@ require "pathname"
|
|
24
24
|
project_root = Pathname.new(__FILE__).parent.parent
|
25
25
|
|
26
26
|
# Add lib directory to load path
|
27
|
-
lib = project_root
|
27
|
+
lib = project_root / "lib"
|
28
28
|
$LOAD_PATH.unshift(lib.to_s) unless $LOAD_PATH.include?(lib.to_s)
|
29
29
|
|
30
30
|
# Tell Bundler explicitly which Gemfile to use
|
31
|
-
ENV["BUNDLE_GEMFILE"] ||= (project_root
|
31
|
+
ENV["BUNDLE_GEMFILE"] ||= (project_root / "Gemfile").to_s
|
32
32
|
require "bundler"
|
@@ -30,11 +30,15 @@ module BarcodeValidation
|
|
30
30
|
# Upon inheritance, register the subclass so users of the library can dynamically add more GTINs in their own code.
|
31
31
|
def self.inherited(subclass)
|
32
32
|
BarcodeValidation::GTIN.append_gtin_class(subclass)
|
33
|
+
super
|
33
34
|
end
|
34
35
|
|
35
36
|
# Ensure this class is earlier in the GTIN classes list than +other_gtin_class+ and thus will get asked earlier if it handles a GTIN.
|
36
37
|
def self.prioritize_before(other_gtin_class)
|
37
|
-
|
38
|
+
unless GTIN.gtin_class?(other_gtin_class)
|
39
|
+
raise ArgumentError,
|
40
|
+
"The class you want to prioritize before is not a registered prioritized GTIN class."
|
41
|
+
end
|
38
42
|
|
39
43
|
GTIN.reprioritize_before(self, other_gtin_class)
|
40
44
|
end
|
@@ -48,11 +52,16 @@ module BarcodeValidation
|
|
48
52
|
abstract_class
|
49
53
|
|
50
54
|
def valid?
|
51
|
-
valid_length == length && check_digit.valid?
|
55
|
+
valid_length == length && !all_zeros? && check_digit.valid?
|
52
56
|
end
|
53
57
|
|
54
58
|
def valid_length
|
55
|
-
|
59
|
+
unless self.class.const_defined?(:VALID_LENGTH)
|
60
|
+
raise(
|
61
|
+
AbstractMethodError,
|
62
|
+
"Concrete classes must define the VALID_LENGTH constant"
|
63
|
+
)
|
64
|
+
end
|
56
65
|
|
57
66
|
self.class::VALID_LENGTH
|
58
67
|
end
|
@@ -64,7 +73,7 @@ module BarcodeValidation
|
|
64
73
|
to_gtin_8,
|
65
74
|
to_gtin_12,
|
66
75
|
to_gtin_13,
|
67
|
-
to_gtin_14
|
76
|
+
to_gtin_14
|
68
77
|
].select(&:valid?)
|
69
78
|
end
|
70
79
|
|
@@ -112,14 +121,14 @@ module BarcodeValidation
|
|
112
121
|
# BarcodeValidation::InvalidGTIN with valid? = false and a meaningful
|
113
122
|
# error message.
|
114
123
|
def transcode_to(klass)
|
115
|
-
gtin = klass.new(format("%0#{klass::VALID_LENGTH}d", to_s.gsub(/^0
|
124
|
+
gtin = klass.new(format("%0#{klass::VALID_LENGTH}d", to_s.gsub(/^0+(?=.)/, "")))
|
116
125
|
|
117
126
|
if gtin.valid?
|
118
127
|
gtin
|
119
128
|
else
|
120
129
|
BarcodeValidation::InvalidGTIN.new(
|
121
130
|
input,
|
122
|
-
error: klass::ConversionError.new(klass).exception(input)
|
131
|
+
error: klass::ConversionError.new(klass).exception(input)
|
123
132
|
)
|
124
133
|
end
|
125
134
|
end
|
data/lib/barcodevalidation.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodevalidation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marketplacer
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: A RubyGem to parse and validate barcodes
|
14
13
|
email:
|
@@ -42,7 +41,6 @@ homepage: https://github.com/marketplacer/barcodevalidation
|
|
42
41
|
licenses:
|
43
42
|
- MIT
|
44
43
|
metadata: {}
|
45
|
-
post_install_message:
|
46
44
|
rdoc_options: []
|
47
45
|
require_paths:
|
48
46
|
- lib
|
@@ -50,15 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
48
|
requirements:
|
51
49
|
- - ">="
|
52
50
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
51
|
+
version: '3.1'
|
54
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
53
|
requirements:
|
56
54
|
- - ">="
|
57
55
|
- !ruby/object:Gem::Version
|
58
56
|
version: '0'
|
59
57
|
requirements: []
|
60
|
-
rubygems_version: 3.
|
61
|
-
signing_key:
|
58
|
+
rubygems_version: 3.6.7
|
62
59
|
specification_version: 4
|
63
60
|
summary: Parses and validates barcodes
|
64
61
|
test_files: []
|