barcodevalidation 1.0.1 → 2.0.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/LICENSE.md +23 -0
- data/README.md +118 -13
- data/barcodevalidation.gemspec +16 -9
- data/config/boot.rb +30 -0
- data/lib/barcodevalidation.rb +29 -18
- data/lib/barcodevalidation/digit.rb +26 -0
- data/lib/barcodevalidation/digit_sequence.rb +46 -0
- data/lib/barcodevalidation/error.rb +1 -0
- data/lib/barcodevalidation/error/argument_error_class.rb +20 -0
- data/lib/barcodevalidation/gtin.rb +42 -0
- data/lib/barcodevalidation/invalid_gtin.rb +23 -0
- data/lib/barcodevalidation/mixin.rb +2 -0
- data/lib/barcodevalidation/mixin/has_check_digit.rb +29 -0
- data/lib/barcodevalidation/mixin/value_object.rb +42 -0
- data/lib/barcodevalidation/version.rb +2 -2
- metadata +34 -18
- data/.gitignore +0 -22
- data/.travis.yml +0 -7
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -9
- data/test/minitest_helper.rb +0 -4
- data/test/test_barcodevalidation.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84bbd3fe9cbb881208a51ecfafa282d5ee9bc5e9
|
4
|
+
data.tar.gz: 5ac9ff35d2d81d7ea0d67192acde59a29b94e681
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a4842daa354e183476db6a0c61a70f99d4a0aa426a90f5ff166dba01718fa7557f8d3a7576c6aa13ca2180c51cafc9e0c80ba5a6b2bb85e430e22b8fa09769
|
7
|
+
data.tar.gz: be9e9f1e3a9393c93030a2979e1d4a9232c502b792831e79dc7e5d160c8bfcabd4bf0aa042fea598150facff3aa43e52833ccde03e03b507a9684b4510954fbf
|
data/LICENSE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
MIT License
|
2
|
+
===========
|
3
|
+
|
4
|
+
Copyright (c) 2016 Marketplacer
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
7
|
+
copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included
|
15
|
+
in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
18
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
-
|
1
|
+
barcodevalidation
|
2
|
+
=================
|
2
3
|
|
3
|
-
|
4
|
+
[![Build Status][travis-badge]][travis]
|
5
|
+
[![Gem Version][rubygems-badge]][rubygems]
|
4
6
|
|
5
|
-
|
7
|
+
[travis]: <https://travis-ci.org/marketplacer/barcodevalidation>
|
8
|
+
[travis-badge]: <https://travis-ci.org/marketplacer/barcodevalidation.svg?branch=master>
|
9
|
+
[rubygems]: <https://badge.fury.io/rb/barcodevalidation>
|
10
|
+
[rubygems-badge]: <https://badge.fury.io/rb/barcodevalidation.svg>
|
6
11
|
|
7
|
-
|
12
|
+
A RubyGem to parse and validate barcodes.
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
8
18
|
|
9
19
|
Add this line to your application's Gemfile:
|
10
20
|
|
11
|
-
|
21
|
+
```ruby
|
22
|
+
gem "barcodevalidation"
|
23
|
+
```
|
12
24
|
|
13
25
|
And then execute:
|
14
26
|
|
@@ -18,14 +30,107 @@ Or install it yourself as:
|
|
18
30
|
|
19
31
|
$ gem install barcodevalidation
|
20
32
|
|
21
|
-
## Usage
|
22
33
|
|
23
|
-
Barcodevalidator.valid?(937179004167)
|
24
34
|
|
25
|
-
|
35
|
+
Usage
|
36
|
+
-----
|
37
|
+
|
38
|
+
The main API is `BarcodeValidation.scan`. It accepts a single argument,
|
39
|
+
and it's pretty flexible about what you give it.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
gtin = BarcodeValidation.scan("937179-004167")
|
43
|
+
# => #<BarcodeValidation::GTIN(937179004167)>
|
44
|
+
gtin.to_s # => "937179004167"
|
45
|
+
gtin.valid? # => true
|
46
|
+
gtin.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(7)>
|
47
|
+
gtin.first(6) # => #<BarcodeValidation::DigitSequence(937179)>
|
48
|
+
gtin.slice(0..5) # => #<BarcodeValidation::DigitSequence(937179)>
|
49
|
+
|
50
|
+
bad = BarcodeValidation.scan(937_179_004_162)
|
51
|
+
# => #<BarcodeValidation::GTIN(937179004162)>
|
52
|
+
bad.valid? # => false
|
53
|
+
bad.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(2) invalid: expected 7>
|
54
|
+
bad.check_digit.valid? # => false
|
55
|
+
bad.check_digit.actual # => #<BarcodeValidation::Digit(2)>
|
56
|
+
bad.check_digit.expected # => #<BarcodeValidation::Digit(7)>
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
Development
|
62
|
+
-----------
|
63
|
+
|
64
|
+
Download the code from GitHub:
|
65
|
+
|
66
|
+
```
|
67
|
+
git clone git@github.com:marketplacer/barcodevalidation.git
|
68
|
+
```
|
69
|
+
|
70
|
+
Set up dependencies using Bundler:
|
71
|
+
|
72
|
+
```
|
73
|
+
cd barcodevalidation
|
74
|
+
bin/setup
|
75
|
+
```
|
76
|
+
|
77
|
+
Start the interactive development console:
|
78
|
+
|
79
|
+
```
|
80
|
+
bin/console
|
81
|
+
```
|
82
|
+
|
83
|
+
Run a build:
|
84
|
+
|
85
|
+
```
|
86
|
+
bin/rake
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Code Quality Checks
|
90
|
+
|
91
|
+
Rubocop is used to enforce coding standards.
|
92
|
+
|
93
|
+
```
|
94
|
+
bin/rubocop
|
95
|
+
bin/rubocop --help
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
Continuous Integration
|
101
|
+
----------------------
|
102
|
+
|
103
|
+
Code is automatically tested with each push, on both Travis CI and
|
104
|
+
Marketplacer's internal Buildkite.
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
Project Structure
|
109
|
+
-----------------
|
110
|
+
This project's structure is inspired by the Bundler skeleton for a new
|
111
|
+
Gem, created using `bundler gem barcodevalidation`.
|
112
|
+
|
113
|
+
* `.bundle/config`: Configuration for Bundler
|
114
|
+
* `.ruby-version`: Gives rvm, rbenv, chruby etc. a Ruby version to use
|
115
|
+
* `Gemfile`: Lists RubyGem dependencies, to be installed by Bundler
|
116
|
+
* `Rakefile`: Defines Rake tasks
|
117
|
+
* `bin/`: Contains binstubs, useful for development tasks
|
118
|
+
* `bundle`: Runs Bundler, in the correct way
|
119
|
+
* `console`: development console (equiv. to `bin/bundle exec pry`)
|
120
|
+
* `rake`: Runs Rake (equivalent to `bin/bundle exec rake`)
|
121
|
+
* `rubocop`: Runs Rubocop (equivalent to `bin/bundle exec rubocop`)
|
122
|
+
* `setup`: Sets up the project to be ready for development
|
123
|
+
* `config/boot.rb`: Prepares dependencies before loading the library
|
124
|
+
* `lib/`: Source files; this directory is added to Ruby's load path
|
125
|
+
* `script/ci`: The script run by Buildkite to start a build
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
License
|
130
|
+
-------
|
131
|
+
|
132
|
+
This project is licensed under the [MIT License]. See [LICENSE.md] for
|
133
|
+
the full text.
|
26
134
|
|
27
|
-
|
28
|
-
|
29
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create a new Pull Request
|
135
|
+
[MIT License]: <https://opensource.org/licenses/MIT>
|
136
|
+
[LICENSE.md]: <https://github.com/marketplacer/barcodevalidation/blob/master/LICENSE.md>
|
data/barcodevalidation.gemspec
CHANGED
@@ -1,20 +1,27 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "barcodevalidation/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "barcodevalidation"
|
8
|
-
spec.version =
|
8
|
+
spec.version = BarcodeValidation::VERSION
|
9
9
|
spec.authors = ["Marketplacer"]
|
10
10
|
spec.email = ["it@marketplacer.com"]
|
11
|
-
|
12
|
-
spec.
|
13
|
-
spec.
|
11
|
+
|
12
|
+
spec.summary = "Parses and validates barcodes"
|
13
|
+
spec.description = "A RubyGem to parse and validate barcodes"
|
14
|
+
spec.homepage = "https://github.com/marketplacer/#{spec.name}"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
|
-
spec.files =
|
17
|
-
|
18
|
-
|
17
|
+
spec.files = %w(LICENSE.md README.md barcodevalidation.gemspec
|
18
|
+
config/*.rb lib/**/*.rb)
|
19
|
+
.flat_map { |pattern| Dir.glob(pattern) }
|
20
|
+
.reject { |f| File.directory?(f) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files
|
23
|
+
.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
24
|
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "adamantium"
|
20
27
|
end
|
data/config/boot.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This script sets up the common environment for the project
|
2
|
+
#
|
3
|
+
# Require this file using:
|
4
|
+
#
|
5
|
+
# require File.expand_path("../config/boot.rb", __FILE__)
|
6
|
+
#
|
7
|
+
# This would work from any file located in the root of the project.
|
8
|
+
# For files that are nested within a subdirectory, use a relative path:
|
9
|
+
#
|
10
|
+
# # From within foo/bar/baz.rb relative to the root of the project
|
11
|
+
# require File.expand_path("../../../config/boot.rb", __FILE__)
|
12
|
+
#
|
13
|
+
# Then, to all RubyGems in the Gemfile available, use one of:
|
14
|
+
#
|
15
|
+
# - require "bundler/setup"
|
16
|
+
# - Bundler.setup
|
17
|
+
#
|
18
|
+
# To make only certain groups available, use:
|
19
|
+
#
|
20
|
+
# Bundler.setup(:default, :ci)
|
21
|
+
require "pathname"
|
22
|
+
project_root = Pathname.new(__FILE__).parent.parent
|
23
|
+
|
24
|
+
# Add lib directory to load path
|
25
|
+
lib = project_root + "lib"
|
26
|
+
$LOAD_PATH.unshift(lib.to_s) unless $LOAD_PATH.include?(lib.to_s)
|
27
|
+
|
28
|
+
# Tell Bundler explicitly which Gemfile to use
|
29
|
+
ENV["BUNDLE_GEMFILE"] ||= (project_root + "Gemfile").to_s
|
30
|
+
require "bundler"
|
data/lib/barcodevalidation.rb
CHANGED
@@ -1,26 +1,37 @@
|
|
1
|
+
require "barcodevalidation/mixin"
|
2
|
+
require "barcodevalidation/error"
|
3
|
+
require "barcodevalidation/digit"
|
4
|
+
require "barcodevalidation/digit_sequence"
|
5
|
+
require "barcodevalidation/gtin"
|
6
|
+
require "barcodevalidation/invalid_gtin"
|
1
7
|
require "barcodevalidation/version"
|
2
8
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# accept lengths defined at gtin.info
|
9
|
-
return false unless [8, 12, 13, 14].include?(barcode.length)
|
10
|
-
|
11
|
-
parts = barcode.rjust(18, '0').chars.map(&:to_i)
|
12
|
-
checksum = parts.pop
|
9
|
+
module BarcodeValidation
|
10
|
+
class << self
|
11
|
+
def scan(input)
|
12
|
+
GTIN.new(sanitize(input))
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
calculated_checksum += (part * 3)
|
18
|
-
else
|
19
|
-
calculated_checksum += part
|
15
|
+
def scan!(input)
|
16
|
+
scan(input).tap do |result|
|
17
|
+
raise InvalidGTINError, input unless result.valid?
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
# Strips punctuation
|
24
|
+
def sanitize(input)
|
25
|
+
return input.gsub(/(\s|[-_])/, "") if input.respond_to? :gsub
|
26
|
+
input
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class InvalidGTINError < ::ArgumentError
|
31
|
+
include Error
|
32
|
+
|
33
|
+
def initialize(input)
|
34
|
+
super "Invalid GTIN #{input.inspect}"
|
35
|
+
end
|
25
36
|
end
|
26
37
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
class Digit < DelegateClass(Integer)
|
5
|
+
include Mixin::ValueObject
|
6
|
+
|
7
|
+
INTEGER_CAST_ERRORS = [::ArgumentError, ::TypeError].freeze
|
8
|
+
|
9
|
+
# Memoize constructor based on the integer value given
|
10
|
+
def self.memoization_key(input, *)
|
11
|
+
Integer(input)
|
12
|
+
rescue *INTEGER_CAST_ERRORS
|
13
|
+
nil # the constructor will raise
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(input)
|
17
|
+
value = Integer(input)
|
18
|
+
raise ::ArgumentError unless (0..9).cover? value
|
19
|
+
super(value)
|
20
|
+
rescue *INTEGER_CAST_ERRORS
|
21
|
+
raise Digit::ArgumentError, input
|
22
|
+
end
|
23
|
+
|
24
|
+
ArgumentError = Error::ArgumentErrorClass.new(self)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
class DigitSequence < Array
|
5
|
+
extend Forwardable
|
6
|
+
include Mixin::ValueObject
|
7
|
+
|
8
|
+
delegate to_s: :join
|
9
|
+
delegate cast: "self.class"
|
10
|
+
|
11
|
+
# Memoize constructor based on the integer value given
|
12
|
+
def self.memoization_key(input, *)
|
13
|
+
input.respond_to?(:join) ? input.join : input.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.cast(input)
|
17
|
+
input = input.to_s if input.is_a? Integer
|
18
|
+
input = input.chars if input.is_a? String
|
19
|
+
input
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(values)
|
23
|
+
values = cast(values)
|
24
|
+
raise ArgumentError, values unless values.respond_to? :map
|
25
|
+
super(values.map { |value| BarcodeValidation::Digit.new(value) })
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
case other
|
30
|
+
when String, Numeric then super(self.class.new(other))
|
31
|
+
else super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
%i(* + - drop first last reverse rotate slice shuffle
|
36
|
+
take).each do |method_name|
|
37
|
+
define_method method_name do |*args|
|
38
|
+
super(*args).tap do |result|
|
39
|
+
return DigitSequence.new(result) if result.is_a? Enumerable
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ArgumentError = Error::ArgumentErrorClass.new(DigitSequence)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "error/argument_error_class"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
module Error
|
5
|
+
class ArgumentErrorClass < ::ArgumentError
|
6
|
+
include BarcodeValidation::Error
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
delegate klass: "self.class"
|
10
|
+
|
11
|
+
def self.new(klass)
|
12
|
+
Class.new(self) { define_singleton_method(:klass) { klass } }
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(input)
|
16
|
+
super "invalid value for #{klass}(): #{input.inspect}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
class GTIN < BarcodeValidation::DigitSequence
|
5
|
+
extend Forwardable
|
6
|
+
include Mixin::HasCheckDigit
|
7
|
+
|
8
|
+
VALID_LENGTHS = [8, 12, 13, 14].freeze
|
9
|
+
|
10
|
+
def self.new(input)
|
11
|
+
super
|
12
|
+
rescue BarcodeValidation::Error => e
|
13
|
+
return InvalidGTIN.new(input, error: e)
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid?
|
17
|
+
VALID_LENGTHS.include?(length) && check_digit.valid?
|
18
|
+
end
|
19
|
+
|
20
|
+
class CheckDigit < DelegateClass(Digit)
|
21
|
+
include Mixin::ValueObject
|
22
|
+
|
23
|
+
attr_reader :actual, :expected
|
24
|
+
|
25
|
+
def initialize(actual, expected: nil)
|
26
|
+
expected = actual if expected.nil?
|
27
|
+
@expected = Digit.new(expected)
|
28
|
+
@actual = Digit.new(actual)
|
29
|
+
super(@actual)
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
actual == expected
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
return super if valid?
|
38
|
+
"#<#{self.class}(#{actual}) invalid: expected #{expected}>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "delegate"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
class InvalidGTIN < SimpleDelegator
|
5
|
+
def initialize(input, error: nil)
|
6
|
+
@error = error
|
7
|
+
super(input)
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
%(#<#{self.class} input=#{super} error="#{error_message}">)
|
16
|
+
end
|
17
|
+
|
18
|
+
def error_message
|
19
|
+
return @error.message if @error.respond_to? :message
|
20
|
+
@error.inspect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BarcodeValidation
|
2
|
+
module Mixin
|
3
|
+
# Wraps #last as a CheckDigit
|
4
|
+
module HasCheckDigit
|
5
|
+
MODULUS = 10
|
6
|
+
|
7
|
+
def check_digit
|
8
|
+
GTIN::CheckDigit.new(last, expected: expected_check_digit)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def expected_check_digit
|
14
|
+
(MODULUS - weighted_checkable_digit_sum) % MODULUS
|
15
|
+
end
|
16
|
+
|
17
|
+
def weighted_checkable_digit_sum
|
18
|
+
checkable_digits
|
19
|
+
.zip([3, 1].cycle)
|
20
|
+
.map { |l, r| l * r }
|
21
|
+
.reduce(&:+)
|
22
|
+
end
|
23
|
+
|
24
|
+
def checkable_digits
|
25
|
+
take(length - 1).reverse
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "adamantium"
|
2
|
+
|
3
|
+
module BarcodeValidation
|
4
|
+
module Mixin
|
5
|
+
module ValueObject
|
6
|
+
def self.included(mod)
|
7
|
+
mod.extend ClassMethods
|
8
|
+
mod.include Adamantium
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# Memoizes return values based on the inputs
|
13
|
+
def new(*args)
|
14
|
+
(@__new_cache ||= {})[memoization_key(*args)] ||= super
|
15
|
+
end
|
16
|
+
|
17
|
+
# Customise the memoisation logic in classes which include this
|
18
|
+
def memoization_key(*args)
|
19
|
+
args
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def eql?(other)
|
24
|
+
object_id == other.object_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"#<#{description}>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def pretty_print(pp)
|
32
|
+
pp.text inspect
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def description
|
38
|
+
"#{self.class}(#{self})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "
|
1
|
+
module BarcodeValidation
|
2
|
+
VERSION = "2.0.0".freeze
|
3
3
|
end
|
metadata
CHANGED
@@ -1,34 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodevalidation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marketplacer
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
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'
|
27
|
+
description: A RubyGem to parse and validate barcodes
|
14
28
|
email:
|
15
29
|
- it@marketplacer.com
|
16
30
|
executables: []
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
20
|
-
-
|
21
|
-
- ".travis.yml"
|
22
|
-
- Gemfile
|
23
|
-
- LICENSE.txt
|
34
|
+
- LICENSE.md
|
24
35
|
- README.md
|
25
|
-
- Rakefile
|
26
36
|
- barcodevalidation.gemspec
|
37
|
+
- config/boot.rb
|
27
38
|
- lib/barcodevalidation.rb
|
39
|
+
- lib/barcodevalidation/digit.rb
|
40
|
+
- lib/barcodevalidation/digit_sequence.rb
|
41
|
+
- lib/barcodevalidation/error.rb
|
42
|
+
- lib/barcodevalidation/error/argument_error_class.rb
|
43
|
+
- lib/barcodevalidation/gtin.rb
|
44
|
+
- lib/barcodevalidation/invalid_gtin.rb
|
45
|
+
- lib/barcodevalidation/mixin.rb
|
46
|
+
- lib/barcodevalidation/mixin/has_check_digit.rb
|
47
|
+
- lib/barcodevalidation/mixin/value_object.rb
|
28
48
|
- lib/barcodevalidation/version.rb
|
29
|
-
|
30
|
-
- test/test_barcodevalidation.rb
|
31
|
-
homepage: ''
|
49
|
+
homepage: https://github.com/marketplacer/barcodevalidation
|
32
50
|
licenses:
|
33
51
|
- MIT
|
34
52
|
metadata: {}
|
@@ -48,10 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
66
|
version: '0'
|
49
67
|
requirements: []
|
50
68
|
rubyforge_project:
|
51
|
-
rubygems_version: 2.4.5
|
69
|
+
rubygems_version: 2.4.5.1
|
52
70
|
signing_key:
|
53
71
|
specification_version: 4
|
54
|
-
summary:
|
55
|
-
test_files:
|
56
|
-
- test/minitest_helper.rb
|
57
|
-
- test/test_barcodevalidation.rb
|
72
|
+
summary: Parses and validates barcodes
|
73
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 The Exchange Group
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
data/test/minitest_helper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
class TestBarcodevalidation < MiniTest::Test
|
4
|
-
def test_valid_barcodes
|
5
|
-
[
|
6
|
-
937179004167,
|
7
|
-
'937179004167',
|
8
|
-
9312631133233,
|
9
|
-
'0753759137885'
|
10
|
-
].each { |barcode| assert Barcodevalidation.valid?(barcode), barcode }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_invalid_barcodes
|
14
|
-
[
|
15
|
-
144793, #too short
|
16
|
-
1234567890123, #invalid check digit
|
17
|
-
50140424, #invalid check digit
|
18
|
-
5420056646861,
|
19
|
-
10004336,
|
20
|
-
'48cm',
|
21
|
-
123,
|
22
|
-
1, #make sure only valid length barcodes are accepted
|
23
|
-
22,
|
24
|
-
333,
|
25
|
-
4444,
|
26
|
-
55555,
|
27
|
-
666666,
|
28
|
-
777777,
|
29
|
-
99999999,
|
30
|
-
12345678901,
|
31
|
-
123456789012345,
|
32
|
-
'BODGYBARCODE'
|
33
|
-
].each { |barcode| refute Barcodevalidation.valid?(barcode), barcode }
|
34
|
-
end
|
35
|
-
end
|