require 'eancom/version' module Eancom class Error < StandardError; end class StructureNotFoundError < StandardError; end FILE_TYPES = %I[ desadv pricat ordrsp slsrpt invrp orders ].freeze DELIMITERS = { component: ':', data: '+', release: '?', decimal: '.', reserve: ' ', segment: '\'' }.freeze attr_accessor :definitions, :segments def self.definitions @configs ||= {} end def self.segments @segments ||= {} end def self.structures @structures ||= {} end def self.register_definition(definition) type = definition.type name = definition.name definitions[type] ||= {} definitions[type][name] = definition end def self.find_definition(name:, type:) definitions[type][name] end def self.register_segment(tag:, klass:) segments[tag] ||= klass end def self.find_segment(tag:) segments[tag] end def self.register_structure(tag:, structure:) structures[tag] ||= structure end def self.find_structure(tag:) structure = structures[tag] if structure.nil? raise StructureNotFoundError.new( "Structure for tag: #{tag} not found." ) end structure end end # TODO: Describe why loaded here... require 'eancom/edifact' require 'eancom/factory' require 'eancom/parser' require 'eancom/definition' spec = Gem::Specification.find_by_name('eancom') gem_root = spec.gem_dir Dir[File.join(gem_root, 'definitions', '**/*.rb')].sort.each do |file| require file end