barcodevalidation 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/barcodevalidation/digit.rb +3 -7
- data/lib/barcodevalidation/digit_sequence.rb +1 -14
- data/lib/barcodevalidation/gtin.rb +1 -0
- data/lib/barcodevalidation/mixin/has_check_digit.rb +2 -2
- data/lib/barcodevalidation/mixin/value_object.rb +1 -7
- data/lib/barcodevalidation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 897dd3cdb0c9e0bf7d9f50bfeb98b0ac8be7b79d
|
4
|
+
data.tar.gz: 93fb7cc3b723a9ce5c935c6eba57bfadad217d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a6cee629384d5ff836f8ca9df2a29bbbd3a982498cd3d5f232bfd5b8b86dde9c6cbc569ae2ca01658fd0b887d24c185e5ee523ff82b90f21aa2f280e133b21d
|
7
|
+
data.tar.gz: 2d6659bfb3bf670a7b28d7c55e25ecc81412706421ffeee3ea19043f0d28df50e16d7e4f51d0f6f093d959435725e48d38c74b771af1d5f50229499654a07809
|
@@ -2,17 +2,11 @@ require "delegate"
|
|
2
2
|
|
3
3
|
module BarcodeValidation
|
4
4
|
class Digit < DelegateClass(Integer)
|
5
|
+
include Adamantium
|
5
6
|
include Mixin::ValueObject
|
6
7
|
|
7
8
|
INTEGER_CAST_ERRORS = [::ArgumentError, ::TypeError].freeze
|
8
9
|
|
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
10
|
def initialize(input)
|
17
11
|
value = Integer(input)
|
18
12
|
raise ::ArgumentError unless (0..9).cover? value
|
@@ -21,6 +15,8 @@ module BarcodeValidation
|
|
21
15
|
raise Digit::ArgumentError, input
|
22
16
|
end
|
23
17
|
|
18
|
+
alias to_i __getobj__
|
19
|
+
|
24
20
|
ArgumentError = Error::ArgumentErrorClass.new(self)
|
25
21
|
end
|
26
22
|
end
|
@@ -3,16 +3,12 @@ require "forwardable"
|
|
3
3
|
module BarcodeValidation
|
4
4
|
class DigitSequence < Array
|
5
5
|
extend Forwardable
|
6
|
+
include Adamantium::Flat
|
6
7
|
include Mixin::ValueObject
|
7
8
|
|
8
9
|
delegate to_s: :join
|
9
10
|
delegate cast: "self.class"
|
10
11
|
|
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
12
|
def self.cast(input)
|
17
13
|
input = input.to_s if input.is_a? Integer
|
18
14
|
input = input.chars if input.is_a? String
|
@@ -32,15 +28,6 @@ module BarcodeValidation
|
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
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
31
|
ArgumentError = Error::ArgumentErrorClass.new(DigitSequence)
|
45
32
|
end
|
46
33
|
end
|
@@ -17,12 +17,12 @@ module BarcodeValidation
|
|
17
17
|
def weighted_checkable_digit_sum
|
18
18
|
checkable_digits
|
19
19
|
.zip([3, 1].cycle)
|
20
|
-
.map { |
|
20
|
+
.map { |digit, factor| digit * factor }
|
21
21
|
.reduce(&:+)
|
22
22
|
end
|
23
23
|
|
24
24
|
def checkable_digits
|
25
|
-
take(length - 1).reverse
|
25
|
+
take(length - 1).reverse.map(&:to_i)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -5,18 +5,12 @@ module BarcodeValidation
|
|
5
5
|
module ValueObject
|
6
6
|
def self.included(mod)
|
7
7
|
mod.extend ClassMethods
|
8
|
-
mod.include Adamantium
|
9
8
|
end
|
10
9
|
|
11
10
|
module ClassMethods
|
12
11
|
# Memoizes return values based on the inputs
|
13
12
|
def new(*args)
|
14
|
-
(@__new_cache ||= {})[
|
15
|
-
end
|
16
|
-
|
17
|
-
# Customise the memoisation logic in classes which include this
|
18
|
-
def memoization_key(*args)
|
19
|
-
args
|
13
|
+
(@__new_cache ||= {})[args] ||= super
|
20
14
|
end
|
21
15
|
end
|
22
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodevalidation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marketplacer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: adamantium
|