Module: BarcodeValidation::GTIN

Defined in:
lib/barcodevalidation/gtin.rb,
lib/barcodevalidation/gtin/base.rb,
lib/barcodevalidation/gtin/gtin8.rb,
lib/barcodevalidation/gtin/gtin12.rb,
lib/barcodevalidation/gtin/gtin13.rb,
lib/barcodevalidation/gtin/gtin14.rb,
lib/barcodevalidation/gtin/check_digit.rb

Overview

GTIN is responsible for wrapping input in an appropriate GTIN::Base sub-class. An important part of this involves managing the prioritized list of GTIN classes we use for handling input. The methods implemented here are used by GTIN::Base to manage this list and prioritize classes.

Defined Under Namespace

Classes: Base, CheckDigit, GTIN12, GTIN13, GTIN14, GTIN8

Class Method Summary collapse

Class Method Details

.append_gtin_class(gtin_class) ⇒ Object

Adds the provided class to the back of the list of prioritized GTIN classes.



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

def append_gtin_class(gtin_class)
  prioritized_gtin_classes.push(gtin_class) unless gtin_class?(gtin_class)
  nil
end

.gtin_class?(gtin_class) ⇒ true, false

Is this a registered prioritized GTIN class?



30
31
32
# File 'lib/barcodevalidation/gtin.rb', line 30

def gtin_class?(gtin_class)
  prioritized_gtin_classes.include?(gtin_class)
end

.new(input) ⇒ Object



12
13
14
# File 'lib/barcodevalidation/gtin.rb', line 12

def new(input)
  (class_for_input(input) || BarcodeValidation::InvalidGTIN).new(input)
end

.remove_gtin_class(gtin_class) ⇒ Object

Ensure the provided class is removed from the list of prioritized GTIN classes.



23
24
25
26
# File 'lib/barcodevalidation/gtin.rb', line 23

def remove_gtin_class(gtin_class)
  prioritized_gtin_classes.delete(gtin_class)
  nil
end

.reprioritize_before(high_priority_class, low_priority_class) ⇒ Object



36
37
38
39
40
41
# File 'lib/barcodevalidation/gtin.rb', line 36

def reprioritize_before(high_priority_class, low_priority_class)
  low_priority_index = prioritized_gtin_classes.index(low_priority_class)
  remove_gtin_class(high_priority_class)
  prioritized_gtin_classes.insert(low_priority_index, high_priority_class)
  nil
end