Class: BarcodeValidation::Digit

Inherits:
Integer
  • Object
show all
Includes:
Mixin::ValueObject
Defined in:
lib/barcodevalidation/digit.rb

Direct Known Subclasses

GTIN::CheckDigit

Constant Summary collapse

INTEGER_CAST_ERRORS =
[::ArgumentError, ::TypeError].freeze
ArgumentError =
Error::ArgumentErrorClass.new(self)

Instance Method Summary collapse

Methods included from Mixin::ValueObject

#eql?, included, #inspect, #pretty_print

Constructor Details

#initialize(input) ⇒ Digit

Returns a new instance of Digit.



12
13
14
15
16
17
18
19
# File 'lib/barcodevalidation/digit.rb', line 12

def initialize(input)
  value = Integer(input)
  raise ::ArgumentError unless (0..9).cover? value

  super(value)
rescue *INTEGER_CAST_ERRORS
  raise Digit::ArgumentError, input
end