Class: BarcodeValidation::GTIN::CheckDigit
- Includes:
- Mixin::ValueObject
- Defined in:
- lib/barcodevalidation/gtin.rb
Constant Summary
Constants inherited from Digit
Digit::ArgumentError, Digit::INTEGER_CAST_ERRORS
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Instance Method Summary collapse
-
#initialize(actual, expected: nil) ⇒ CheckDigit
constructor
A new instance of CheckDigit.
- #inspect ⇒ Object
- #valid? ⇒ Boolean
Methods included from Mixin::ValueObject
#eql?, included, #pretty_print
Methods inherited from Digit
Constructor Details
#initialize(actual, expected: nil) ⇒ CheckDigit
Returns a new instance of CheckDigit.
25 26 27 28 29 30 |
# File 'lib/barcodevalidation/gtin.rb', line 25 def initialize(actual, expected: nil) expected = actual if expected.nil? @expected = Digit.new(expected) @actual = Digit.new(actual) super(@actual) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
Returns the value of attribute actual.
23 24 25 |
# File 'lib/barcodevalidation/gtin.rb', line 23 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
23 24 25 |
# File 'lib/barcodevalidation/gtin.rb', line 23 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
36 37 38 39 |
# File 'lib/barcodevalidation/gtin.rb', line 36 def inspect return super if valid? "#<#{self.class}(#{actual}) invalid: expected #{expected}>" end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/barcodevalidation/gtin.rb', line 32 def valid? actual == expected end |