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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba3b5afd4aee1020e30233ec636f17390d4ce3b0683f485e26811d84afe9e7e5
4
- data.tar.gz: 1c533193d00fad326a78342876b42f15b5a4534d0cd4c47451962687c2dce95e
3
+ metadata.gz: b6949efb809df8a20b1d2816bd27f5fada9ed3273f5ed52e1008c85169a29151
4
+ data.tar.gz: 120483828346597e8e418737d8bba2f7348104117008caf2e69245720f4f9eaa
5
5
  SHA512:
6
- metadata.gz: f295608b02b3ce172d58b45572db6f1c0d566d55fa9277b59c1ba34098503d1bc9513cbb00c785169ff342a242c29c5398771bc578d23ce348c69984c90e84fe
7
- data.tar.gz: 5784a212986f8973bd2e7d5bcfc473c0b61c9c92c194d966f554e86dedbf92943cf7766a89debe4ee0428967ab6e138b87b8b309a79c85b0fbdcc3b766ae31ac
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
- Rubocop is used to enforce coding standards.
137
+ [StandardRB](https://github.com/standardrb/standard) is used to enforce coding standards.
138
138
 
139
139
  ```
140
- bin/rubocop
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
- * `rubocop`: Runs Rubocop (equivalent to `bin/bundle exec rubocop`)
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
@@ -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 = ">= 2.5"
9
- spec.name = "barcodevalidation"
10
- spec.version = BarcodeValidation::VERSION
11
- spec.authors = ["Marketplacer"]
12
- spec.email = ["it@marketplacer.com"]
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 = "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"
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 = %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) }
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 + "lib"
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 + "Gemfile").to_s
31
+ ENV["BUNDLE_GEMFILE"] ||= (project_root / "Gemfile").to_s
32
32
  require "bundler"
@@ -18,7 +18,7 @@ module BarcodeValidation
18
18
  raise Digit::ArgumentError, input
19
19
  end
20
20
 
21
- alias to_i __getobj__
21
+ alias_method :to_i, :__getobj__
22
22
 
23
23
  ArgumentError = Error::ArgumentErrorClass.new(self)
24
24
  end
@@ -31,6 +31,10 @@ module BarcodeValidation
31
31
  end
32
32
  end
33
33
 
34
+ def all_zeros?
35
+ all? { |digit| digit.to_i.zero? }
36
+ end
37
+
34
38
  def *(other)
35
39
  self.class.new(super)
36
40
  end
@@ -15,7 +15,7 @@ module BarcodeValidation
15
15
  end
16
16
 
17
17
  def initialize(input)
18
- super "invalid value for #{klass}(): #{input.inspect}"
18
+ super("invalid value for #{klass}(): #{input.inspect}")
19
19
  end
20
20
  end
21
21
  end
@@ -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
- raise ArgumentError, "The class you want to prioritize before is not a registered prioritized GTIN class." unless GTIN.gtin_class?(other_gtin_class)
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
- raise(AbstractMethodError, "Concrete classes must define the VALID_LENGTH constant") unless self.class.const_defined?(:VALID_LENGTH)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BarcodeValidation
4
- VERSION = "2.6.0"
4
+ VERSION = "2.7.0"
5
5
  end
@@ -34,7 +34,7 @@ module BarcodeValidation
34
34
  include Error
35
35
 
36
36
  def initialize(input)
37
- super "Invalid GTIN #{input.inspect}"
37
+ super("Invalid GTIN #{input.inspect}")
38
38
  end
39
39
  end
40
40
  end
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.6.0
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: 2022-09-29 00:00:00.000000000 Z
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: '2.5'
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.2.33
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: []