Sha256: 8687e74ad7e3996f19b7030fd0515f84f1cc58147c866bcd72c0d3981900974d

Contents?: true

Size: 1.5 KB

Versions: 15

Compression:

Stored size: 1.5 KB

Contents

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eancom-1.6.3 lib/eancom.rb
eancom-1.6.2 lib/eancom.rb
eancom-1.6.0 lib/eancom.rb
eancom-1.5.7 lib/eancom.rb
eancom-1.5.6 lib/eancom.rb
eancom-1.5.5 lib/eancom.rb
eancom-1.5.4 lib/eancom.rb
eancom-1.5.2 lib/eancom.rb
eancom-1.5.1 lib/eancom.rb
eancom-1.5.0 lib/eancom.rb
eancom-1.4.0 lib/eancom.rb
eancom-1.3.0 lib/eancom.rb
eancom-1.2.0 lib/eancom.rb
eancom-1.1.1 lib/eancom.rb
eancom-1.1.0 lib/eancom.rb