Module: Gtiny::Converters

Defined in:
lib/gtiny/converters.rb,
lib/gtiny/converters/registrar.rb

Overview

A module containing converters and utility classes for translating between encoding types.

Defined Under Namespace

Classes: Registrar

Constant Summary collapse

ISBN10_PREFIX =
"978-"

Class Method Summary collapse

Class Method Details

.registrarObject

The out-of-the-box registrar that is aware of all our conversions.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gtiny/converters.rb', line 51

def self.registrar
  @registrar ||= Registrar.new.tap do |registrar|
    registrar.register(@gtin_to_gtin14, from: GTIN13, to: GTIN14)
    registrar.register(@gtin_to_gtin14, from: GTIN12, to: GTIN14)
    registrar.register(@gtin_to_gtin14, from: GTIN8, to: GTIN14)
    registrar.register(@isbn13_to_gtin13, from: ISBN13, to: GTIN13)
    registrar.register(@isbn10_to_isbn13, from: ISBN10, to: ISBN13)

    # ISBNs can require a few hops to make it to a GTIN-14.
    registrar.register_chain(from: ISBN13, to: GTIN14, via: GTIN13)
    registrar.register_chain(from: ISBN10, to: GTIN13, via: ISBN13)
    registrar.register_chain(from: ISBN10, to: GTIN14, via: ISBN13)
  end
end