Class: BarcodeValidation::GTIN::CheckDigit
- Includes:
- Adamantium::Flat, 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.
11 12 13 14 15 16 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 11 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.
9 10 11 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 9 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
9 10 11 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 9 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
22 23 24 25 26 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 22 def inspect return super if valid? "#<#{self.class}(#{actual}) invalid: expected #{expected}>" end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 18 def valid? actual == expected end |