Class: BarcodeValidation::DigitSequence

Inherits:
Array
  • Object
show all
Extended by:
Forwardable
Includes:
Mixin::ValueObject
Defined in:
lib/barcodevalidation/digit_sequence.rb

Direct Known Subclasses

GTIN::Base

Constant Summary collapse

ArgumentError =
Error::ArgumentErrorClass.new(DigitSequence)

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ValueObject

#eql?, included, #inspect, #pretty_print

Constructor Details

#initialize(values) ⇒ DigitSequence

Returns a new instance of DigitSequence.

Raises:



20
21
22
23
24
25
# File 'lib/barcodevalidation/digit_sequence.rb', line 20

def initialize(values)
  values = cast(values)
  raise ArgumentError, values unless values.respond_to? :map

  super(values.map { |value| BarcodeValidation::Digit.new(value) })
end

Class Method Details

.cast(input) ⇒ Object



14
15
16
17
18
# File 'lib/barcodevalidation/digit_sequence.rb', line 14

def self.cast(input)
  input = input.to_s if input.is_a? Integer
  input = input.chars if input.is_a? String
  input
end

Instance Method Details

#*(other) ⇒ Object



34
35
36
# File 'lib/barcodevalidation/digit_sequence.rb', line 34

def *(other)
  self.class.new(super)
end

#==(other) ⇒ Object



27
28
29
30
31
32
# File 'lib/barcodevalidation/digit_sequence.rb', line 27

def ==(other)
  case other
  when String, Numeric then super(self.class.new(other))
  else super
  end
end