Class: BarcodeValidation::GTIN::CheckDigit

Inherits:
Digit
  • Object
show all
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

Instance Method Summary collapse

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

#actualObject (readonly)

Returns the value of attribute actual.



8
9
10
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 8

def actual
  @actual
end

#expectedObject (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

#inspectObject



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

Returns:

  • (Boolean)


17
18
19
# File 'lib/barcodevalidation/gtin/check_digit.rb', line 17

def valid?
  actual == expected
end