Class: BarcodeValidation::GTIN::CheckDigit
- Includes:
- Mixin::ValueObject
- Defined in:
- lib/barcodevalidation/gtin/check_digit.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
Constructor Details
#initialize(actual, expected: nil) ⇒ CheckDigit
Returns a new instance of CheckDigit.
10 11 12 13 14 15 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 10 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.
8 9 10 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 8 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
8 9 10 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 8 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
21 22 23 24 25 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 21 def inspect return super if valid? "#<#{self.class}(#{actual}) invalid: expected #{expected}>" end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 17 def valid? actual == expected end |