Class: BarcodeValidation::GTIN::Base
Defined Under Namespace
Classes: AbstractMethodError
Constant Summary
collapse
- MODULUS =
10
DigitSequence::ArgumentError
Instance Attribute Summary collapse
Instance Method Summary
collapse
#*, #==, cast
#eql?, included, #inspect, #pretty_print
Constructor Details
#initialize(input) ⇒ Base
Returns a new instance of Base.
Instance Attribute Details
Returns the value of attribute input.
12
13
14
|
# File 'lib/barcodevalidation/gtin/base.rb', line 12
def input
@input
end
|
Instance Method Details
#check_digit ⇒ Object
59
60
61
|
# File 'lib/barcodevalidation/gtin/base.rb', line 59
def check_digit
CheckDigit.new(last, expected: expected_check_digit)
end
|
#to_all_valid ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/barcodevalidation/gtin/base.rb', line 34
def to_all_valid
[
to_gtin_8,
to_gtin_12,
to_gtin_13,
to_gtin_14,
].select(&:valid?)
end
|
#to_gtin_12 ⇒ Object
47
48
49
|
# File 'lib/barcodevalidation/gtin/base.rb', line 47
def to_gtin_12
is_a?(GTIN12) ? self : transcode_to(GTIN12)
end
|
#to_gtin_13 ⇒ Object
51
52
53
|
# File 'lib/barcodevalidation/gtin/base.rb', line 51
def to_gtin_13
is_a?(GTIN13) ? self : transcode_to(GTIN13)
end
|
#to_gtin_14 ⇒ Object
55
56
57
|
# File 'lib/barcodevalidation/gtin/base.rb', line 55
def to_gtin_14
is_a?(GTIN14) ? self : transcode_to(GTIN14)
end
|
#to_gtin_8 ⇒ Object
43
44
45
|
# File 'lib/barcodevalidation/gtin/base.rb', line 43
def to_gtin_8
is_a?(GTIN8) ? self : transcode_to(GTIN8)
end
|
#valid? ⇒ Boolean
22
23
24
|
# File 'lib/barcodevalidation/gtin/base.rb', line 22
def valid?
valid_length == length && check_digit.valid?
end
|
#valid_length ⇒ Object
26
27
28
29
30
|
# File 'lib/barcodevalidation/gtin/base.rb', line 26
def valid_length
raise(AbstractMethodError, "Concrete classes must define the VALID_LENGTH constant") unless self.class.const_defined?(:VALID_LENGTH)
self.class::VALID_LENGTH
end
|