Class: BarcodeValidation::Digit
- Inherits:
-
Integer
- Object
- Integer
- BarcodeValidation::Digit
- Includes:
- Mixin::ValueObject
- Defined in:
- lib/barcodevalidation/digit.rb
Direct Known Subclasses
Constant Summary collapse
- INTEGER_CAST_ERRORS =
[::ArgumentError, ::TypeError].freeze
- ArgumentError =
Error::ArgumentErrorClass.new(self)
Class Method Summary collapse
-
.memoization_key(input) ⇒ Object
Memoize constructor based on the integer value given.
Instance Method Summary collapse
-
#initialize(input) ⇒ Digit
constructor
A new instance of Digit.
Methods included from Mixin::ValueObject
#eql?, included, #inspect, #pretty_print
Constructor Details
#initialize(input) ⇒ Digit
Returns a new instance of Digit.
16 17 18 19 20 21 22 |
# File 'lib/barcodevalidation/digit.rb', line 16 def initialize(input) value = Integer(input) raise ::ArgumentError unless (0..9).cover? value super(value) rescue *INTEGER_CAST_ERRORS raise Digit::ArgumentError, input end |
Class Method Details
.memoization_key(input) ⇒ Object
Memoize constructor based on the integer value given
10 11 12 13 14 |
# File 'lib/barcodevalidation/digit.rb', line 10 def self.memoization_key(input, *) Integer(input) rescue *INTEGER_CAST_ERRORS nil # the constructor will raise end |