barcodevalidation 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: 84bbd3fe9cbb881208a51ecfafa282d5ee9bc5e9
4
- data.tar.gz: 5ac9ff35d2d81d7ea0d67192acde59a29b94e681
3
+ metadata.gz: 897dd3cdb0c9e0bf7d9f50bfeb98b0ac8be7b79d
4
+ data.tar.gz: 93fb7cc3b723a9ce5c935c6eba57bfadad217d6a
5
5
  SHA512:
6
- metadata.gz: f4a4842daa354e183476db6a0c61a70f99d4a0aa426a90f5ff166dba01718fa7557f8d3a7576c6aa13ca2180c51cafc9e0c80ba5a6b2bb85e430e22b8fa09769
7
- data.tar.gz: be9e9f1e3a9393c93030a2979e1d4a9232c502b792831e79dc7e5d160c8bfcabd4bf0aa042fea598150facff3aa43e52833ccde03e03b507a9684b4510954fbf
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
@@ -18,6 +18,7 @@ module BarcodeValidation
18
18
  end
19
19
 
20
20
  class CheckDigit < DelegateClass(Digit)
21
+ include Adamantium::Flat
21
22
  include Mixin::ValueObject
22
23
 
23
24
  attr_reader :actual, :expected
@@ -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 { |l, r| l * r }
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 ||= {})[memoization_key(*args)] ||= super
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
 
@@ -1,3 +1,3 @@
1
1
  module BarcodeValidation
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
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.0.0
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-01 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adamantium